diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-10-06 23:56:02 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-10-06 23:56:02 -0700 |
commit | 17c8e76951ea9dc407f07bf2173e8f60ac5efd80 (patch) | |
tree | f235f35ec09cf0c82ec6477e94db6fb5edc8038f /txr.1 | |
parent | 7c8c8d326bbb8b9725efa6a3c364d3426a7cdca9 (diff) | |
download | txr-17c8e76951ea9dc407f07bf2173e8f60ac5efd80.tar.gz txr-17c8e76951ea9dc407f07bf2173e8f60ac5efd80.tar.bz2 txr-17c8e76951ea9dc407f07bf2173e8f60ac5efd80.zip |
Improving behavior of op and fixing a bug.
Explicitly specifying @rest using (op ... . @rest)
did not work at all.
The then-func agument of iff and iffi may now be nil.
* eval.c (format_op_arg): New static function.
(transform_op): Handle dotted lists ending in @rest
or @<num>.
(supplement_op_syms): New static function.
(expand_op): Add missing numeric arguments,
so that all 1 through n are in the list.
Trailing rest is now added under different
conditions.
* lib.c (do_iff): Give thenfun the same
behavior on nil that elsefun enjoys.
* txr.1: Updated.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 52 |
1 files changed, 35 insertions, 17 deletions
@@ -9609,11 +9609,11 @@ construct is erroneous. .IP @rest The meta-symbol @rest indicates that any trailing arguments to the -function are to be inserted. If the @<num> syntax is not used anywhere, -it means that the function only has trailing arguments. If @1 is used, -it means that the second and subsequent arguments are trailing arguments. -If @rest is not used anywhere, then the rest arguments are automatically -applied to the op form. If @rest appears, then this is suppressed. +function are to be inserted there. If the form does not contain +any @<num> syntax or @<rest> syntax, then @<rest> is implicitly +inserted. What this means is that, for example, since the form (op foo) does +not contain any numeric positional arguments like @1, and does not contain +@rest, it is actually a shorthand for (op foo . @rest). The actions of form may be understood by these examples, which show how op is rewritten to lambda. However, note that the real translator @@ -9624,13 +9624,27 @@ symbols in the program. (op +) -> (lambda rest [+ . rest]) - (op @1 @2) -> (lambda (arg1 arg2 . rest) [arg1 arg2 . rest]) + (op + foo) -> (lambda rest [+ foo . rest]) + + (op @1 @2) -> (lambda (arg1 arg2 . rest) [arg1 arg2]) + + (op @1 . @rest) -> (lambda (arg1 . rest) [arg1 . @rest]) + + (op @1 @rest) -> (lambda (arg1 . rest) [arg1 @rest]) + + (op @1 @2) -> (lambda (arg1 arg2 . rest) [arg1 arg2]) (op foo @1 (@2) (bar @3)) -> (lambda (arg1 arg2 arg3 . rest) - [foo arg1 (arg2) (bar arg3) . rest]) + [foo arg1 (arg2) (bar arg3)]) (op foo @rest @1) -> (lambda (arg1 . rest) [foo rest arg1]) +Note that if argument @<n> appears, it is not necessary +for arguments @1 through @<n-1> to appear. The function +will have n arguments: + + (op @3) -> (lambda (arg1 arg2 arg3 . rest) [arg3]) + .PP .TP @@ -9738,22 +9752,26 @@ The iff function is the functional equivalent of the if operator. It accepts functional arguments and returns a function. The resulting function takes its arguments and applies them to <cond-func>. If -<cond-func> yields true, then the arguments are passed to <then-func,> and the -resulting value is returned. Otherwise if <cond-func> yields a false result, -and there is no <else-func>, then nil is returned. If <cond-func> yields false, -and an <else-func> exists, then the original arguments are passed to -<else-func> and the resulting value is returned. +<cond-func> yields true, then the arguments are passed to <then-func> and the +resulting value is returned. Otherwise the arguments are passed to <else-func> +and the resulting value is returned. + +If <then-func> needs to be called, but is nil, then nil is returned +immediately. Likewise, if <else-func> needs to be calld, but is nil, then nil +is returned. The iffi function differs from iff only in the defaulting behavior with respect -to the <else-func> argument. The following equivalence holds: +to the <else-func> argument. The following equivalences hold: + + (iffi a b c) <--> (iff a b c) - (iffi a b c) <--> (iff a b c) + (iffi a b) <--> (iff a b identity) - (iffi a b) <--> (iff a b identity) + (iffi a b nil) <--> (iff a b identity) The iffi function defaults to the identity function when <else-func> is -omitted, and therefore is useful in situations when one value is to be replaced -with another one when the condition is true, otherwise left alone. +omitted or nil, and therefore is useful in situations when one value is to be +replaced with another one when the condition is true, otherwise left alone. .SH INPUT AND OUTPUT |