SIGN IN SIGN UP
# Environment
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
from mal_types import List
class Env():
def __init__(self, outer=None, binds=None, exprs=None):
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
"""If binds is not None, exprs must be an iterable.."""
self.data = {}
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
self.outer = outer
if binds:
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
exprs_it = iter(exprs)
for i in range(len(binds)):
if binds[i] == "&":
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
# binds may be a non-list iterable
self.data[binds[i+1]] = List(exprs_it)
break
else:
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
self.data[binds[i]] = next(exprs_it)
def set(self, key, value):
self.data[key] = value
return value
python: various simplifications Use raw or multiline string litterals to make some hard-coded strings more readable. Replace some lambda constructs with more idiomatic generator expressions, removing several temporary sequences (conversions, contatenations, slices, arguments). Replace definitions with assignments when possible. Replace most python2/3 wrappers with code compatible with both versions. Use a non-printable ASCII characters instead of Unicode characters (in order to avoid unicode in python2). core: Close file open by 'slurp' after reading. coll_Q: remove as obsolete. conj: do not preserve metadata. env: Replace find with an optional argument to get. Search in outer environments with a loop instead of a recursion. (python is not intended for large recursions). readline: Copy the example from the docs. Write the history once. mal_types: clone: copy.copy() everything except callables. functions: construct fn* functions in steps, where they are used (there was no encapsulation anyway) Derive List and Vector from tuple, which is more efficient than list for immutable structures. Remove the need for __getitem__ stuff. maps: provide an asPairs iterator. printer: Introduce a pr_list helper like many other implementations. steps: Remove obviously backported stuff from first steps. Port forward the limitation of the exception backtrace size from step5 to later steps, so that REGRESS=1 does not crash stepA tests. Fix the detection of special forms (strings were accepted as well as symbols). Let try* benefit from TCO.
2024-08-08 16:08:30 +02:00
def get(self, key, return_nil=False):
# Python prefers iteration over recursion.
env = self
while key not in env.data:
env = env.outer
if env is None:
if return_nil:
return None
raise Exception("'" + key + "' not found")
return env.data[key]