A tiny (< 400 lines) Scheme written in Python to prepare for this class.
Currently, this Scheme implements everything needed to follow along in SICP up to page 54.
pip install -r requirements.txt
nosetests
Use rlwrap
if you want history and that sort of thing:
$ rlwrap ./smallscheme/scheme.py
scheme> (define (fact n) (if (< n 2) n (* n (fact (- n 1)))))
scheme> (fact 50)
30414093201713378043612608166064768844377641568960512000000000000
scheme> ^D
$
See smallscheme/test_scheme.py
for many more examples.
Example:
$ cat test.scm
(define (fact n)
(if (< n 2)
n
(* n (fact (- n 1)))))
(define f10 (fact 10))
(display f10)
$ ./smallscheme/scheme.py test.scm
3628800
$
- Lexing and parsing of atoms and s-expressions
- Read-Eval-Print
- Special forms
quote if cond define or and lambda
- Functions
+ - / * = < > not car cdr cons remainder random
- Local (block or function level defines)
- Program file evaluation (e.g.,
scheme.py myprog.scm
)
runtime
andnewline
functions- Python interop?
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.