Skip to content

Conversation

@asarhaddon
Copy link
Contributor

The second commit contains the actual changes and describes them in detail.
I have also reduced the diff between step files (as far as rustfmt allows).

`make lint` reformats the code, creating a lot of space/indentation
noise in the diff.

Cargo.lock:
 * remove from git, add to clean Make target.

Cargo.toml, Dockerfile:
 * install regex and rustyline via apt-get.

Cargo.toml, Dockerfile, reader.rs, readline.rs, steps:
 * Implement global variables with thread_local, avoiding an external
   dependency on lazy_static and/or the complexity of Mutex.

Makefile, core.rs, readline.rs, steps:
 * Move the readline stuff into a separate file.
 * enable history during self-hosting
 * save the history at exit, not after each line
 * skip empty lines
 * crash on readline errors (other than EOF)

core.rs, steps, types.rs:
 * remove specific error types. try* requires a MAL form anyway.
 * Split the {list,vector}! macros. A variant only needs a function,
   the other one need no intermediate array.
 * Introduce a FuncStruct intermediate struct for the Func enum
   variant. This allows functional update syntax and more intuitive
   pattern matching (fn? macro? defmacro!).

core.rs, types.rs:
 * Move type helpers hide/encapsulate nothing from types.rs to core.rs.
 * Add a Kwd variant to the MalVal enum, with (un)wrap_map_key helpers.
   This is safer than a prefix (for example, `(slurp :a)` was accepted).

core.rs:
 vals: fix typo
 vec: clone if already a vector.
 nth: the .get() standard function checks array bounds.
 first, rest, seq: merge similar choices
 get_meta, with_meta, atom: remove the intermediate anonymous function
   (it is confusing and does not bring anything)

env.rs:
 The outer field is private.
 The outer argument for env_bind is not optional.

env.rs, steps:
 Implement the eval core function, using a global REPL environment. It
 was implemented with a special form and an env method searching the
 ancester of the current environment (`(map eval [1])` was failing).

reader.rs:
 Let read_seq always return a vector, and read_form deal with the result,
 instead of duplicating the choices.

steps, types.rs:
 Implement `apply` as a `MalVal` method but in step sources. The
 ugly `eval` reference in each closure is not necessary anmymore.

steps:
 Check sooner the exit status of eval(a0, env).
 Print a new line on exit.

types.rs:
 Metadata needs no mutability.

Everywhere, remove as many clone() as possible.
@kanaka kanaka merged commit 2b6d7f1 into kanaka:master Aug 26, 2025
4 checks passed
@kanaka
Copy link
Owner

kanaka commented Aug 26, 2025

Love to see this:
image

@asarhaddon asarhaddon deleted the rust branch August 30, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants