diff --git a/implementations/c/src/evaluator.c b/implementations/c/src/evaluator.c index 7bc8db3..66552ca 100644 --- a/implementations/c/src/evaluator.c +++ b/implementations/c/src/evaluator.c @@ -11,9 +11,13 @@ static Pointer run_fn(Func fn, Pointer params) { env = cons(tbl, env); while(args != NIL && params != NIL) { - table_set(tbl, CAR(args), CAR(params)); - args = CDR(args); - params = CDR(params); + if (CAR(args) == BODY && CAR(CDR(args)) != NIL) { + table_set(tbl, CAR(CDR(args)), params); + break; + } + table_set(tbl, CAR(args), CAR(params)); + args = CDR(args); + params = CDR(params); } REDUCE(body, eval(CAR(body), env), value); diff --git a/implementations/c/src/lisp.c b/implementations/c/src/lisp.c index 89ab7fb..37c15c3 100644 --- a/implementations/c/src/lisp.c +++ b/implementations/c/src/lisp.c @@ -325,6 +325,7 @@ void init(void) { /* (set-reader-macro \' (fn (s c) (list quote (read s)))) +(defmacro defn (name args &body body) (list def name (cons fn (cons args body)))) */ void repl(void) { diff --git a/implementations/c/src/lisp.h b/implementations/c/src/lisp.h index 5ea34fe..f9b06c3 100644 --- a/implementations/c/src/lisp.h +++ b/implementations/c/src/lisp.h @@ -113,6 +113,7 @@ extern Pointer UNDEFINED; extern Pointer T; extern Pointer STANDARD_INPUT; extern Pointer STANDARD_OUTPUT; +extern Pointer BODY; /** UTILS **/ void init(void); diff --git a/implementations/c/src/symbol.c b/implementations/c/src/symbol.c index 2b46623..cd6cdd5 100644 --- a/implementations/c/src/symbol.c +++ b/implementations/c/src/symbol.c @@ -6,6 +6,7 @@ Pointer T; Pointer STANDARD_INPUT; Pointer STANDARD_OUTPUT; Pointer UNDEFINED; +Pointer BODY; static Pointer SYMBOLS; @@ -53,5 +54,6 @@ void symbol_init(void) { STANDARD_INPUT = symbol1("*standard-input*"); STANDARD_OUTPUT = symbol1("*standard-output*"); UNDEFINED = symbol1("undefined"); + BODY = symbol1("&body"); }