Norvig’s originals and updates
This directory contains:
original/: Norvig’slis.py,lispy.py, and thelispytest.pycustom test script for testing both;py3.10/:lis.pywith type hints, pattern matching, and minor edits—requires Python 3.10.
The py3.10/ directory also has lis_test.py
to run with pytest, including the
lis_tests
suite from original/lispytest.py, and additional
separate tests for each expression and special form handled by
evaluate.
Provenance, Copyright and License
lis.py is published
in the norvig/pytudes
repository on Github. The copyright holder is Peter Norvig and the code
is licensed under the MIT
license.
Changes to Norvig’s code
I made small changes to the programs in original/:
- In
lis.py:- The
Procedureclass accepts a list of expressions as thebody, and__call__evaluates those expressions in order, and returns the value of the last. This is consistent with Scheme’slambdasyntax and provided a useful example for pattern matching. - In the
elifblock for'lambda', I added the*in front of the*bodyvariable in the tuple unpacking to capture the expressions as a list, before calling theProcedureconstructor.
- The
- In
lispy.pyI made changes and a pull request to make it run on Python 3.
Luciano Ramalho
June 29, 2021