ShareThis

Showing posts with label Scheme. Show all posts
Showing posts with label Scheme. Show all posts

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)

[Scheme] How to merge two lists

Say you have '( 1 2 3) and '(4 5 6), and you are using (cons lst1 lst2), getting ((1 2 3) 4 5 6)

You can get one list by using append function