summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-02-21 18:13:52 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-02-21 18:13:52 -0800
commit72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a (patch)
tree2232b5a5374c92d566f087f2bc5e5067a5fb8fd4 /txr.1
parent216c446da541d2a2e68c57feee04bafce00013e5 (diff)
downloadtxr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.gz
txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.bz2
txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.zip
Introducing optional arguments.
* debug.c (help, show_bindings): put_string arguments reversed. * eval.c (bind_args): Support colon notation in interpreted function lambda lists for optional arguments. Improved error checking. (apply): Allow optional arguments to be left out. (dwim_loc): Reversed arguments to replace_str, replace_vec, replace_list. (eval_init): Numerous intrinsics now have arguments that are optional. New function rand introduced which reverses arguments relative to random. New intrinsic function hash introduced for alternative construction of hashes. * gc.c (sweep): Reversed arguments to put_char. * hash.c (weak_keys_k, weak_vals_k, equal_based_k): New keyword symbol variables. (hashv): New function. (hash_init): Intern new symbols. * hash.h (weak_keys_k, weak_vals_k, equal_based_k, hashv): Declared. * lib.c (colon_k): New keyword symbol variable. (replace_list, replace_str, replace_vec): Arguments rearranged. (tree_find): testfun becomes optional argument. (int_str): base becomes optional argument. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_interp): Initialize optargs to zero. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): New functions. (cobj_print_op): Reversed arguments to put_string. (find): testfun and keyfun become optional arguments. (replace): Parameters rearranged and arguments rearranged in calls to replace_list, replace_str and replace_vec. (obj_init): colon_k initialized. (obj_print, obj_pprint): Arguments reversed, and stream defaults to std_output. Arguments reversed in calls to put_char and put_string. (dump): Arguments reversed in call to put_char. * lib.h (struct func): sizes of minparam, fixparam bitfields adjusted. New bitfield optargs. New unnamed bitfield added so the previous ones add up to 16 bits. (colon_k): Declared. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): Declared. (replace_list, replace_str, replace_vec, replace): Declarations updated. * match.c (debuglf, dump_shell_string, dump_byte_string, dump_var, do_output_line, extract): Reversed arguments to put_char and
Diffstat (limited to 'txr.1')
-rw-r--r--txr.124
1 files changed, 18 insertions, 6 deletions
diff --git a/txr.1 b/txr.1
index 636c8aba..25e6d8b6 100644
--- a/txr.1
+++ b/txr.1
@@ -4606,6 +4606,11 @@ 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.
+
Functions created by lambda capture the surrounding variable bindings.
@@ -4628,6 +4633,11 @@ Variadic funcion:
(lambda args (list 'my-list-of-arguments args))
+Optional arguments:
+
+ [(lambda (x : y) (list x y)) 1] -> (1 nil)
+ [(lambda (x : y) (list x y)) 1 2] -> (1 2)
+
.SS Operator op
.TP
@@ -4855,11 +4865,13 @@ Syntax:
Description:
The defun operator introduces a new function in the global function namespace.
-The function is similar to a lambda, except that <body-form>-s are surrounded
-by a named block called nil. The name of this block is the same as the name of
-the function, making it possible to terminate the function and return a
-value using (return-from <name> <value>). For more information, see the
-definition of the block operator.
+The function is similar to a lambda, and has the same parameter syntax
+and semantics as the lambda operator.
+
+Unlike in lambda, the <body-form>-s of a defun are surrounded by a block.
+The name of this block is the same as the name of the function, making it
+possible to terminate the function and return a value using (return-from <name>
+<value>). For more information, see the definition of the block operator.
A function may call itself by name, allowing for recursion.
@@ -6430,7 +6442,7 @@ Certain object types have a custom equal function.
.SS Functions search-regex and match-regex
-.SS Function make-hash
+.SS Functions make-hash, hash
.SS Function sethash