Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Closures

Name: Anonymous 2011-05-23 0:34

can someone explain them to me.. I'm thinken they might be simple but my pee sized brain can't comprehend most definitions off of google

Name: Anonymous 2011-05-23 4:21

>>31
(define (f x y z) (+ x (- y z))
(define f-curried ((curry f) 2))
(define f-partially-applied (papply f 2))

(f-curried 3 4) ; should be an error
((f-curried 3) 4) ; ok
(f-partially-applied 3 4) ; ok
((f-partially-applied 3) 4) ; should be an error

(curry f) ≡ (lambda (x) (lambda (y) (lambda (z) (f x y z))))
(papply f . a) ≡ (lambda b (apply f (append a b)))


In Lisp:
(defun f (x y z) (+ x (- y z)))
(setf (symbol-function 'f-curried) (funcall (curry f) 2))
(setf (symbol-function 'f-partially-applied) (papply f 2))

(f-curried 3 4) ; error
(funcall (f-curried 3) 4) ; ok
(f-partially-applied 3 4) ; ok
(funcall (f-partially-applied 3) 4) ; error


Haskell's functions all take only one argument. Functions with multiple arity are curried, they return a function that takes the other arguments.

From the page you just linked: http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application
From Partial Application: http://en.wikipedia.org/wiki/Partial_application#Definitions

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List