diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-04 10:22:08 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-04 10:22:08 -0700 |
commit | 75ddca922ba8dcaf696f23f613b1a9f594a1884f (patch) | |
tree | 2792a86030426b5e170edfc4acd294e218d8a987 /txr.1 | |
parent | 0b587e521b5bee74c530adcf4636993ed91036c4 (diff) | |
download | txr-75ddca922ba8dcaf696f23f613b1a9f594a1884f.tar.gz txr-75ddca922ba8dcaf696f23f613b1a9f594a1884f.tar.bz2 txr-75ddca922ba8dcaf696f23f613b1a9f594a1884f.zip |
Optional arguments in boa construction.
* share/txr/stdlib/struct.tl (defstruct): Split boa
arguments on colon and generate the lambda
accordingly. The generated function detects which
optional arguments are actually present and only
performs the slot updates for those.
* tests/012/struct.tl: Corrected boa test case.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 37 |
1 files changed, 34 insertions, 3 deletions
@@ -17972,9 +17972,33 @@ arguments in the .code new macro or the .code make-struct -function. A slot initialized in this style still has a +function. + +Slots are first initialized according to their +.metn init-form -s, +regardless of whether they are involved in boa construction + +A slot initialized in this style still has a .meta init-form -which is evaluated unconditionally. +which is processed independently of the existence of, and prior to, +boa construction. + +The boa constructor syntax can specify optional arguments, delimited +by a colon, similarly to the +.code lambda +syntax. However, the optional arguments may only be symbols which name +slots. The +.cblk +.meti >> ( name < init-form <> [ present-p ]) +.cble +optional argument syntax isn't supported. + +When boa construction is invoked with optional arguments missing, +the default values for those arguments come from the +.metn init-form -s +in the remaining +.code defstruct +syntax. .TP* Examples: .cblk @@ -18004,7 +18028,7 @@ which is evaluated unconditionally. *counter* -> 5 ;; boa initialization - (defstruct (point x y) nil (x 0) (y 0)) + (defstruct (point x : y) nil (x 0) (y 0)) (new point) -> #S(point x 0 y 0) (new (point 1 1)) -> #S(point x 1 y 1) @@ -18015,6 +18039,13 @@ which is evaluated unconditionally. ;; boa applies last: (new (point 1 1) x 4 y 5) -> #S(point x 1 y 1) + + ;; boa with optional argument omitted: + (new (point 1)) -> #S(point x 1 y 0) + + ;; boa with optional argument omitted and + ;; with property list style initialization: + (new (point 1) x 5 y 5) -> #S(point x 1 y 5) .cble .coNP Macro @ new |