This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn eval-statement | |
[[stmt env] [stack store]] | |
(case (:tag stmt) | |
:skip [stack store] | |
;; let creates a number of name bindings | |
;; and pushes its block onto the stack. | |
:let (let [{:keys [names block]} stmt | |
;; Initialize new variables in the store and | |
;; associate them with specified names in the env. | |
[store' env'] (append-store store env names) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cons = n => () => n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const succ = n => n + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const proj = i => (...ns) => ns[i - 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const comp = (h, ...gs) => (...xs) => h(...gs.map(g => g(...xs))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function recur(g, h) { | |
function p(y, ...xs) { | |
if (y == 0) // If index is 0, | |
return g(...xs) // end with base case. | |
else // Otherwise, | |
return h(y - 1, p(y - 1, ...xs), ...xs) // perform inductive step. | |
} | |
return p | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minim(f, max) { | |
function u(...xs) { | |
let z = 0 | |
while (f(z, ...xs) != 0) { | |
if (z == max) { | |
return undefined | |
} else { | |
z += 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = dict() # 'x' is a name of the memory address. | |
x['y'] = 'z' | |
def foo(d): | |
del d['y'] # Memory location is modified. | |
foo(x) | |
assert x['y'] == 'z' # KeyError is thrown. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert id(100) == id(100) # OK | |
x = 100 | |
y = 100 | |
assert id(x) == id(y) # OK | |
x = 1000 | |
y = 1000 | |
assert id(1000) == id(1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[:p | |
{:class "some-class" | |
" " | |
(when active? "active"}] |