Skip to content
 
 

Repository files navigation

SICP JavaScript Edition

This repository contains processing scripts and sources for the textbook SICP JS: Structure and Interpretation of Computer Programs, JavaScript Edition (SICP JS). See Preface for background.

Available versions:

Details how to generate these versions are in the repo wiki.

Platform requirement: Generating the JSON edition and extracting the programs (yarn json, yarn programs) works on any platform with Node.js. Generating the PDF edition and running the full build require Unix/macOS; Windows users can use WSL to run the shell scripts involved.

Check out our Resources for Learners, Educators and Researchers, and read more About the SICP JS Project in Interactive SICP JS.

Testing the SICPy (Python) edition

The SICPy example programs can be tested automatically against their expected outputs. First, generate the programs from the XML sources:

SICP_EDITION=py npx tsx ./javascript/index.js programs_py

Then run the tests:

yarn test:py

# Or scope to one chapter/section by passing a folder, same as `yarn test`:
yarn test:py -- programs_py/chapter1
yarn test:py -- programs_py/chapter1/section1/subsection4

By default the programs are run through py-slang, the Source Academy Python interpreter, which is installed as the @sourceacademy/py-slang dependency (run yarn install first). To test against a local py-slang build instead, set the PY_SLANG environment variable to its dist/index.cjs (e.g. PY_SLANG=../py-slang/dist/index.cjs).

To run against CPython instead (useful for comparison or as a ground truth — this is what scripts/run_py.py does, and what test.js shells out to when PY_SLANG=0):

yarn test:py:cpython
# scoped to a folder, same as above:
yarn test:py:cpython -- programs_py/chapter1

The CPython path needs the sicp runtime (published as sourceacademy-sicp, maintained in the py-slang repo under python/) importable from wherever python3 runs. scripts/run_py.py looks for it in this order:

  1. An installed copy — pip install sourceacademy-sicp.
  2. A sibling py-slang checkout — if this repo and py-slang sit next to each other on disk (e.g. both under the same parent directory), pip install -e ../py-slang/python (or nothing at all — run_py.py also falls back to importing straight out of that checkout without an install).

If neither is available, run_py.py exits with an error naming both options rather than failing with a raw ModuleNotFoundError.

Chapters 1–3 currently pass in full against CPython. Chapter 4 (the meta-circular evaluator) has a number of known, pre-existing failures unrelated to the sicp runtime itself — mostly program fragments that reference names like parse that only exist in the Source/JS edition, or that are intentionally incomplete snippets extracted from the book.

The JavaScript edition tests are unchanged and continue to run through js-slang:

yarn test

Licenses

CC BY-SA 4.0

The print version of SICP JS and the ebook version will be published in 2022 by The MIT Press under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA).

CC BY-SA 4.0

The text of SICP JS is derived from the book Structure and Interpretation of Computer Programs, Second Edition, 1996, (SICP) by Harold Abelson and Gerald Jay Sussman, and is licensed by these original authors and by the adapters Martin Henz and Tobias Wrigstad under a Creative Commons Attribution-ShareAlike 4.0 International License (CC BY-SA). A comparison edition indicates the changes that were made to SICP for the JavaScript edition. Interactive SICP JS is licensed by Martin Henz, Tobias Wrigstad, and Samuel Fang under CC BY-SA. The figures in all versions are derived from figures created by Andres Raba in 2015, and are licensed by Martin Henz and Tobias Wrigstad under CC BY-SA.

GPL 3

The JavaScript programs in SICP JS are derived from the Scheme programs in SICP and are licensed by Martin Henz and Tobias Wrigstad under the GNU General Public License v3.0.

License All JavaScript and TypeScript programs that generate the SICP (JS) versions are licensed by the contributors under the Apache License Version 2.

About

XML sources of SICP and SICP JS, and support for generating Interactive SICP JS, PDF, e-book and comparison editions

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages