1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-11 21:57:38 +03:00
mal/impls/sml/env.sml

12 lines
396 B
Standard ML
Raw Permalink Normal View History

2021-04-01 19:12:41 +03:00
fun set s v (NS d) = d := (s, v) :: (!d |> List.filter (not o eq s o #1))
2021-03-26 14:05:05 +03:00
2021-04-01 19:12:41 +03:00
fun get (NS d) s = !d |> List.find (eq s o #1) |> Option.map #2
2021-03-26 19:29:52 +03:00
2021-04-01 19:12:41 +03:00
fun def s v (ENV ns) = set s v ns
| def s v (INNER (ns, _)) = set s v ns
fun lookup (ENV ns) s = get ns s
| lookup (INNER (ns, outer)) s = optOrElse (get ns s) (fn () => lookup outer s)
fun inside outer = INNER (NS (ref []), outer)