diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-10-02 06:59:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-10-02 06:59:15 -0700 |
commit | c4a66ad7ed5c74cda3a16b191c6763c1a5cedc6d (patch) | |
tree | ce0cf1bfc1d3c471760ffcc8905e485780f03853 | |
parent | bfd251f813aee284d9cd3886a5aeffdb58497ea6 (diff) | |
download | txr-c4a66ad7ed5c74cda3a16b191c6763c1a5cedc6d.tar.gz txr-c4a66ad7ed5c74cda3a16b191c6763c1a5cedc6d.tar.bz2 txr-c4a66ad7ed5c74cda3a16b191c6763c1a5cedc6d.zip |
Struct methods and functions set up named block.
* share/txr/stdlib/struct.tl (defstruct): Generate a named
block around the body forms of the :method and
:function lambdas, whose name matches the slot name.
* txr.1: Documented.
-rw-r--r-- | share/txr/stdlib/struct.tl | 8 | ||||
-rw-r--r-- | txr.1 | 19 |
2 files changed, 24 insertions, 3 deletions
diff --git a/share/txr/stdlib/struct.tl b/share/txr/stdlib/struct.tl index 24bccbe5..3958692c 100644 --- a/share/txr/stdlib/struct.tl +++ b/share/txr/stdlib/struct.tl @@ -46,9 +46,13 @@ "~s: method ~s needs \ \ at least one parameter" 'defstruct name)) - ^(:static ,name (lambda ,args ,*body))) + ^(:static ,name + (lambda ,args + (block ,name ,*body)))) (:function ^(:static ,name - (lambda ,args ,*body))) + (lambda ,args + (block ,name + ,*body)))) ((:static :instance) (when body (sys:bad-slot-syntax slot)) @@ -17807,7 +17807,16 @@ There must be at least one When the function is invoked as a method, as intended, the leftmost .meta param -receives the structure instance. Methods are invoked +receives the structure instance. +The +.metn body-form -s +are evaluated in a context in which a block named +.meta name +is visible. Consequently, +.code return-from +may be used to terminate the execution of a method +and return a value. +Methods are invoked using the .code instance.(name arg ...) syntax, which implicitly inserts the instance into the argument list. @@ -17830,6 +17839,14 @@ only in one respect: there may be zero parameters. A structure function defined this way is intended to be used as a utility function which doesn't receive the structure instance as an argument. +The +.metn body-form -s +are evaluated in a context in which a block named +.meta name +is visible. Consequently, +.code return-from +may be used to terminate the execution of the function +and return a value. Such functions are called using the .code instance.[name arg ...] syntax which doesn't insert the instance name into |