mirror of
https://github.com/kanaka/mal.git
synced 2024-11-11 00:52:44 +03:00
4eb88ef295
Tested on UCBLogo 6.0 with some minor tweaks (for performance and adding a `timems` function). The tweaks are performed during Docker image creation (see Dockerfile). Tests of step 5 are skipped because UCBLogo is too slow. Interop is available via `(logo-eval "logo code to run")`. The `examples` directory contains a Mal example of drawing a tree using turtle graphics.
52 lines
1.0 KiB
Plaintext
52 lines
1.0 KiB
Plaintext
load "../logo/printer.lg
|
|
load "../logo/types.lg
|
|
|
|
to env_new :outer :binds :exprs
|
|
localmake "data []
|
|
if not emptyp :binds [
|
|
localmake "i 0
|
|
while [:i < _count :binds] [
|
|
ifelse (nth :binds :i) = [symbol &] [
|
|
localmake "val drop :exprs :i
|
|
make "i (:i + 1)
|
|
localmake "key nth :binds :i
|
|
] [
|
|
localmake "val nth :exprs :i
|
|
localmake "key nth :binds :i
|
|
]
|
|
make "data hashmap_put :data :key :val
|
|
make "i (:i + 1)
|
|
]
|
|
]
|
|
output listtoarray list :outer :data
|
|
end
|
|
|
|
to env_outer :env
|
|
output item 1 :env
|
|
end
|
|
|
|
to env_data :env
|
|
output item 2 :env
|
|
end
|
|
|
|
to env_find :env :key
|
|
if emptyp :env [output []]
|
|
localmake "val hashmap_get env_data :env :key
|
|
ifelse emptyp :val [
|
|
output env_find env_outer :env :key
|
|
] [
|
|
output :env
|
|
]
|
|
end
|
|
|
|
to env_get :env :key
|
|
localmake "foundenv env_find :env :key
|
|
if emptyp :foundenv [(throw "error sentence (word "' pr_str :key "true "' ) [not found])]
|
|
output hashmap_get env_data :foundenv :key
|
|
end
|
|
|
|
to env_set :env :key :val
|
|
.setitem 2 :env hashmap_put env_data :env :key :val
|
|
output :val
|
|
end
|