diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-10-06 11:02:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-10-06 11:02:23 -0700 |
commit | b9746b4840d0f38042773bbc097286dd02857e18 (patch) | |
tree | ebe73725ef28da213ad71957e9cc42c18745150b /lib.c | |
parent | 9ea10a1408eb1cd63bd38f0367428b2b57b57b97 (diff) | |
download | txr-b9746b4840d0f38042773bbc097286dd02857e18.tar.gz txr-b9746b4840d0f38042773bbc097286dd02857e18.tar.bz2 txr-b9746b4840d0f38042773bbc097286dd02857e18.zip |
* lib.c (funcall3, curry_123_2): New functions.
(do_curry_123_2): New static function.
* lib.h (funcall3, curry_123_2): Declared.
* match.c (subst_vars): Bugfix: throw error on unbound variable instead
of ignoring the situation. This bug caused unbound variables in
quasiliterals to be silently ignored.
(eval_form): Function changed to three argument form, so that
it takes a line number for reporting errors. Restructured to catch
the new unbound variable exception from subst_vars, and re-throw
it with a line number. Also, throws exception now instead of returning
nil if itself it detets an unbound variable. Uses of eval_form
no longer have to test the return value for nil, but just assume
it worked.
(match_lines): Currying calls to eval form updated to use
curry_123_2. Test of eval return value eliminated. In function
calls, eval isn't used for reducing symbol arguments to values,
because it now throws in the unbound case, and it's not worth
setting up a catch for this. Instead, assoc is used directly.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -1446,6 +1446,21 @@ val funcall2(val fun, val arg1, val arg2) } } +val funcall3(val fun, val arg1, val arg2, val arg3) +{ + type_check(fun, FUN); + + switch (fun->f.functype) { + case F3: + return fun->f.f.f3(fun->f.env, arg1, arg2, arg3); + case N3: + return fun->f.f.n3(arg1, arg2, arg3); + default: + uw_throwf(error_s, lit("funcall3: wrong number of arguments")); + } +} + + val reduce_left(val fun, val list, val init, val key) { if (!key) @@ -1477,6 +1492,15 @@ val bind2other(val fun2, val arg2) return func_f1(cons(fun2, arg2), do_bind2other); } +static val do_curry_123_2(val fcons, val arg2) +{ + return funcall3(car(fcons), car(cdr(fcons)), arg2, cdr(cdr(fcons))); +} + +val curry_123_2(val fun3, val arg1, val arg3) +{ + return func_f1(cons(fun3, cons(arg1, arg3)), do_curry_123_2); +} static val do_chain(val fun1_list, val arg) { |