hare-lisp

small lisp written in hare
git clone git://jeskin.net/hare-lisp.git
README | Log | Files | Refs | LICENSE

commit 0db71423385453ffa4c783714d44d44eed9950d2
parent 11b3962a6008489efa980148f0bbd37af854f179
Author: Jon Eskin <eskinjp@gmail.com>
Date:   Sun, 19 Jun 2022 05:05:43 -0400

add gensym

Diffstat:
MREADME.md | 2+-
Mlisp.ha | 9+++++++++
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md @@ -19,7 +19,7 @@ - [x] = - [x] defmacro - [x] defun -- [ ] gensym +- [x] gensym - [ ] garbage collection - [ ] rational numbers diff --git a/lisp.ha b/lisp.ha @@ -699,6 +699,14 @@ fn prim_plus(env: *Environment, list: List) (Obj | invocation_error) = { return alloc(sum); }; +fn prim_gensym(env: *Environment, list: List) (Obj | invocation_error) = { + static let count = 0; + let buf: [10]u8 = [0 ... ]; + fmt::bsprintf(buf, "G__{}", count); + count += 1; + return alloc(strings::fromutf8(buf)); +}; + fn prim_times(env: *Environment, list: List) (Obj | invocation_error) = { let sum: int = 1; for(let args= eval_list(env,list); !(args is Nil); args = (args as *Cell).cdr @@ -839,6 +847,7 @@ fn define_primitives(env: *Environment) void = { add_primitive(env, "=", &prim_num_eq); add_primitive(env, "defun", &prim_defun); add_primitive(env, "defmacro", &prim_defmacro); + add_primitive(env, "gensym", &prim_gensym); }; // ===========================================================================