Skip to content

Instantly share code, notes, and snippets.

(defn my-get
"@param {*} m
@param {*} k
@return {nil|Object}"
[m k]
(get m k))
(defn foo
"@param {!Object} x" ;; non-nullable
[x] x)
@drewlesueur
drewlesueur / y_combinator.md
Created June 27, 2012 06:21
How to generate the Y-Combinator in coffeescript

How to Generate the Y-Combinator in CoffeeScript

Problem

For fun, let's say you are programming in a language that doesn't allow variable assignments and you still want to make a recursive function. Although you can't assign variables, you can use functions (and enclosed function arguments). Can you make a function recursive without calling it by name?

Lets try implementing the factorial function. First with a function calling itself by name, then with a funtion that never calls itself by name

Here is the implementation of factorial that calls itself by name. It's a simple recursive function