Problem 5: K-Curry (100 pts)
Note: You are supposed to finish this problem after Wednesday's lecture about Macros
.
Write the macro k-curry
, which takes in a function fn
, a list of the function's arguments args
, a list of k
values to substitute in for these arguments, and a sorted list of k
non-negative indices
specifying which arguments to pass values from vals
into. k-curry
will return a new function which takes in whatever arguments are remaining from fn
's list of arguments, with the arguments picked out by indices
automatically filled in with the values from vals
.
Hint: Write helper functions outside the macro, and use them inside the macro.
(define-macro (k-curry fn args vals indices)
''YOUR-CODE-HERE
)
;;; Tests
; scm> (define (f a b c d) (- (+ a c) (+ b d)))
; f
; scm> (define minus-six (k-curry f (a b c d) (2 4) (1 3)))
; minus-six
; scm> (minus-six 8 10) ; (- (+ 8 10) (+ 2 4))
; 12