Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Momchil Ivanov
alexandria
Commits
6fb9452b
Commit
6fb9452b
authored
Nov 02, 2011
by
James M. Lawrence
Committed by
Nikodemus Siivola
Nov 02, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug in CURRY compiler-macro
Multiple evaluation of the function argument, oops.
parent
268b6da4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
functions.lisp
functions.lisp
+8
-4
tests.lisp
tests.lisp
+22
-0
No files found.
functions.lisp
View file @
6fb9452b
(
in-package
:alexandria
)
(
in-package
:alexandria
)
(
declaim
(
inline
ensure-function
))
; to propagate return type.
;;; To propagate return type and allow the compiler to eliminate the IF when
;;; it is known if the argument is function or not.
(
declaim
(
inline
ensure-function
))
(
declaim
(
ftype
(
function
(
t
)
(
values
function
&optional
))
(
declaim
(
ftype
(
function
(
t
)
(
values
function
&optional
))
ensure-function
))
ensure-function
))
...
@@ -120,11 +122,13 @@ it is called with to FUNCTION."
...
@@ -120,11 +122,13 @@ it is called with to FUNCTION."
(
multiple-value-call
fn
(
values-list
arguments
)
(
values-list
more
)))))
(
multiple-value-call
fn
(
values-list
arguments
)
(
values-list
more
)))))
(
define-compiler-macro
curry
(
function
&rest
arguments
)
(
define-compiler-macro
curry
(
function
&rest
arguments
)
(
let
((
curries
(
make-gensym-list
(
length
arguments
)
"CURRY"
)))
(
let
((
curries
(
make-gensym-list
(
length
arguments
)
"CURRY"
))
`
(
let
,
(
mapcar
#'
list
curries
arguments
)
(
fun
(
gensym
"FUN"
)))
`
(
let
((
,
fun
(
ensure-function
,
function
))
,@
(
mapcar
#'
list
curries
arguments
))
(
declare
(
optimize
(
speed
3
)
(
safety
1
)
(
debug
1
)))
(
declare
(
optimize
(
speed
3
)
(
safety
1
)
(
debug
1
)))
(
lambda
(
&rest
more
)
(
lambda
(
&rest
more
)
(
apply
,
fun
ction
,@
curries
more
)))))
(
apply
,
fun
,@
curries
more
)))))
(
defun
rcurry
(
function
&rest
arguments
)
(
defun
rcurry
(
function
&rest
arguments
)
"Returns a function that applies the arguments it is called
"Returns a function that applies the arguments it is called
...
...
tests.lisp
View file @
6fb9452b
...
@@ -508,11 +508,33 @@
...
@@ -508,11 +508,33 @@
(
funcall
fun
2
)))
(
funcall
fun
2
)))
4
)
4
)
(
deftest
curry.4
(
let*
((
x
1
)
(
curried
(
curry
(
progn
(
incf
x
)
(
lambda
(
y
z
)
(
*
x
y
z
)))
3
)))
(
list
(
funcall
curried
7
)
(
funcall
curried
7
)
x
))
(
42
42
2
))
(
deftest
rcurry.1
(
deftest
rcurry.1
(
let
((
r
(
rcurry
'/
2
)))
(
let
((
r
(
rcurry
'/
2
)))
(
funcall
r
8
))
(
funcall
r
8
))
4
)
4
)
(
deftest
rcurry.2
(
let*
((
x
1
)
(
curried
(
rcurry
(
progn
(
incf
x
)
(
lambda
(
y
z
)
(
*
x
y
z
)))
3
)))
(
list
(
funcall
curried
7
)
(
funcall
curried
7
)
x
))
(
42
42
2
))
(
deftest
named-lambda.1
(
deftest
named-lambda.1
(
let
((
fac
(
named-lambda
fac
(
x
)
(
let
((
fac
(
named-lambda
fac
(
x
)
(
if
(
>
x
1
)
(
if
(
>
x
1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment