From a06c8a9af9f6164e7667a7e6d79dd91b2fb6ed8a Mon Sep 17 00:00:00 2001 From: gilch Date: Wed, 12 Aug 2015 08:45:43 -0600 Subject: [PATCH] xi parameter may appear in function position --- docs/contrib/anaphoric.rst | 2 +- hy/contrib/anaphoric.hy | 4 ++-- tests/native_tests/contrib/anaphoric.hy | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/contrib/anaphoric.rst b/docs/contrib/anaphoric.rst index a241cd3..db36ffc 100644 --- a/docs/contrib/anaphoric.rst +++ b/docs/contrib/anaphoric.rst @@ -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. diff --git a/hy/contrib/anaphoric.hy b/hy/contrib/anaphoric.hy index df80e68..dc6bb24 100644 --- a/hy/contrib/anaphoric.hy +++ b/hy/contrib/anaphoric.hy @@ -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))) diff --git a/tests/native_tests/contrib/anaphoric.hy b/tests/native_tests/contrib/anaphoric.hy index 20b7848..175231d 100644 --- a/tests/native_tests/contrib/anaphoric.hy +++ b/tests/native_tests/contrib/anaphoric.hy @@ -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))