updated lis.py examples · codegithubka/example-code-2e@1754a51 · GitHub
Skip to content

Commit 1754a51

Browse files
committed
updated lis.py examples
1 parent f0f1608 commit 1754a51

9 files changed

Lines changed: 639 additions & 7 deletions

File tree

02-array-seq/lispy/LICENSE

Lines changed: 21 additions & 0 deletions

02-array-seq/lispy/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Norvig's originals and updates
2+
3+
This directory contains:
4+
5+
* `original/`:
6+
Norvig's [`lis.py`](https://github.com/norvig/pytudes/blob/c33cd6835a506a57d9fe73e3a8317d49babb13e8/py/lis.py),
7+
[`lispy.py`](https://github.com/norvig/pytudes/blob/c33cd6835a506a57d9fe73e3a8317d49babb13e8/py/lispy.py), and the `lispytest.py` custom test script for testing both;
8+
* `py3.10/`: `lis.py` with type hints, pattern matching, and minor edits—requires Python 3.10.
9+
10+
The `py3.10/` directory also has `lis_test.py` to run with
11+
[pytest](https://docs.pytest.org), including all the
12+
[`lis_tests` suite](https://github.com/norvig/pytudes/blob/60168bce8cdfacf57c92a5b2979f0b2e95367753/py/lispytest.py#L5)
13+
from `original/lispytest.py`,
14+
and additional separate tests for each expression and special form handled by `evaluate`.
15+
16+
17+
## Provenance, Copyright and License
18+
19+
`lis.py` is
20+
[published](https://github.com/norvig/pytudes/blob/c33cd6835a506a57d9fe73e3a8317d49babb13e8/py/lis.py)
21+
in the [norvig/pytudes](https://github.com/norvig/pytudes) repository on Github.
22+
The copyright holder is Peter Norvig and the code is licensed under the
23+
[MIT license](https://github.com/norvig/pytudes/blob/60168bce8cdfacf57c92a5b2979f0b2e95367753/LICENSE).
24+
25+
26+
## Changes to Norvig's code
27+
28+
I made small changes to the programs in `original/`:
29+
30+
* In `lis.py`:
31+
* The `Procedure` class accepts a list of expressions as the `body`, and `__call__` evaluates all those expressions in order, returning the value of the last. This is consistent with Scheme's `lambda` syntax and provided a useful example for pattern matching.
32+
* 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.
33+
34+
* In `lispy.py` I made [changes and a pull request](https://github.com/norvig/pytudes/pull/106) to make it run on Python 3.
35+
36+
_Luciano Ramalho<br/>June 29, 2021_

02-array-seq/lispy/original/lis.py

Lines changed: 135 additions & 0 deletions

0 commit comments

Comments
 (0)