| Paste number 36324: | Currying macro |
| Pasted by: | pjd |
| When: | 3 years, 6 days ago |
| Share: | Tweet this! | http://paste.lisp.org/+S10 |
| Channel: | #scheme |
| Paste contents: |
(define-syntax curried
(syntax-rules ()
((curried () body ...) (lambda () body ...))
((curried (arg) body ...) (lambda (arg) body ...))
((curried (arg args ...) body ...)
(lambda (arg . rest)
(let ((next (curried (args ...) body ...)))
(if (null? rest)
next
(apply next rest)))))))
(define-syntax define-curried
(syntax-rules ()
((define-curried (name args ...) body ...)
(define name (curried (args ...) body ...)))))
(define-curried (mad a b c)
(+ (* a b) c))
(mad 2 3 4)
((mad 2) 3 4)
((mad 2 3) 4)
(((mad 2) 3) 4)
This paste has no annotations.