python.2: fix tests, use source checkers and more python3 features
Check the whole code with flake8, pylint and mypy.
Report all possible errors with extensive context.
Demonstrate iterators, decorators, functional tools, chain maps,
dataclasses, match statements, assignments expressions.
Implement environments with python chain maps.
Rewrite the reader without external dependencies (but inspired by the
ptk library). The motivation was that no external library is fully
type-checked for now.
Avoid name clashes when possible (print, read, readline, types).
Write the readline history file at exit, not after each prompt.
Replace printer.pr_str as methods of MAL objects. This is idiomatic
python, and improves the error reporting.
Change some representations so that the python equality matches the
MAL equality. The recursion is now implicit.
Remove -O from ./run. It took me a while to understand that run-time
assertions were disabled! MAL is about development, not performance.
Dispatch the special forms from a dict, for readability (pylint
rightfully complains that there are too many return statements in
eval_()).
Copy the recursion overflow fix, the python interaction from the first
python implementation.
Add tests detecting that nil false 0 () [] "" are distinct, and that 0
() are not False when tested (in python False == 0 and an empty
container is tested ).
Add tests checking that metadata does not affect equality (they do
with a naive python dataclass).
2024-08-22 06:56:10 +02:00
|
|
|
# Env is defined in mal_types.py in order to avoid a circular dependency.
|
|
|
|
|
from collections.abc import Sequence
|
2019-08-18 10:05:48 -07:00
|
|
|
|
python.2: fix tests, use source checkers and more python3 features
Check the whole code with flake8, pylint and mypy.
Report all possible errors with extensive context.
Demonstrate iterators, decorators, functional tools, chain maps,
dataclasses, match statements, assignments expressions.
Implement environments with python chain maps.
Rewrite the reader without external dependencies (but inspired by the
ptk library). The motivation was that no external library is fully
type-checked for now.
Avoid name clashes when possible (print, read, readline, types).
Write the readline history file at exit, not after each prompt.
Replace printer.pr_str as methods of MAL objects. This is idiomatic
python, and improves the error reporting.
Change some representations so that the python equality matches the
MAL equality. The recursion is now implicit.
Remove -O from ./run. It took me a while to understand that run-time
assertions were disabled! MAL is about development, not performance.
Dispatch the special forms from a dict, for readability (pylint
rightfully complains that there are too many return statements in
eval_()).
Copy the recursion overflow fix, the python interaction from the first
python implementation.
Add tests detecting that nil false 0 () [] "" are distinct, and that 0
() are not False when tested (in python False == 0 and an empty
container is tested ).
Add tests checking that metadata does not affect equality (they do
with a naive python dataclass).
2024-08-22 06:56:10 +02:00
|
|
|
from mal_types import Env, Error, Form, List, pr_seq
|
2019-08-18 10:05:48 -07:00
|
|
|
|
|
|
|
|
|
python.2: fix tests, use source checkers and more python3 features
Check the whole code with flake8, pylint and mypy.
Report all possible errors with extensive context.
Demonstrate iterators, decorators, functional tools, chain maps,
dataclasses, match statements, assignments expressions.
Implement environments with python chain maps.
Rewrite the reader without external dependencies (but inspired by the
ptk library). The motivation was that no external library is fully
type-checked for now.
Avoid name clashes when possible (print, read, readline, types).
Write the readline history file at exit, not after each prompt.
Replace printer.pr_str as methods of MAL objects. This is idiomatic
python, and improves the error reporting.
Change some representations so that the python equality matches the
MAL equality. The recursion is now implicit.
Remove -O from ./run. It took me a while to understand that run-time
assertions were disabled! MAL is about development, not performance.
Dispatch the special forms from a dict, for readability (pylint
rightfully complains that there are too many return statements in
eval_()).
Copy the recursion overflow fix, the python interaction from the first
python implementation.
Add tests detecting that nil false 0 () [] "" are distinct, and that 0
() are not False when tested (in python False == 0 and an empty
container is tested ).
Add tests checking that metadata does not affect equality (they do
with a naive python dataclass).
2024-08-22 06:56:10 +02:00
|
|
|
def call_env(env: Env, parms: Sequence[str], args: Sequence[Form]) -> Env:
|
|
|
|
|
match parms:
|
|
|
|
|
case [*required, '&', rest]:
|
|
|
|
|
if len(args) < len(required):
|
|
|
|
|
raise Error('not enough arguments for fn*['
|
|
|
|
|
+ ' '.join(parms) + ']: ' + pr_seq(args))
|
|
|
|
|
fn_env = env.new_child(dict(zip(required, args)))
|
|
|
|
|
fn_env[rest] = List(args[len(required):])
|
|
|
|
|
return fn_env
|
|
|
|
|
case _:
|
|
|
|
|
if len(args) != len(parms):
|
|
|
|
|
raise Error('bad argument count for fn*['
|
|
|
|
|
+ ' '.join(parms) + ']: ' + pr_seq(args))
|
|
|
|
|
return env.new_child(dict(zip(parms, args)))
|