summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-22 01:03:54 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-22 01:03:54 -0800
commit8ced687d65438141be8a1305fa4058a76fa3cc59 (patch)
treefc806ca24868f5ce0255668e6440f22ab38d7fa9 /txr.1
parent97865d48b22fd96e75ca216e2dd67850b1c84b2a (diff)
downloadtxr-8ced687d65438141be8a1305fa4058a76fa3cc59.tar.gz
txr-8ced687d65438141be8a1305fa4058a76fa3cc59.tar.bz2
txr-8ced687d65438141be8a1305fa4058a76fa3cc59.zip
Support function versions of if, and, or so that partial
evaluation like (op or @1 42) or (op if (eq @1 foo) bar xyzzy) is possible. * eval.c (do_eval): Change precedence between operator and function lookup to favor operators. This is important since there are several operators now which are also functions. (if_fun, or_fun, and_fun): New static functions. (eval_init): New functions registered as intrinsics. * txr.1: Documented that if, and, or exist as both functions and operators.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.141
1 files changed, 37 insertions, 4 deletions
diff --git a/txr.1 b/txr.1
index b43630fa..8c7683e9 100644
--- a/txr.1
+++ b/txr.1
@@ -5135,16 +5135,22 @@ If the first form of a group yields nil, then processing continues with the
next group, if any. If all form groups yield nil, then the cond form yields
nil. This holds in the case that the syntax is empty: (cond) yields nil.
-.SS Operator if
+.SS Operator/function if
.TP
Syntax:
(if <cond> <t-form> [<e-form>])
+ [if <cond> <then> [<else>]]
.TP
Description:
+There exist both an if operator and an if function. A list form with the symbol
+if in the fist position is interpreted as an invocation of the if operator.
+The function can be accessed using the DWIM bracket notation and in other
+ways.
+
The if operator provides a simple two-way-selective evaluation control.
The <cond> form is evaluated. If it yields true then <t-form> is
evaluated, and that form's return value becomes the return value of the if.
@@ -5152,16 +5158,27 @@ If <cond> yields false, then <e-form> is evaluated and its return value
is taken to be that of if. If <e-form> is omitted, then the behavior is
as if <e-form> were specified as nil.
-.SS Operator and
+The if function provides no evaluation control. All of arguments
+are evaluated from left to right. If the <cond> argument is true, then it
+returns the <then> argument, otherwise it returns the value of the
+<else> argument, if present, otherwise it returns nil.
+
+.SS Operator/function and
.TP
Syntax:
(and {<form>}*)
+ [and {<arg>]*)
.TP
Description:
+There exist both an and operator and an and function. A list form with the
+symbol and in the fist position is interpreted as an invocation of the
+operator. The function can be accessed using the DWIM bracket notation and in
+other ways.
+
The and operator provides three functionalities in one. It computes the
logical "and" function over several forms. It controls evaluation (a.k.a.
"short-circuiting"). It also allows the convenient substitution of an
@@ -5174,6 +5191,11 @@ the result of each form. Evaluation stops when all forms are exhausted,
or when any of them yields nil. When evaluation stops, the operator yields
the return value.
+The and function provides no evaluation control; it receives all of its
+arguments fully evaluated. If it is given no arguments, it returns t.
+If it is given one or more arguments, and any of them are nil, it returns
+nil. Otherwise it returns the value of the last argument.
+
.TP
Examples:
@@ -5181,17 +5203,23 @@ Examples:
(and (> 10 5) (stringp "foo")) -> t
(and 1 2 3) -> 3
-.SS Operator or
+.SS Operator/function or
.TP
Syntax:
(or {<form>}*)
+ [or {<arg>}*]
.TP
Description:
-The and operator provides three functionalities in one. It computes the
+There exist both an or operator and an or function. A list form with the
+symbol or in the fist position is interpreted as an invocation of the
+operator. The function can be accessed using the DWIM bracket notation and in
+other ways.
+
+The or operator provides three functionalities in one. It computes the
logical "or" function over several forms. It controls evaluation (a.k.a.
"short-circuiting"). The behavior of or also provides for a simplified
selection of the first non-nil value from a sequence of forms.
@@ -5203,6 +5231,11 @@ with the result of each form. Evaluation stops when all forms are
exhausted, or when a form yields a true value. When evaluation stops, the
operator yields the return value.
+The and function provides no evaluation control; it receives all of its
+arguments fully evaluated. If it is given no arguments, it returns nil.
+If all of its arguments are nil, it also returns nil. Otherwise, it
+returns the value of the first non-nil argument.
+
.TP
Examples: