ShareThis

Friday, September 7, 2012

[Scheme] How to curry a function

This is a new concept on my Scheme homework. The request is to turn a somewhat curried script into a fully-curried script:


(define noncurried?
    (lambda (x y)
       (lambda (z t) 
        (> (+ x y) (+ z t))
       )
    )
)

; In English, this function returns #t if x and y are greater than z and t, or #f if they are less than.
In turning this function into a fully curried function, we need to split up the lambda expressions and add two more, such that, each parameter that is part of the function is defined in its own lambda expression. 

(define curried?
  (lambda (x)
    (lambda (y)
      (lambda (z)
        (lambda (t)
            (> (+ x y) (+ z t))
          )
        )
     )
   )
)

Interesting in how to call curried? 


((((curried? 1) 2) 3) 4)

0 comments:

Post a Comment