Skip to content

Instantly share code, notes, and snippets.

View IwoHerka's full-sized avatar

Iwo Herka IwoHerka

View GitHub Profile
(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)
@IwoHerka
IwoHerka / constant.js
Created May 18, 2020 16:42
Constant function in JavaScript
const cons = n => () => n
@IwoHerka
IwoHerka / successor.js
Created May 18, 2020 16:41
Successor function in JavaScript
const succ = n => n + 1
@IwoHerka
IwoHerka / projection.js
Created May 18, 2020 16:40
Projection in JavaScript
const proj = i => (...ns) => ns[i - 1]
@IwoHerka
IwoHerka / composition.js
Created May 18, 2020 16:38
Composition in JavaScript
const comp = (h, ...gs) => (...xs) => h(...gs.map(g => g(...xs)))
@IwoHerka
IwoHerka / recursion.js
Last active May 22, 2020 10:22
Primitive recursion in JavaScript
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
}
@IwoHerka
IwoHerka / minimisation.js
Created May 18, 2020 16:22
Minimasation in JavaScript
function minim(f, max) {
function u(...xs) {
let z = 0
while (f(z, ...xs) != 0) {
if (z == max) {
return undefined
} else {
z += 1
}
@IwoHerka
IwoHerka / example1.py
Created October 15, 2019 16:24
Example 1
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.
@IwoHerka
IwoHerka / example2.py
Created October 15, 2019 16:24
Example 2
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)
@IwoHerka
IwoHerka / ex.clj
Created September 15, 2019 15:49
Lightning Hiccup Tutorial Example 17
[:p
{:class "some-class"
" "
(when active? "active"}]