Merge pull request #893 from gilch/xi-forms
xi parameter may appear in function position
This commit is contained in:
commit
ead65b646b
@ -231,7 +231,7 @@ Returns a function which applies several forms in series from left to right. The
|
||||
xi
|
||||
==
|
||||
|
||||
Usage ``(xi function body ...)``
|
||||
Usage ``(xi body ...)``
|
||||
|
||||
Returns a function with parameters implicitly determined by the presence in the body of xi parameters. An xi symbol designates the ith parameter (1-based, e.g. x1, x2, x3, etc.), or all remaining parameters for xi itself. This is not a replacement for lambda. The xi forms cannot be nested.
|
||||
|
||||
|
@ -122,7 +122,7 @@
|
||||
"Returns a function which is the composition of several forms."
|
||||
`(fn [var] (ap-pipe var ~@forms)))
|
||||
|
||||
(defmacro xi [function &rest body]
|
||||
(defmacro xi [&rest body]
|
||||
"Returns a function with parameters implicitly determined by the presence in
|
||||
the body of xi parameters. An xi symbol designates the ith parameter
|
||||
(1-based, e.g. x1, x2, x3, etc.), or all remaining parameters for xi itself.
|
||||
@ -143,5 +143,5 @@
|
||||
~@(if (in 'xi flatbody)
|
||||
'(&rest xi)
|
||||
'())]
|
||||
(~function ~@body)))
|
||||
(~@body)))
|
||||
|
||||
|
@ -134,4 +134,8 @@
|
||||
(assert-equal ((xi identity [x3 x1]) 1 2 3) [3 1])
|
||||
;; test nesting
|
||||
(assert-equal ((xi identity [x1 (, x2 [x3] "Hy" [xi])]) 1 2 3 4 5)
|
||||
[1 (, 2 [3] "Hy" [(, 4 5)])]))
|
||||
[1 (, 2 [3] "Hy" [(, 4 5)])])
|
||||
;; test arg as function
|
||||
(assert-equal ((xi x1 2 4) +) 6)
|
||||
(assert-equal ((xi x1 2 4) -) -2)
|
||||
(assert-equal ((xi x1 2 4) /) 0.5))
|
||||
|
Loading…
Reference in New Issue
Block a user