1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/skew/env.sk
Dov Murik 034e82adc5 Add Skew implementation
See http://skew-lang.org/ for details on the Skew language. Currently
Mal only compiles to Javascript, as there are some issues with the C#
backend for Skew (https://github.com/evanw/skew/issues/19).

Tested with Skew 0.7.42.
2016-11-20 10:10:41 +00:00

39 lines
858 B
Plaintext

class Env {
const _outer Env
var _data StringMap<MalVal> = {}
def new(outer Env) {
_outer = outer
}
def new(outer Env, binds List<MalVal>, exprs List<MalVal>) {
_outer = outer
for i in 0..binds.count {
const name = (binds[i] as MalSymbol).val
if name == "&" {
const restName = (binds[i + 1] as MalSymbol).val
_data[restName] = MalList.new(exprs.slice(i))
break
} else {
_data[name] = exprs[i]
}
}
}
def find(key MalSymbol) Env {
if key.val in _data { return self }
return _outer?.find(key)
}
def get(key MalSymbol) MalVal {
const env = find(key)
if env == null { throw MalError.new("'" + key.val + "' not found") }
return env._data[key.val]
}
def set(key MalSymbol, value MalVal) MalVal {
_data[key.val] = value
return value
}
}