Skip to content

Instantly share code, notes, and snippets.

@zealoushacker
Created January 14, 2014 06:45
Show Gist options
  • Select an option

  • Save zealoushacker/8414167 to your computer and use it in GitHub Desktop.

Select an option

Save zealoushacker/8414167 to your computer and use it in GitHub Desktop.
A closure containing a pure function
=begin
Functions containing no free/unbound variables are called pure functions.
Functions containing one or more free variables are called closures.
Adapted from the quick exercise in https://leanpub.com/javascript-allonge/read#closures
In turn, this is adapted from https://gist.github.com/zealoushacker/8091614
If pure functions can contain closures, can a closure contain a pure function?
Attempt to compose a closure that contains a pure function.
Many thanks to @raganwald!
=end
lambda do |x|
lambda do |y|
lambda { |n| n }
return x
end
end["foo"]["bar"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment