mirror of
https://github.com/kanaka/mal.git
synced 2024-09-19 09:38:28 +03:00
Merge pull request #476 from rectalogic/python.2-env
Fix python.2 Env.find implementation.
This commit is contained in:
commit
0279f85f35
@ -12,10 +12,8 @@ class Env(object):
|
||||
binds: Optional[List[MalExpression]] = None,
|
||||
exprs: Optional[List[MalExpression]] = None,
|
||||
) -> None:
|
||||
if outer:
|
||||
self._data: Dict[str, MalExpression] = outer._data.copy()
|
||||
else:
|
||||
self._data = {}
|
||||
self._outer = outer
|
||||
self._data: Dict[str, MalExpression] = {}
|
||||
if binds is not None and exprs is not None:
|
||||
for x in range(0, len(binds)):
|
||||
assert isinstance(binds[x], MalSymbol)
|
||||
@ -32,6 +30,8 @@ class Env(object):
|
||||
def find(self, key: MalExpression) -> Optional["Env"]:
|
||||
if str(key) in self._data:
|
||||
return self
|
||||
if self._outer is not None:
|
||||
return self._outer.find(key)
|
||||
return None
|
||||
|
||||
def get(self, key: MalExpression) -> MalExpression:
|
||||
@ -49,4 +49,4 @@ class Env(object):
|
||||
for d in self._data:
|
||||
env_str += str(d) + ": " + str(self._data[d]) + ", "
|
||||
env_str += "}"
|
||||
return "environment: (data: " + env_str + ")"
|
||||
return f"environment: (data: {env_str} outer: {repr(self._outer) if self._outer is not None else 'None'})"
|
||||
|
@ -126,6 +126,11 @@
|
||||
*ARGV*
|
||||
;=>()
|
||||
|
||||
;;
|
||||
;; Testing that eval sets aa in root scope, and that it is found in nested scope
|
||||
(let* (b 12) (do (eval (read-string "(def! aa 7)")) aa ))
|
||||
;=>7
|
||||
|
||||
;>>> soft=True
|
||||
;>>> optional=True
|
||||
;;
|
||||
@ -175,3 +180,4 @@ mymap
|
||||
;;; Hopefully less problematic characters can be checked together
|
||||
(read-string "1; &()*+,-./:;<=>?@[]^_{|}~")
|
||||
;=>1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user