Compare commits

...

8 Commits

Author SHA1 Message Date
Scott Richmond
3f6bafb1bd release build 2025-07-07 08:42:44 -04:00
Scott Richmond
c2329519d7 fix prelude bindings 2025-07-07 08:42:09 -04:00
Scott Richmond
28cc6ddf1d update prelude location in docs 2025-07-07 00:40:26 -04:00
Scott Richmond
f04522e62b bring in old readme 2025-07-07 00:27:20 -04:00
Scott Richmond
75c90c50a4 Merge branch 'main' into actors 2025-07-07 00:22:56 -04:00
Scott Richmond
69b6b0cce6 commit some changes 2025-07-07 00:17:57 -04:00
Scott Richmond
74ecea9ff6 build 2025-07-07 00:12:45 -04:00
Scott Richmond
8a9170b002 work on functions, discover recursion problems 2024-12-23 22:04:25 -05:00
6 changed files with 104 additions and 14 deletions

View File

@ -1,3 +1,93 @@
# rudus ![Ludus logo](logo.png)
## Ludus: A friendly, dynamic, functional language
Ludus is a scripting programming language that is designed to be friendly, dynamic, and functional.
A Rust implementation of Ludus. This repo currently contains a work-in-progress implementation of an interpreter for the Ludus programming language, using [Janet](https://janet-lang.org) as a host language.
Ludus is part of the [_Thinking with Computers_ project](https://alea.ludus.dev/twc/), run by Scott Richmond at the University of Toronto, with collaborator Matt Nish-Lapidus; Bree Lohman and Mynt Marsellus are the RAs for the project. Ludus is our research language, which aspires to be a free translation of Logo for the 2020s.
Here are our design goals:
#### Friendly
Ludus, like Logo, is meant to be a teaching language, often for students who don't think of themselves as "computer people." Our intended audience are humanities and art people at the university level (undergrads, grads, faculty). Everything is kept as simple as possible, but no simpler. Everything is consistent as possible. We aspire to the best error messages we can muster, which is important for a language to be teachable. That means being as strict as we can muster, _in order to be friendlier_.
Our current development target is Ludus on the web: https://web.ludus.dev. That wires what we do on the langauge interpreter (here in this repo) to a web frontend.
Naturally, it starts with Logo's famed turtle graphics.
#### Dynamic
Statically typed programming languages generally give more helpful error messages than dynamic ones, but learning a type system (even one with robust type inference) requires learning two parallel systems: the type system and the expression system (well, and the pattern system). Type systems only really make sense once you've learned why they're necessary. And their benefits seem (to us, anyway) to be largely necessary when writing long-lived, maintainable, multi-author code. Ludus code is likely to be one-off, expressive, and single-authored.
To stay friendly, Ludus is dynamic. But: despite the dynamism, we aim to be as strict as possible. Certainly, we want to avoid the type conversion shenanigans of a language like JavaScript.
#### Functional
Ludus is emphatically functional: it uses functions for just about everything. This is both because your humble PI had his world reordered when he learned his first functional language (Elixir), and because the research into Logo and the programming cultures of MIT in the 1970s revolve around extremely functional Lisp code (i.e., Scheme). Logo is a weird little language, but it is a descendant of Lisp. So is Ludus.
Also, we believe that Ludus's immutable bindings and persistent or immutable data structures and careful approach to manipulating state lead to a lot of good pedagogical results. Learning a programming language involves learning how to model what's going on inside the computer; Ludus, we think, makes that both simpler and easier.
If you're looking for cognate languages, Ludus takes a _lot_ of design inspiration from Clojure and Elixir (which itself took a lot from Clojure). (The current--quick, dirty, and slow--version of Ludus is written in [Janet](https://janet-lang.org).) Clojure and Elixir are great! If you're asking why you should use Ludus instead of them, you're already at the point where you should be using them. Ludus is, maybe, for the people whom you'd like to work with in 5 years at your Pheonix shop (but even then, probably not).
### Status
Pre-alpha, still under active development. Lots of things change all the time.
The current version of Ludus is a pure function that runs in JavaScript as a WASM blob. We have plans for more and better things.
### Use
Current emphasis is on the web version: https://web.ludus.dev.
### Main features
* Expression-oriented: everything returns a value
* Pattern matching in all the places
* No operators: everything is called as a function
* Easy-peasy partial application with placeholders
* Function pipelines
* Persistent or immutable data structures
* Careful, explicit state management using `box`es
* Clean, concise, expressive syntax
* Value-based equality; only functions are reference types
#### Under construction
* Actor-model style concurrency.
* Faster, bytecode-based VM written in a systems language, for better performance.
* Performant persistent, immutable data structures, à la Clojure.
### `Hello, world!`
Ludus is a scripting language. At current it does not have a good REPL. Our aim is to get interactive coding absolutely correct, and our efforts in [ludus-web](https://github.com/thinking-with-computers/ludus-web) are currently under way to surface the right interactivity models for Ludus.
Either:
```
"Hello, world!"
```
`=> "Hello, world!"`
Ludus scripts (and blocks) simply return their last expression; this script returns the bare string and exits.
Or:
```
print! ("Hello, world!")
```
```
=> Hello, world!
=> :ok
```
Here, we use the `print!` function, which sends a string to a console (`stdout` on Unix, or a little console box on the web). Because `print!` returns the keyword `:ok` when it completes, that is the result of the last expression in the script--and so Ludus also prints this.
### Some code
Fibonacci numbers:
```
& fibonacci!, with multi-clause fns/pattern matching
fn fib {
"Returns the nth fibonacci number."
(1) -> 1
(2) -> 1
(n) -> add (
fib (sub (n, 1))
fib (sub (n, 2)))
}
fib (10) &=> 55
```
### More on Ludus
See the [language reference](language.md) and [the documentation for the prelude](prelude.md).

View File

@ -1137,7 +1137,7 @@ fn heed {
fn send_sync { fn send_sync {
"Sends the message to the specified process, and waits for a response in the form of a `(:reply, response)` tuple." "Sends the message to the specified process, and waits for a response in the form of a `(:reply, response)` tuple."
(pid, msg) -> { (pid, msg) -> {
send (pid, msg) send! (pid, msg)
receive { receive {
(:reply, res) -> res (:reply, res) -> res
} }
@ -1157,7 +1157,7 @@ fn request_fetch! {
request_fetch! (pid) request_fetch! (pid)
} }
else { else {
send (pid, (:reply, unbox (fetch_inbox))) send! (pid, (:reply, unbox (fetch_inbox)))
store! (fetch_inbox, ()) store! (fetch_inbox, ())
} }
} }
@ -1167,7 +1167,7 @@ fn fetch {
"Requests the contents of the URL passed in. Returns a result tuple of (:ok, <contents>) or (:err, <status code>)." "Requests the contents of the URL passed in. Returns a result tuple of (:ok, <contents>) or (:err, <status code>)."
(url) -> { (url) -> {
let pid = self () let pid = self ()
spawn! (fn () -> request_fetch! (pid, url)) spawn (fn () -> request_fetch! (pid, url))
receive { receive {
(:reply, (_, response)) -> response (:reply, (_, response)) -> response
} }
@ -1182,7 +1182,7 @@ fn input_reader! {
input_reader! (pid) input_reader! (pid)
} }
else { else {
send (pid, (:reply, unbox (input))) send! (pid, (:reply, unbox (input)))
store! (input, nil) store! (input, nil)
} }
} }
@ -1192,7 +1192,7 @@ fn read_input {
"Waits until there is input in the input buffer, and returns it once there is." "Waits until there is input in the input buffer, and returns it once there is."
() -> { () -> {
let pid = self () let pid = self ()
spawn! (fn () -> input_reader! (pid)) spawn (fn () -> input_reader! (pid))
receive { receive {
(:reply, response) -> response (:reply, response) -> response
} }
@ -1390,10 +1390,10 @@ fn turtle_listener () -> {
add_command! (self (), (:loadstate, position, heading, visible?, pendown?, penwidth, pencolor)) add_command! (self (), (:loadstate, position, heading, visible?, pendown?, penwidth, pencolor))
} }
(:pencolor, pid) -> send (pid, (:reply, do turtle_states > unbox > self () > :pencolor)) (:pencolor, pid) -> send! (pid, (:reply, do turtle_states > unbox > self () > :pencolor))
(:position, pid) -> send (pid, (:reply, do turtle_states > unbox > self () > :position)) (:position, pid) -> send! (pid, (:reply, do turtle_states > unbox > self () > :position))
(:penwidth, pid) -> send (pid, (:reply, do turtle_states > unbox > self () > :penwidth)) (:penwidth, pid) -> send! (pid, (:reply, do turtle_states > unbox > self () > :penwidth))
(:heading, pid) -> send (pid, (:reply, do turtle_states > unbox > self () > :heading)) (:heading, pid) -> send! (pid, (:reply, do turtle_states > unbox > self () > :heading))
does_not_understand -> { does_not_understand -> {
let pid = self () let pid = self ()
panic! "{pid} does not understand message: {does_not_understand}" panic! "{pid} does not understand message: {does_not_understand}"
@ -1405,7 +1405,7 @@ fn turtle_listener () -> {
fn spawn_turtle { fn spawn_turtle {
"Spawns a new turtle in a new process. Methods on the turtle process mirror those of turtle graphics functions in prelude. Returns the pid of the new turtle." "Spawns a new turtle in a new process. Methods on the turtle process mirror those of turtle graphics functions in prelude. Returns the pid of the new turtle."
() -> { () -> {
let pid = spawn! (fn () -> turtle_listener ()) let pid = spawn (fn () -> turtle_listener ())
update! (turtle_states, assoc (_, pid, turtle_init)) update! (turtle_states, assoc (_, pid, turtle_init))
pid pid
} }

View File

@ -5,7 +5,7 @@ e.g., running `doc! (add)` will send the documentation for `add` to the console.
For more information on the syntax & semantics of the Ludus language, see [language.md](./language.md). For more information on the syntax & semantics of the Ludus language, see [language.md](./language.md).
The prelude itself is just a Ludus file, which you can see at [prelude.ld](./prelude.ld). The prelude itself is just a Ludus file, which you can see at [prelude.ld](../assets/prelude.ld).
## A few notes ## A few notes
**Naming conventions.** Functions whose name ends with a question mark, e.g., `eq?`, return booleans. **Naming conventions.** Functions whose name ends with a question mark, e.g., `eq?`, return booleans.

View File

@ -81,7 +81,7 @@ e.g., running `doc! (add)` will send the documentation for `add` to the console.
For more information on the syntax & semantics of the Ludus language, see [language.md](./language.md). For more information on the syntax & semantics of the Ludus language, see [language.md](./language.md).
The prelude itself is just a Ludus file, which you can see at [prelude.ld](./prelude.ld). The prelude itself is just a Ludus file, which you can see at [prelude.ld](../assets/prelude.ld).
## A few notes ## A few notes
**Naming conventions.** Functions whose name ends with a question mark, e.g., `eq?`, return booleans. **Naming conventions.** Functions whose name ends with a question mark, e.g., `eq?`, return booleans.

BIN
logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.