summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-29 06:58:15 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-29 06:58:15 -0800
commitff17df5e47559aa87ffd828c6126a63165805ad2 (patch)
tree3a0aa3cf65ed8ff39356fd1a8a5eaf78d7dbfefb /txr.1
parentb8966f0bf73f01e1e380a08e6949ccc9ddd45637 (diff)
downloadtxr-ff17df5e47559aa87ffd828c6126a63165805ad2.tar.gz
txr-ff17df5e47559aa87ffd828c6126a63165805ad2.tar.bz2
txr-ff17df5e47559aa87ffd828c6126a63165805ad2.zip
Default argument initializer scoping rule change, allowing
things like (defun foo (s : (l (length s))) ...). Default arguments can be initialized by expressions that refer to the arguments. * eval.c (bind_args): By means of a local array, defer the evaluation of optional argument init forms until the lexical environment, including all the parameters, is captured. Then valuates the forms in the array, and set the variable values. * txr.1: Clarify the new scoping rules.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.124
1 files changed, 17 insertions, 7 deletions
diff --git a/txr.1 b/txr.1
index 89148672..f92bedba 100644
--- a/txr.1
+++ b/txr.1
@@ -5912,19 +5912,29 @@ The dotted notation can be used to write a function that accepts
a variable number of arguments. To write a function that accepts
variable arguments only, with no required arguments, use a single symbol.
-The keyword symbol : can appear in the parameter list. It is not an argument,
-but a separator between required parameters and optional parameters.
-When the function is called, optional parameter for which arguments
-are not supplied take on the value nil.
+The keyword symbol : (colon) can appear in the parameter list. It is not an
+argument, but a separator between required parameters and optional parameters.
+When the function is called, optional parameter for which arguments are not
+supplied take on the value nil.
An optional parameter can also be written in the form (<name> <expr>).
In this situation, if the call does not specify a value for the parameter,
then the parameter takes on the value of the expression <expr>.
-The expression is evaluated in the environment in which the lambda
-was constructed.
-Functions created by lambda capture the surrounding variable bindings.
+The initializer expressions are evaluated an environment in which
+all of the parameters are visible, which extends the environment in
+which the lambda was constructed. For instance:
+ (let ((default 0))
+ (lambda (str : (end (length str)) (counter default))
+ (list str end counter)))
+
+In this lambda, the initializing expression for the optional parameter
+end is (length str), and the str variable it refers to is the previous
+argument. The initializer for the optional variable counter is
+the expression default, and it refers to the binding established
+by the surrounding let. This reference is captured as part of the
+lambda's lexical closure.
.TP
Examples: