fisl

fisl is scheme lox
git clone git://git.alexkarle.com.com/fisl
Log | Files | Refs | README | LICENSE

commit aac74e196655b29072cf69f17b81b9416dbd15e2 (patch)
parent 75369e719adc8defa7d13dd99487b8ef31b71199
Author: Alex Karle <alex@alexkarle.com>
Date:   Wed,  9 Nov 2022 00:25:06 -0500

interpreter: Fix assignment not evaluating RHS

This was a funny find :)

Before

$ ./fisl.scm
> var x = 1;
> print x = 1 + 1;
(+ 1 1)

After:
> var x;
> print x = 1 + 1;
2
> print x;
2

Diffstat:
Minterpreter.scm | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/interpreter.scm b/interpreter.scm @@ -44,9 +44,9 @@ ((assignment? expr) (let ((tok (assignment-name expr))) (if (hash-table-exists? global-env (token-lexeme tok)) - (begin - (hash-table-set! global-env (token-lexeme tok) (assignment-value expr)) - (assignment-value expr)) + (let ((res (evaluate (assignment-value expr)))) + (hash-table-set! global-env (token-lexeme tok) res) + res) (runtime-err! (format "Unbound variable ~A at line ~A" (token-lexeme tok) (token-line tok)))))) ((unary? expr)