MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / standard_env

Function standard_env

02-array-seq/lispy/py3.10/lis.py:78–117  ·  view source on GitHub ↗

An environment with some Scheme standard procedures.

()

Source from the content-addressed store, hash-verified

76
77
78def standard_env() -> Environment:
79 "An environment with some Scheme standard procedures."
80 env = Environment()
81 env.update(vars(math)) # sin, cos, sqrt, pi, ...
82 env.update({
83 '+': op.add,
84 '-': op.sub,
85 '*': op.mul,
86 '/': op.truediv,
87 'quotient': op.floordiv,
88 '>': op.gt,
89 '<': op.lt,
90 '>=': op.ge,
91 '<=': op.le,
92 '=': op.eq,
93 'abs': abs,
94 'append': lambda *args: list(chain(*args)),
95 'apply': lambda proc, args: proc(*args),
96 'begin': lambda *x: x[-1],
97 'car': lambda x: x[0],
98 'cdr': lambda x: x[1:],
99 'cons': lambda x, y: [x] + y,
100 'display': lambda x: print(lispstr(x)),
101 'eq?': op.is_,
102 'equal?': op.eq,
103 'filter': lambda *args: list(filter(*args)),
104 'length': len,
105 'list': lambda *x: list(x),
106 'list?': lambda x: isinstance(x, list),
107 'map': lambda *args: list(map(*args)),
108 'max': max,
109 'min': min,
110 'not': op.not_,
111 'null?': lambda x: x == [],
112 'number?': lambda x: isinstance(x, (int, float)),
113 'procedure?': callable,
114 'round': round,
115 'symbol?': lambda x: isinstance(x, Symbol),
116 })
117 return env
118
119
120################ Interaction: A REPL

Callers 4

lis_test.pyFile · 0.90
std_envFunction · 0.90
replFunction · 0.70
runFunction · 0.70

Calls 3

EnvironmentClass · 0.70
lispstrFunction · 0.70
updateMethod · 0.45

Tested by 1

std_envFunction · 0.72