summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-09 10:46:03 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-09 10:46:03 -0700
commit0bb1f829c745d94386f17f37ed5568a20c7243e9 (patch)
tree6ddb384c58ecc190677e1e28098c22b5aa89ba21 /txr.1
parent4ad96a94657fe688da3f89102c5cc0decd268037 (diff)
downloadtxr-0bb1f829c745d94386f17f37ed5568a20c7243e9.tar.gz
txr-0bb1f829c745d94386f17f37ed5568a20c7243e9.tar.bz2
txr-0bb1f829c745d94386f17f37ed5568a20c7243e9.zip
Support curried arguments in umethod and umeth.
* share/txr/stdlib/struct.tl (umeth): accept variadic arguments. Evaluate them using the dwim brackets and pass to umethod. The (fun umethod) trick is used to refer to the umethod in the function namespace even if it is shadowed by a variable. * struct.c (struct_init): Update registration of umethod to reflect its new variadic argument signature. (umethod_args_fun): New static function. (umethod): Return a function based on umethod_fun, as before, if there are no variadic args. Otherwise, use umethod_args_fun which deals with them. * struct.h (umethod): Declaration updated. * tests/012/oop.tl: Modest testcase for umeth with curried argument. * tests/012/oop.expected: Updated. * txr.1: Updated documentation of umeth and umethod.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.136
1 files changed, 28 insertions, 8 deletions
diff --git a/txr.1 b/txr.1
index d8f0f48a..4e9f4b7f 100644
--- a/txr.1
+++ b/txr.1
@@ -20963,7 +20963,7 @@ in a function slot.
.coNP Macro @ umeth
.synb
-.mets (umeth << slot )
+.mets (umeth << slot << curried-expr *)
.syne
.desc
The
@@ -20972,24 +20972,37 @@ macro binds the symbol
.meta slot
to a function and returns that function.
+The
+.meta curried-expr
+arguments, if present, are evaluated as if they were
+arguments to the
+.code dwim
+operator.
+
When that function is called, it expects at least one argument.
The leftmost argument must be an object of struct type.
The slot named
.meta slot
is retrieved from that object, and is expected to be a function.
-That function is called with the same arguments.
+That function is called with the object, followed by the values
+of the
+.metn curried-expr -s,
+if any, followed by that function's arguments.
The syntax can be understood as a translation to a call of the
.code umethod
function:
.cblk
- (umeth s) <--> (umethod 's)
+ (umeth s ...) <--> [umethod 's ...]
.cble
The macro merely provides the syntactic sugar of not having to quote the
-symbol.
+symbol, and automatically treating the curried argument expressions
+using Lisp-1 semantics of the
+.code dwim
+operator.
.TP* Example:
@@ -21598,7 +21611,7 @@ own arguments.
.coNP Function @ umethod
.synb
-.mets (umethod << slot-name )
+.mets (umethod << slot-name << curried-arg *)
.syne
.desc
The
@@ -21611,12 +21624,19 @@ The
.meta slot-name
argument must be a symbol.
-This function must be called with at least one argument. The leftmost
+If one or more
+.meta curried-arg
+argument are present, these values represent the
+.I "curried arguments"
+which are stored in the function object which is returned.
+
+This returned function must be called with at least one argument. Its leftmost
argument must be an object of structure type, which has a slot named
.metn slot-name .
The function will retrieve the value of the slot from that object,
-expecting it to be a function, and calls it, passing to it all of its
-arguments.
+expecting it to be a function, and calls it, passing to it the following
+arguments: the object itself; all of the curried arguments, if any; and
+all of its remaining arguments.
Note: the
.code umethod