summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--eval.c11
-rw-r--r--txr.133
3 files changed, 48 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 0385c09b..20254472 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/eval.c b/eval.c
index d9acfda4..7339281e 100644
--- a/eval.c
+++ b/eval.c
@@ -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));
diff --git a/txr.1 b/txr.1
index 503b7771..23b55eac 100644
--- a/txr.1
+++ b/txr.1
@@ -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