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 0:41

>>1
Arright. We can do this. We'll use Haskell as an example, since I'm more comfortable with it than Lisp, and Javascript is a pain in the ass.

A closure is a data structure that functional languages use to represent a half-called function. It has some of its arguments specified, but not all of them. You can pass it around as an object, and use it as a function, but it still needs more arguments specified before it will actually trigger.

Consider a function called add:


add :: Int -> Int -> Int
add x y = x + y


If you write z = (add 1), then z is now the following function:


z :: Int -> Int
z y = 1 + y


z is a closure of add. This also means that the syntax (add 1) 2 is equivalent to add 1 2.

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