commit b7e5ec69a29dfb87ae1d074588c0b4d854d83e3d
parent d338423ce3e6fbbd7398bbafd678e6d5243da5be
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Sun, 7 May 2023 17:02:12 -0400
Revert "redefine def to take two arguments"
This reverts commit 239fbeff138c193f57d3b2565a30801910dad9d7.
Diffstat:
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
@@ -65,16 +65,16 @@ mumble> eval { head {1 2 3} }
mumble> (eval { head {+ tail head } } ) 1 2 3
mumble> len {1 2 3}
mumble> join { {1 2} {3 4} }
-mumble> def {x} { 100 }
+mumble> def { {x} { 100 } }
mumble> x
-mumble> def { a b c } { 1 2 3}
+mumble> def { { a b c } { 1 2 3} }
mumble> * a b c
mumble> - a b c
mumble> / a b c
mumble> VERBOSITY=0
mumble> VERBOSITY=1
mumble> VERBOSITY=2
-mumble> def {plus} {(@ {x y} {+ x y})}
+mumble> def { {plus} {(@ {x y} {+ x y})} }
( )
mumble> plus
( @ { x y } { + x y } )
diff --git a/mumble b/mumble
Binary files differ.
diff --git a/src/mumble.c b/src/mumble.c
@@ -733,20 +733,19 @@ lispval* builtin_join(lispval* l, lispenv* e)
// Define a variable
lispval* builtin_def(lispval* v, lispenv* env)
{
- // Takes two arguments: def { a b } { 1 2 }
- LISPVAL_ASSERT(v->count == 2, "Error: function def passed something other than 2 arguments");
-
- lispval* symbols = v->cell[0];
- lispval* values = v->cell[1];
- symbols = evaluate_lispval(symbols, env);
- values = evaluate_lispval(values, env);
-
- LISPVAL_ASSERT(symbols->type == LISPVAL_QEXPR, "Error: Argument passed to def is not a q-expr, i.e., a bracketed list.");
- LISPVAL_ASSERT(values->type == LISPVAL_QEXPR, "Error: Argument passed to def is not a q-expr, i.e., a bracketed list.");
- LISPVAL_ASSERT(symbols->count == values->count, "Error: In function \"def\" both subarguments should have the same length");
-
+ // Takes one argument: def { { a b } { 1 2 } }
+ lispval* source = v->cell[0];
+ LISPVAL_ASSERT(v->count == 1, "Error: function def passed too many arguments");
+ LISPVAL_ASSERT(source->type == LISPVAL_QEXPR, "Error: Argument passed to def is not a q-expr, i.e., a bracketed list.");
+ LISPVAL_ASSERT(source->count == 2, "Error: Argument passed to def should be a q expr with two q expressions as children: def { { a b } { 1 2 } } ");
+ LISPVAL_ASSERT(source->cell[0]->type == LISPVAL_QEXPR, "Error: Argument passed to def should be a q expr with two q expressions as children: def { { a b } { 1 2 } } ");
+ LISPVAL_ASSERT(source->cell[1]->type == LISPVAL_QEXPR || source->cell[1]->type == LISPVAL_SEXPR, "Error: Argument passed to def should be a q expr with two q expressions as children: def { { a b } { 1 2 } } ");
+ LISPVAL_ASSERT(source->cell[0]->count == source->cell[1]->count, "Error: In function \"def\" both subarguments should have the same length");
+
+ lispval* symbols = source->cell[0];
+ lispval* values = source->cell[1];
for (int i = 0; i < symbols->count; i++) {
- LISPVAL_ASSERT(symbols->cell[i]->type == LISPVAL_SYM, "Error: in function def, the first list of items should be of type symbol: def { a b } { 1 2 } ");
+ LISPVAL_ASSERT(symbols->cell[i]->type == LISPVAL_SYM, "Error: in function def, the first list of items should be of type symbol: def { { a b } { 1 2 } }");
if (VERBOSE)
print_lispval_tree(symbols, 0);
if (VERBOSE)