Commit 6a24980c authored by Smith Dhumbumroong's avatar Smith Dhumbumroong

add PARTIAL-APPLY and REVERSE-PARTIAL-APPLY as aliases for CURRY and RCURRY, respectively

Following the discussion in the following mailing list threads: [0] and
[1], and the conclusion reached in this [2] email, I have added
PARTIAL-APPLY and REVERSE-PARTIAL-APPLY function as the aliases/synonyms
for the CURRY and RCURRY function, respectively.

I have also added the tests for the aforementioned two new
functions. All of these tests are (obviously) based on the tests of the
CURRY and RCURRY function.

[0] http://www.mail-archive.com/alexandria-devel@common-lisp.net/msg00199.html
[1] https://www.mail-archive.com/alexandria-devel@common-lisp.net/msg00417.html
[2] https://www.mail-archive.com/alexandria-devel@common-lisp.net/msg00419.html
parent 6316c0dd
......@@ -130,6 +130,10 @@ it is called with to FUNCTION."
(lambda (&rest more)
(apply ,fun ,@curries more)))))
(setf (fdefinition 'partial-apply) #'curry)
(setf (compiler-macro-function 'partial-apply) (compiler-macro-function 'curry))
(defun rcurry (function &rest arguments)
"Returns a function that applies the arguments it is called
with and ARGUMENTS to FUNCTION."
......@@ -139,6 +143,8 @@ with and ARGUMENTS to FUNCTION."
(declare (dynamic-extent more))
(multiple-value-call fn (values-list more) (values-list arguments)))))
(setf (fdefinition 'reverse-partial-apply) #'rcurry)
(defmacro named-lambda (name lambda-list &body body)
"Expands into a lambda-expression within whose BODY NAME denotes the
corresponding function."
......
......@@ -45,12 +45,14 @@
#:compose
#:conjoin
#:curry
#:partial-apply
#:disjoin
#:ensure-function
#:ensure-functionf
#:multiple-value-compose
#:named-lambda
#:rcurry
#:reverse-partial-apply
;; Lists
#:alist-plist
#:appendf
......
......@@ -528,6 +528,36 @@
x))
(42 42 2))
(deftest partial-apply.1
(let ((papplied (partial-apply '+ 3)))
(funcall papplied 1 5))
9)
(deftest partial-apply.2
(let ((papplied (locally (declare (notinline partial-apply))
(partial-apply '* 2 3))))
(funcall papplied 7))
42)
(deftest partial-apply.3
(let ((papplied-form (funcall (compiler-macro-function 'partial-apply)
'(partial-apply '/ 8)
nil)))
(let ((fun (funcall (compile nil `(lambda () ,papplied-form)))))
(funcall fun 2)))
4)
(deftest partial-apply.4
(let* ((x 1)
(papplied (partial-apply (progn
(incf x)
(lambda (y z) (* x y z)))
3)))
(list (funcall papplied 7)
(funcall papplied 7)
x))
(42 42 2))
(deftest rcurry.1
(let ((r (rcurry '/ 2)))
(funcall r 8))
......@@ -544,6 +574,22 @@
x))
(42 42 2))
(deftest reverse-partial-apply.1
(let ((r (reverse-partial-apply '/ 2)))
(funcall r 8))
4)
(deftest reverse-partial-apply.2
(let* ((x 1)
(papplied (reverse-partial-apply (progn
(incf x)
(lambda (y z) (* x y z)))
3)))
(list (funcall papplied 7)
(funcall papplied 7)
x))
(42 42 2))
(deftest named-lambda.1
(let ((fac (named-lambda fac (x)
(if (> x 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment