Skip to content

Commit

Permalink
calculate free variables
Browse files Browse the repository at this point in the history
  • Loading branch information
billhails committed Nov 17, 2024
1 parent 6822655 commit f0fdb7f
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ifeq ($(MODE),production)
CCMODE:= -O2
EXTRA_DEFINES:= -DPRODUCTION_BUILD -DBUILD_MODE=2
else
$(error invalid MODE $(MODE))
$(error invalid MODE=$(MODE), allowed values: debugging, testing or production)
endif
endif
endif
Expand Down
4 changes: 2 additions & 2 deletions fn/ceskf.fn
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ let
(Σ(cexp(letrec(bindings, body)), ρ, σ, κ, ς)) {
let
inds = indices(bindings, σ);
ks = list.map(unsafe fn (#(k, _)) { k }, bindings);
ks = list.map(fn (#(k, _)) { k }, bindings);
e = zipEnv(ks, inds, ρ);
tempStore = list.repeat_prefix(list.length(inds), f, σ);
s = list.map_prefix(A(e, tempStore),
list.map(unsafe fn (#(_, v)) { v }, bindings),
list.map(fn (#(_, v)) { v }, bindings),
σ);
in
Σ(body, e, s, κ, ς)
Expand Down
20 changes: 20 additions & 0 deletions fn/dictionary.fn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ fn foreach {
}
}

fn keys (d) {
let fn h {
(E, lst) | (EE, lst) { lst }
(D(_, l, #(k, _), r), lst) {
h(l, k @ h(r, lst))
}
}
in h(d, [])
}

fn values (d) {
let fn h {
(E, lst) | (EE, lst) { lst }
(D(_, l, #(_, v), r), lst) {
h(l, v @ h(r, lst))
}
}
in h(d, [])
}

fn balance {
(B, D(R, D(R, a, x, b), y, c), z, d) |
(B, D(R, a, x, D(R, b, y, c)), z, d) |
Expand Down
12 changes: 12 additions & 0 deletions fn/listutils.fn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ fn member {
(x, _ @ t) { member(x, t) }
}

// unique: list(#a) -> list(#a)
fn unique {
([]) { [] }
(h @ t) {
if (member(h, t)) {
unique(t)
} else {
h @ unique(t)
}
}
}

// exclude: list(#t) -> list(#t) -> list(#t)
fn exclude {
(items, []) { [] }
Expand Down
Loading

0 comments on commit f0fdb7f

Please sign in to comment.