forked from uehaj/LispBuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Env.groovy
58 lines (49 loc) · 1020 Bytes
/
Env.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Env {
Map localEnv = [:]
def parentEnv
Env(env = null) {
if (env == null) {
parentEnv = [:]
Functions.registerFunctions(parentEnv)
}
else {
this.parentEnv = env
}
}
def getProperty(String key) {
if (localEnv.containsKey(key)) {
return localEnv[key]
}
if (parentEnv != null) {
return parentEnv[key]
}
null
}
void setProperty(String key, value) {
localEnv[key] = value
}
def containsKey(key) {
if (localEnv.containsKey(key)) {
return true
}
if (parentEnv.containsKey(key)) {
return true
}
return false
}
String toString() {
"local:" + localEnv.toString() + "parent:" + parentEnv.toString()
}
def eval(Closure c) {
def bx = new LispBuilder()
return bx.build(c).eval(this)
}
def eval2(Closure c) {
def bx = new LispBuilder2()
return bx.build(c).eval(this)
}
def eval3(Closure c) {
def bx = new LispBuilder3()
return bx.build(c).eval(this)
}
}