norvig / pytudes

Python programs, usually short, of considerable difficulty, to perfect particular skills.
MIT License
23.11k stars 2.43k forks source link

Update lispytest.py #113

Closed gabrielsroka closed 2 years ago

gabrielsroka commented 2 years ago

add tests for +-*/ ref https://web.mit.edu/scheme_v9.2/doc/mit-scheme-ref/Numerical-operations.html#Numerical-operations

norvig commented 2 years ago

Thanks for this work. You are absolutely correct that modern Schemes have these multi-argument capabilities, and your implementation and tests are just right.

However, I decided that I wanted to keep things as simple as possible, and I implemented just the "essential procedures" from the R^3RS specification; these extensions are considered inessential in that version of Scheme. So I think I will keep it as simple as possible.

gabrielsroka commented 2 years ago

EDIT: i see you mention this here

Lispy is not very complete compared to the Scheme standard

ok. according to r3rs https://people.csail.mit.edu/jaffer/r3rs_6.html#SEC28 set! is essential. you mention it in several places on http://norvig.com/lispy.html and include an implementation:

    elif op == 'set!':           # assignment
        (symbol, exp) = args
        env.find(symbol)[symbol] = eval(exp, env)

but it's missing from lis.py (so are several other pieces of "essential syntax", eg, cond, let, etc)

http://norvig.com/lispy.html has links to r5rs, but above, you mentioned r3rs. is it both a subset and a superset then? :)

thanks!

norvig commented 2 years ago

Excellent questions, @gabrielsroka !

Very well, then I contradict myself, I am large, I contain multitudes.

I think you're convincing me that, sometime in the new year, I need to sit down and bring some consistency to this (and update to Python 3, and add type hints). Thank you for bringing this up, and happy new year!

gabrielsroka commented 2 years ago

Happy new year to you, too!

I think I just figured out part of the problem: https://github.com/norvig/pytudes/blob/main/py/lis.py is different than: http://norvig.com/lis.py

eg, one has set! and the other one doesn't.

there are also differences in lispy.py and and lispytest.py

I smell a merge... :)