mirror of
https://github.com/kanaka/mal.git
synced 2024-10-27 06:40:14 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
56 lines
877 B
Julia
56 lines
877 B
Julia
module env
|
|
|
|
export Env, env_set, env_find, env_get
|
|
|
|
type Env
|
|
outer::Any
|
|
data::Dict{Symbol,Any}
|
|
end
|
|
|
|
function Env()
|
|
Env(nothing, Dict())
|
|
end
|
|
|
|
function Env(outer)
|
|
Env(outer, Dict())
|
|
end
|
|
|
|
function Env(outer, binds, exprs)
|
|
e = Env(outer, Dict())
|
|
for i=1:length(binds)
|
|
if binds[i] == :&
|
|
e.data[binds[i+1]] = exprs[i:end]
|
|
break
|
|
else
|
|
e.data[binds[i]] = exprs[i]
|
|
end
|
|
end
|
|
e
|
|
end
|
|
|
|
|
|
function env_set(env::Env, k::Symbol, v)
|
|
env.data[k] = v
|
|
end
|
|
|
|
function env_find(env::Env, k::Symbol)
|
|
if haskey(env.data, k)
|
|
env
|
|
elseif env.outer != nothing
|
|
env_find(env.outer, k)
|
|
else
|
|
nothing
|
|
end
|
|
end
|
|
|
|
function env_get(env::Env, k::Symbol)
|
|
e = env_find(env, k)
|
|
if e != nothing
|
|
e.data[k]
|
|
else
|
|
error("'$(string(k))' not found")
|
|
end
|
|
end
|
|
|
|
end
|