-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcj-curry.scm
39 lines (32 loc) · 936 Bytes
/
cj-curry.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;;; Copyright 2010, 2011 by Christian Jaeger <ch@christianjaeger.ch>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License (GPL) as published
;;; by the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
(require define-macro-star
fixnum
test
cj-env
cj-symbol)
;; not sure this is the end of ideas, but, giving it a try
;; (This is an alternative to |cut| from the srfis)
(define-macro* (curry n-more-args f . args)
(assert** natural? n-more-args
(let rec ((n n-more-args)
(vs args))
(with-gensym
v
`(lambda (,v)
,(let ((n (dec n))
(vs (cons v vs)))
(if (zero? n)
`(,f ,@(reverse vs))
(rec n vs))))))))
(TEST
> ((curry 1 vector) 'a)
#(a)
> (((curry 2 vector) 'a) 'b)
#(a b)
> ((curry 1 vector 'zero) 'a)
#(zero a)
)