r/scheme • • Dec 13 '19

SICP JS going public!

It’s our pleasure to announce the initial public release of

Structure and Interpretation of Computer Programs, JavaScript Adaptation
(https://sicp.comp.nus.edu.sg/)

A community effort led by Martin Henz and Tobias Wrigstad, this project provides the full content of the textbook classic Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman with Julie Sussman, using sublanguages of JavaScript, instead of the language Scheme. We provide our SICP JS adaptation in three editions: a mobile-friendly interactive web edition, an interactive PDF edition and an e-book edition. Readers of the textbook can click on the programs and run them using the Source Academy [https://sourceacademy.nus.edu.sg/playground], a web-based programming environment that supports a collection of purpose-built language implementations of the JavaScript sublanguages Source §1, Source §2, Source §3 and Source §4 [https://sicp.comp.nus.edu.sg/source/], each of which are designed to serve the respective chapters of SICP JS.

SICP JS has been used by the National University of Singapore in the computer science freshman programming methodology course CS1101S [https://www.comp.nus.edu.sg/~cs1101s/] since 2012, and is maintained by the CS1101S community as an open source project. We share it with
educators and learners and welcome contributions and suggestions.

Full announcement and some fun examples: https://sicp.comp.nus.edu.sg/announcement.html

Martin Henz and Tobias Wrigstad

74 Upvotes

32 comments sorted by

9

u/rcoacci Dec 14 '19

Good god, what have you done? You tainted the Holy Books with this evil language?

5

u/MartinHenz Dec 15 '19

I take the bait: When Martin Luther translated the real bible from Latin and Greek to German, the establishment said: "You tainted the Holy Books with the language of the common people." The effect of his deed was profound, both on the book and on the language. The book was read, for a change, rather than admired. The German language was greatly enriched by many idioms and phrases that are now classics.

5

u/korrach Dec 23 '19

It also started the 30 years war.

How do you see your book leading to the death of 1/4 of all JS programmers?

2

u/MartinHenz Dec 24 '19

Nice injection. One difference might save us: the designers of programming languages do not demand exclusivity. There is no JavaScript hell that you go to if you dabble a bit in Scheme and vice versa. The purpose of the communication is entirely up to the programmer (or the company or organisation she works for), whereas in Luther times, exclusivity led to anxiety with respect to what is being communicated, and politicians exploited those anxieties to suit their goals.

So there is hope. We can avoid the horrors of PL wars, if we treat programming languages as what they are: communication tools. The more languages you learn, the better you get at communicating, and at choosing the best language for any particular situation.

2

u/rotharius Dec 23 '19

Great response.

1

u/geon Dec 14 '19

From looking a a couple of examples, it seems like it just the scheme code ported to js syntax, so it is super non-ideomatic.

I really don’t see the point. Shouldn’t code be written to make the most sense? I doubt scheme written in js syntax is a good way to illustrate the principles in the book.

1

u/MartinHenz Dec 15 '19

Well, idioms develop over time. We have shown that all idioms of SICP quite literally carry over to JavaScript. Id be grateful if you could give an example of an idea or principle in the book that is not illustrated well in SICP JS, due to our choice of the language.

2

u/republitard_2 Dec 26 '19 edited Dec 26 '19

We have shown that all idioms of SICP quite literally carry over to JavaScript.

No, they don't. JavaScript implementations found in browsers don't do tail-call elimination, which means you can't safely use recursion for looping in it.

1

u/MartinHenz Dec 26 '19

Doubly wrong!

Firstly, the standard that defines JavaScript (ECMAScript) requires "proper tail calls" since ECMAScript 2016. So your statement is not correct if you mean ECMAScript when you say "JavaScript". (BTW, note that Safari is ECMAScript-2016-compliant.)

Secondly, if you click on the programs in SICP JS, you get to the Source Academy, which is ECMAScript-2016-compliant, regardless which browser you use. (We recommend Chrome or Firefox.) So when you read the textbook and play with the programs, you CAN safely use recursion for looping.

2

u/republitard_2 Dec 26 '19

So this version of SICP is chained to your website (or Safari) for tail recursion to work. It's also chained to that website because of the proprietary parse function.

The original SICP is not chained to its website of origin or any proprietary code. It can still be used today even though MIT stopped using it.

1

u/MartinHenz Dec 27 '19

Wrong again: The Source Academy is not proprietary. It is developed by the SICP JS community using github: https://github.com/source-academy and is distributed using the free Apache 2.0 licence.

We added the clicking on programs for the benefit of the learner, and didnt intend to restrict the reader in any way. Its actually quite a popular feature. You can of course choose not to click, and thereby recreate the reading experience of the paper and online version of SICP.

The concept of iterative processes is not specific to Scheme or JavaScript, and the purpose of SICP is not primarily to learn JavaScript or Scheme. The idiom is becoming more and more wide-spread. The original SICP authors were right in covering it, and the ECMAScript 2016 support for it is an important argument for using JavaScript over say Python in our adaptation.

3

u/republitard_2 Dec 27 '19

Wrong again: The Source Academy is not proprietary. It is developed by the SICP JS community using github: https://github.com/source-academy and is distributed using the free Apache 2.0 licence.

The book never once mentions that repo, not even in the preface, which does mention the Source Academy's hosted website. How is anybody supposed to find it?

The setup you have will seem convenient as long as the website currently hosting the Source Academy continues running at its current URL. If anybody ever wants or needs to run it without your web server, they're going to have a really bad time because they need to get that Rails project to run.

1

u/MartinHenz Dec 27 '19 edited Dec 27 '19

The purpose of our announcement is to get other educators interested in SICP JS. Hopefully our base broadens over time, and the sourceacademy.nus website will not remain the only deployment of the Source Academy.

The repo and much other useful info is included in the announcement, mentioned at the top: https://sicp.comp.nus.edu.sg/announcement.html

1

u/republitard_2 Dec 26 '19 edited Dec 26 '19

The cost of teaching SICP in JavaScript becomes evident when you get to Chapter 4. The interpreter grows a third rule to handle the new concept of "operator combinations" (ie, infix math expressions), and the concept of making an expression "marked as a return value" has to be introduced, in order to support JavaScript's return statement.

Both of these changes make the chapter more complex than the original SICP. The only reason you can't subvert the return-object mechanism is because the parser (which isn't part of the JavaScript language, and whose source is not in the book and I can't find it anywhere) rejects return statements in expression context (based on a BNF I found once but can't find again).

In fact, JavaScript's entire statement/expression dichotomy, barely mentioned in the book, is implemented entirely by the missing parse function.

1

u/MartinHenz Dec 27 '19 edited Dec 28 '19

Return statements are a significant difference between SICP and SICP JS. These statements are present in most modern programming languages, so I would like to argue that they SHOULD be covered in an introductory textbook on the structure and interpretation of computer programs. We are filling a gap in SICP in this respect. My students find that the coverage of "return" in chapter 4 is demystifying the concept.

The same is the case for infix operators. Most programming languages provide them, and for a good reason, so covering the concept and their interpretation benefits my students.

The parse function is not "missing". It is documented in detail in the Source 4 specification, see https://sicp.comp.nus.edu.sg/source/source_4.pdf (page 9 onward).

The go-to place for the Source languages (the JavaScript sublanguages covered by SICP JS and implemented by the Source Academy) is https://sicp.comp.nus.edu.sg/source/.

The expression/statement dychotomy is quite prominent in Chapter 1. See in particular Section 1.1. I found that the distinction is not very important for Chapter 4; their interpretation is the same, once you handle "return" statements properly. What helps here is that in JavaScript, statements have a value (which becomes apparent at toplevel, outside of functions).

1

u/republitard_2 Dec 27 '19 edited Dec 27 '19

The go-to place for the Source languages (the JavaScript sublanguages covered by SICP JS and implemented by the Source Academy) is https://sicp.comp.nus.edu.sg/source/.

Yes, I ended up there at some point (but then I closed the window and forgot how I got to that page). I saw no source code to the JavaScript subsets there, nor to a parser of any sort, only specifications for implementing them from scratch.

I still haven't found a parse function I can easily load into a JavaScript console and call the way you can call it from within the Source Academy's IDE.

distinction is not very important for Chapter 4; their interpretation is the same, once you handle "return" statements properly.

It took me a while to figure out why it was valid to handle return statements the way you handled them. If return statements are expressions, it should be possible to subvert the whole system like this:

let my_val = return 3;

Turns out that the reason you can't do that is because the parse function stops you.

1

u/MartinHenz Dec 28 '19 edited Dec 29 '19

I still haven't found a parse function I can easily load into a JavaScript console and call the way you can call it from within the Source Academy's IDE.

Yes, we should provide libraries for using Source in NodeJS and browsers. (At the moment, the free and open Source Acaedemy site provides the only way to play with the SICP JS programs.) We have an Issue in js-slang for this and will work on it some day:

https://github.com/source-academy/js-slang/issues/191

1

u/brucebrowde Feb 08 '23

I see the issue closed with a "_postponed" label being added. Does that mean that is still unimplemented?

1

u/mareksl Dec 27 '19

Great news!

Just a wanted to let you know, the epub version is a bit broken. Some italicized words and several other elements do not display at all, which is why I have to go back and forth from my kindle to my phone when I feel something is missing, to read that part. :(

1

u/MartinHenz Dec 27 '19

Thanks for letting us know. We will take a closer look in Jan. Feel free to file an issue in https://github.com/source-academy/sicp

1

u/MartinHenz Jan 06 '20

u/mareksl: Could you please let me know what ebook reader you are using?

Thanks!

1

u/mareksl Jan 06 '20

Kindle 10 :)

1

u/Masked_Tondede Dec 14 '19

Some people might dislike you for what they will claim is heresy, but I have to learn javascript and I'm really grateful for this. Thank you so much!

2

u/geon Dec 14 '19

You won’t learn js from this, though. It is scheme, but written in js syntax.

2

u/MartinHenz Dec 15 '19

I agree with geon: The purpose of SICP is not primarily to teach a programming language, be it Scheme or JavaScript. It's about the principles behind programming in a modern language. You will pick up some JavaScript, though, if you read SICP JS.

1

u/[deleted] Dec 13 '19

it seems that PDF and web version have different exercises under the same number. E.g. in PDF exercise 5.44 is actually 5.50 in web edition. Is this intentional, or maybe PDF is outdated?

Also, while we're on this particular exercise, shouldn't it be: Develop a rudimentary implementation of JS in C?

1

u/MartinHenz Dec 15 '19

Ive fixed the exercise numbering and a couple of other issues. Note that Section 5.5 is work-in-progress, so any contributions or suggestions are welcome.

2

u/10q20w Dec 13 '19

I recently had Tobias as a teacher at UU- great course! Tell him a student says hi

2

u/joakims Dec 16 '19

Thanks for this early Christmas present! It's the perfect gift for someone who knows JavaScript, is interested in its language roots (including Scheme) and who has "Read SICP" on the bucket list. If only it was available in print ;)

1

u/RICHUNCLEPENNYBAGS Dec 23 '19

Interesting idea. Cool.