diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-06-17 06:59:46 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-06-17 06:59:46 -0700 |
commit | 95f05cafb8da2dc1a20a41b165c2e03c24d04099 (patch) | |
tree | 61ff68622bd17632bbf731ff9ffb73bc136756fb | |
parent | 5b140a070a99937da7c0b1fac9c23b7a281be82f (diff) | |
download | txr-95f05cafb8da2dc1a20a41b165c2e03c24d04099.tar.gz txr-95f05cafb8da2dc1a20a41b165c2e03c24d04099.tar.bz2 txr-95f05cafb8da2dc1a20a41b165c2e03c24d04099.zip |
* eval.c (not_null): New static function.
(eval_init): Use null_f in existing registration of null
and not. Add registration for not_null as "true",
and for null_f as "false".
* txr.1: Documented true and false.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | eval.c | 11 | ||||
-rw-r--r-- | txr.1 | 33 |
3 files changed, 48 insertions, 5 deletions
@@ -1,5 +1,14 @@ 2014-06-17 Kaz Kylheku <kaz@kylheku.com> + * eval.c (not_null): New static function. + (eval_init): Use null_f in existing registration of null + and not. Add registration for not_null as "true", + and for null_f as "false". + + * txr.1: Documented true and false. + +2014-06-17 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): register tuples as intrinsic. * lib.c (tuples_func): New static function. @@ -3057,6 +3057,11 @@ static val and_fun(val vals) return item; } +static val not_null(val obj) +{ + return if3(nilp(obj), nil, t); +} + static val prinl(val obj, val stream) { val ret = obj_print(obj, stream); @@ -3224,8 +3229,10 @@ void eval_init(void) reg_fun(intern(lit("typeof"), user_package), func_n1(typeof)); reg_fun(intern(lit("atom"), user_package), func_n1(atom)); - reg_fun(intern(lit("null"), user_package), func_n1(null)); - reg_fun(not_s, func_n1(null)); + reg_fun(intern(lit("null"), user_package), null_f); + reg_fun(intern(lit("false"), user_package), null_f); + reg_fun(intern(lit("true"), user_package), func_n1(not_null)); + reg_fun(not_s, null_f); reg_fun(intern(lit("consp"), user_package), func_n1(consp)); reg_fun(intern(lit("listp"), user_package), func_n1(listp)); reg_fun(intern(lit("proper-listp"), user_package), func_n1(proper_listp)); @@ -6900,19 +6900,20 @@ A bignum integer: arbitrary precision integer that is heap-allocated. .PP There are additional kinds of objects, such as streams. -.SS Functions null and not +.SS Functions null, not, false .TP Syntax: (null <value>) (not <value>) + (false <value>) .TP Description: -The null and not functions are synonyms. They tests whether <value> is the -object nil. They return t if this is the case, nil otherwise. +The null, not and false functions are synonyms. They tests whether <value> is +the object nil. They return t if this is the case, nil otherwise. .TP Examples: @@ -6920,6 +6921,7 @@ Examples: (null '()) -> t (null nil) -> t (null ()) -> t + (false t) -> nil (if (null x) (format t "x is nil!")) @@ -6927,6 +6929,31 @@ Examples: (if (not (memq 'a list)) (format t "list ~s does not contain the symbol a\en"))) +.SS Function true + +.TP +Syntax: + + (true <value>) + +.TP +Description: + +The true function is the complement of the null, not and false functions. +It return t if the <value> is any object other than nil. If <value> is +nil, it returns nil. + +Note: programs should avoid explicitly testing values with true. +For instance (if x ...) should be favored over (if (true x) ...) + +.TP +Example: + + ;; Compute indices where the list '(1 nil 2 nil 3) has true values: + ;; "Where is (1 nil 2 nil 3) true?" + + [where '(1 nil 2 nil 3) true] -> (1 3) + .SS Functions eq, eql and equal .TP |