Higher-order functions: Difference between revisions

(Coffeescript implementation)
Line 416:
Using a function stored in a variable:
 
<lang coffeescript>fn = -> return 8
return 8
 
sum = (a, b) -> a() + b()
 
sum(fn, fn) # => 16
</lang>
Line 431 ⟶ 428:
return "Smashed #{ingredient}"
 
contents = smash ingredient for ingredient in bowl</lang>
<pre# => ["Smashed Cheese", "Smashed Tomato"]</pre>
</lang>
 
A function that returns a function that returns a function that returns a function that returns 2, immediately executed:
 
<lang coffeescript>(-> -> -> -> 2 )()()()() # => 2</lang>
 
A function that takes a function that takes a function argument:
 
<lang coffeescript>((x)->
<pre>["Smashed Cheese", "Smashed Tomato"]</pre>
2 + x(-> 5)
)((y) -> y()+3)
# result: 10</lang>
 
=={{header|Common Lisp}}==