example-code-2e/02-array-seq/lispy
2021-08-07 00:44:01 -03:00
..
original sync with O'Reilly Atlas 2021-07-07 23:45:54 -03:00
py3.9 Update README.md 2021-07-08 00:23:56 -03:00
py3.9-no-hints Update README.md 2021-07-10 12:03:04 -03:00
py3.10 sync with O'Reilly Atlas 2021-07-07 23:45:54 -03:00
LICENSE sync with O'Reilly Atlas 2021-07-07 23:45:54 -03:00
README.md updated from Atlas 2021-08-07 00:44:01 -03:00

Norvigs originals and updates

This directory contains:

  • original/: Norvigs lis.py, lispy.py, and the lispytest.py custom test script for testing both;
  • py3.10/: lis.py with 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.

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 Norvigs code

I made small changes to the programs in original/:

  • In lis.py:
    • The Procedure class accepts a list of expressions as the body, and __call__ evaluates those expressions in order, and returns the value of the last. This is consistent with Schemes lambda syntax and provided a useful example for pattern matching.
    • In the elif block for 'lambda', I added the * in front of the *body variable in the tuple unpacking to capture the expressions as a list, before calling the Procedure constructor.
  • In lispy.py I made changes and a pull request to make it run on Python 3.

Luciano Ramalho
June 29, 2021