diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-11-06 07:13:27 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-11-06 07:13:27 -0800 |
commit | 9499064b56a96169b0d06619064e00c0ef3e11a7 (patch) | |
tree | 61fe213b0b635cc87bc434607cae26f9acddffa4 | |
parent | 6cd6af985619569e7e12df7b28c6aa1dc10726c1 (diff) | |
download | txr-9499064b56a96169b0d06619064e00c0ef3e11a7.tar.gz txr-9499064b56a96169b0d06619064e00c0ef3e11a7.tar.bz2 txr-9499064b56a96169b0d06619064e00c0ef3e11a7.zip |
* eval.c (eval_init): Register chand intrinsic.
* lib.c (do_chand): New static function.
(chandv): New function.
* lib.h (chandv): Declared.
* txr.1: Documented chand.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 23 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 19 |
5 files changed, 54 insertions, 1 deletions
@@ -1,5 +1,16 @@ 2014-11-06 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): Register chand intrinsic. + + * lib.c (do_chand): New static function. + (chandv): New function. + + * lib.h (chandv): Declared. + + * txr.1: Documented chand. + +2014-11-06 Kaz Kylheku <kaz@kylheku.com> + Allow then-func to be omitted in iff. Cleanup. * eval.c (eval_init): Register iff as requiring only one arg. @@ -3745,6 +3745,7 @@ void eval_init(void) reg_fun(intern(lit("env-fbind"), user_package), func_n3(env_fbind)); reg_fun(intern(lit("env-vbind"), user_package), func_n3(env_vbind)); reg_fun(intern(lit("chain"), user_package), func_n0v(chainv)); + reg_fun(intern(lit("chand"), user_package), func_n0v(chandv)); reg_fun(intern(lit("juxt"), user_package), func_n0v(juxtv)); reg_fun(intern(lit("andf"), user_package), func_n0v(andv)); reg_fun(intern(lit("orf"), user_package), func_n0v(orv)); @@ -4498,6 +4498,29 @@ val chainv(val funlist) return func_f0v(nullify(funlist), do_chain); } +static val do_chand(val fun1_list, val args) +{ + val arg = nil; + + fun1_list = nullify(fun1_list); + + if (fun1_list) { + arg = apply(car(fun1_list), args, nil); + fun1_list = cdr(fun1_list); + } + + for (; arg && fun1_list; fun1_list = cdr(fun1_list)) + arg = funcall1(car(fun1_list), arg); + + return arg; +} + + +val chandv(val funlist) +{ + return func_f0v(nullify(funlist), do_chand); +} + static val do_juxt(val funcs, val args) { return mapcar(curry_123_1(func_n3(apply), args, nil), funcs); @@ -728,6 +728,7 @@ val curry_123_23(val fun3, val arg1); val curry_1234_34(val fun3, val arg1, val arg2); val chain(val first_fun, ...); val chainv(val funlist); +val chandv(val funlist); val juxtv(val funlist); val andf(val first_fun, ...); val andv(val funlist); @@ -20443,9 +20443,10 @@ and the expression returns a function similar to .codn (lambda (. rest) 42) . -.coNP Function @ chain +.coNP Functions @ chain and @ chand .synb .mets (chain << func *) +.mets (chand << func *) .syne .desc The @@ -20469,6 +20470,22 @@ function. The return value of that call is then passed to the second function, and the return value of that call is passed to the third function and so on. The final return value is returned to the caller. +The +.code chand +function is similar, except that it combines the functionality of +.code andf +into chaining. The difference between +.code chain +and +.code chand +is that +.code chand +immediately terminates and returns +.code nil +whenever any of the functions returns +.codn nil , +without evaluating the remainder of the functions. + .TP* Example: .cblk |