Let's take the following filter
function:
#lang sicp
(define (filter function sequence)
(if (null? sequence)
nil
(let ((elem (car sequence)) (rest (cdr sequence)))
(if (function elem)
(cons elem (filter function rest))
(filter function rest)))))
(filter (lambda (x) (> x 3)) '(1 2 3 4 5))
Is the following the correct way to convert it to a curried function?
(define filter2
(lambda (function)
(lambda (sequence)
(if (null? sequence)
nil
(let ((elem (car sequence)) (rest (cdr sequence)))
(if (function elem)
(cons elem ((filter2 function) rest))
((filter2 function) rest)))))))
That is, the two differences being:
- Definition: Instead of calling it defining it as
(define func arg1 arg2 ...)
it turns into(define func (lambda (arg1) (lambda (arg2) (... )))
. - Calling: Instead of calling it as
(func arg1 arg2 ...)
it turns into(((func arg1) arg2) ...)
.
Are there any other differences, or it's more like syntactic sugar / differences in parens when doing the two?