From ecefd793e54d3cf0a56df705a18deb587d2a19c1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 5 Feb 2014 01:22:58 -0800 Subject: * eval.c (apply): Pass missing optional arguments as colon_k. to functions for which this is requested. (reg_fun_mark): New static function. (eval_init): Register reduce_left and reduce_right as requiring marking for missing optionals. * lib.c (func_set_mark_missing): New function. (generic_funcall): Pass missing optional arguments as colon_k to functions for which this is requested. (reduce_left, reduce_right): Handle missing values of init and key. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_n5, func_n6, func_n7, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n5v, func_n6v, func_n7v): Initialize new mark_missing_args member of struct func. * lib.h (struct func): New bitfield member, mark_missing_args. (func_set_mark_missing): Declared. (missingp, null_or_missing_p): New inline functions. * txr.1: Updated descriptions of reduce-left and reduce-right. --- lib.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index dfc68db0..03a67406 100644 --- a/lib.h +++ b/lib.h @@ -106,7 +106,7 @@ struct func { unsigned fixparam : 7; /* total non-variadic parameters */ unsigned optargs : 7; /* fixparam - optargs = required args */ unsigned variadic : 1; - unsigned : 1; + unsigned mark_missing_args: 1; /* missing opt. args given as special value */ unsigned functype : 16; val env; union { @@ -601,6 +601,7 @@ val func_interp(val env, val form); val func_get_form(val fun); val func_get_env(val fun); val func_set_env(val fun, val env); +val func_set_mark_missing(val fun); val functionp(val); val interp_fun_p(val); val funcall(val fun); @@ -717,6 +718,10 @@ INLINE val nullp(val v) { return v ? nil : t; } #define nao ((obj_t *) (1 << TAG_SHIFT)) /* "not an object" sentinel value. */ +INLINE val missingp(val v) { return v == colon_k ? t : nil; } + +INLINE val null_or_missing_p(val v) { return (!v || v == colon_k) ? t : nil; } + #define if2(a, b) ((a) ? (b) : nil) #define if3(a, b, c) ((a) ? (b) : (c)) -- cgit v1.2.3