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

Function standard_env

18-with-match/lispy/original/lis.py:25–54  ·  view source on GitHub ↗

An environment with some Scheme standard procedures.

()

Source from the content-addressed store, hash-verified

23################ Global Environment
24
25def standard_env():
26 "An environment with some Scheme standard procedures."
27 env = {}
28 env.update(vars(math)) # sin, cos, sqrt, pi, ...
29 env.update({
30 '+':op.add, '-':op.sub, '*':op.mul, '/':op.truediv,
31 '>':op.gt, '<':op.lt, '>=':op.ge, '<=':op.le, '=':op.eq,
32 'abs': abs,
33 'append': op.add,
34 'apply': lambda proc, args: proc(*args),
35 'begin': lambda *x: x[-1],
36 'car': lambda x: x[0],
37 'cdr': lambda x: x[1:],
38 'cons': lambda x,y: [x] + y,
39 'eq?': op.is_,
40 'equal?': op.eq,
41 'length': len,
42 'list': lambda *x: list(x),
43 'list?': lambda x: isinstance(x,list),
44 'map': lambda *args: list(map(*args)),
45 'max': max,
46 'min': min,
47 'not': op.not_,
48 'null?': lambda x: x == [],
49 'number?': lambda x: isinstance(x, Number),
50 'procedure?': callable,
51 'round': round,
52 'symbol?': lambda x: isinstance(x, Symbol),
53 })
54 return env
55
56global_env = standard_env()
57

Callers 1

lis.pyFile · 0.70

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected