commit ae26a50533f019d67bd620f6bec0c7703ae3eb8b
parent b5f18b6adc4966f26e522dc677cdd684c46ad24e
Author: Ed van Bruggen <edvb@uw.edu>
Date: Tue, 31 Dec 2019 01:10:16 -0800
Have set! return new value of variable
Diffstat:
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/test.c b/test.c
@@ -169,9 +169,9 @@ char *tests[][2] = {
{ "foo", "4" },
{ "(define bar foo)", "" },
{ "bar", "4" },
- { "(set! foo 5)", "" },
+ { "(set! foo 5)", "5" },
{ "foo", "5" },
- { "(set! foo (+ foo bar))", "" },
+ { "(set! foo (+ foo bar))", "9" },
{ "foo", "9" },
{ "(define add +)", "" },
{ "(add foo bar)", "13" },
@@ -184,9 +184,9 @@ char *tests[][2] = {
{ "(define (add2 x)"
" (+ x 1) (+ x 2))", "" },
{ "(add2 2)", "4" },
- { "(set! add2 2)", "" },
+ { "(set! add2 2)", "2" },
{ "add2", "2" },
- { "(set! add2 \"2\")", "" },
+ { "(set! add2 \"2\")", "\"2\"" },
{ "add2", "\"2\"" },
{ "lambda", NULL },
diff --git a/tibs/lib.tsp b/tibs/lib.tsp
@@ -203,9 +203,7 @@
(cons val stack))
(defmacro (push! stack val)
- (list do
- (list set! stack (list push stack val))
- stack))
+ (list set! stack (list push stack val)))
(define pop cdr)
@@ -225,8 +223,7 @@
(defmacro (swap! stack)
(list let (list (list 'x (list pop! stack))
(list 'y (list pop! stack)))
- (list set! stack (list push (list push stack 'x) 'y))
- stack))
+ (list set! stack (list push (list push stack 'x) 'y))))
;;; Math
(define pi (* 4 (arctan 1.)))
diff --git a/tisp.c b/tisp.c
@@ -966,7 +966,7 @@ prim_set(Tsp st, Hash env, Val args)
if (!e || !e->key)
tsp_warnf("set!: variable %s is not defined", car(args)->v.s);
e->val = val;
- return st->none;
+ return val;
}
/* loads tisp file or C dynamic library */