7 ms·
SICP translated to JavaScript
Sections of Structure and Interpretation of Computer Programs translated to JavaScript by Professor Martin Henz with executable examples.
- jfe 13y agowhy, God, why?
- hackNightly 13y agoPerhaps due to the increasing popularity of JavaScript and the decreasing accessibility or usage of Scheme.
- fsck--off 13y agoSICP uses Scheme, not Common Lisp. Edit: Here's a list of available Scheme implementations. SICP uses MIT/GNU Scheme, which uses an Emacs-like editor. http://groups.csail.mit.edu/mac/projects/scheme/ http://groups.csail.mit.edu/mac/projects/scheme/
- hackNightly 13y agoThanks, you're correct.
- lucian1900 13y agoPlenty of Scheme implementations work in JavaScript VMs.
- lambda 13y agoSICP uses Scheme, not Common Lisp. Scheme is a deliberately minimalist language, which is fairly accessible and easy to write your own implementation of. In fact, in SICP, you do that, a couple of times, writing first a Scheme interpreter, then extending it in various ways like adding logic programming capabilities, then you write a virtual machine and a compiler that compiles down to that virtual machine. JavaScript is, well, a weird and warty language. You wouldn't want to try implementing JavaScript in an introductory CS class, and it's much less amenable to language extension like the logic programming variant of Scheme you implement in SICP. But I notice that this translation of SICP into JavaScript doesn't got that far; it only goes up through Chapter 2 of SICP.
- lispm 13y ago> Scheme is a deliberately minimalist language Ever looked at R6RS?
- lambda 13y agoI'm not a big fan of R6RS, but it is still fairly minimalist. One of the good things that it did was divide the standard into a core language, and standard library built on top of the small core language. The core language eliminated many things from R5RS, but the standard library adds a lot more. The main issues I have with R6RS are the library system (which I think is too complex, and it frustratingly adds an extra level of indentation as you need to wrap everything in one big expression), and some of the libraries in the standard library, like the I/O library, the Unicode library (which standardizes on such things as char-upcase and char-downcase, which are fairly useless in a Unicode context, without adding much that's actually useful). R6RS is this kind of weird, awkward beast that's not sure what it's doing. It neither strips the language down to a minimal core, nor does it build up a comprehensive set of libraries containing all of the basics that people expect from standard libraries in a language these days.
- Tichy 13y agoJavaScript is rather minimalist as well. It has some warts, but they are easy to avoid.
- RockyMcNuts 13y agoNow if someone would only translate it to Visual Basic it would be truly accessible.
- Fixnum 13y agoActually, Scheme is more accessible than ever before. If installing MIT Scheme and Edwin/Emacs is too difficult, now there's Racket-SICP, which allows you to program with DrRacket, a beginner-friendly graphical IDE, and actually comes with implementations of some parts of SICP that MIT Scheme omitted, like the picture language and (afaik) some concurrency primitives. Is Scheme really decreasing in usage? Sure, in recent years there have been high-profile moves to Python at MIT and UCB, but I don't know of any hard stats on worldwide Scheme usage. Not that it matters.
- brudgers 13y agoDue to the increasing popularity of casual dining and the decreasing accessibility of Danish nobility, I've rewritten Hamlet to be an Appleby's assistant manager. The fifth act of SICP is meta-linguistic abstraction, and among Javascript's merits it is not. SICP is no more a book about Scheme than Moby Dick is a whale tale. I admire the effort, and understand the sentiment behind the project. I just think the authors are missing the big picture of SICP. In fairness, few of us are Ablesons or Sussmans.
- macmac 13y agoThank you for the imagery. As Dane who grew up in Elsinore, it will stay with me for quite a while I am sure.
- dragonwriter 13y ago> Due to the increasing popularity of casual dining and the decreasing accessibility of Danish nobility, I've rewritten Hamlet to be an Appleby's assistant manager. Replace "casual dining" with "megacorporations" and you get an actual movie made in 2000 [1]. And, of course, that example is not unique [2][3][4][5][6][7][8][9][10]. [1] http://www.imdb.com/title/tt0171359/ http://www.imdb.com/title/tt0171359/ [2] http://www.imdb.com/title/tt0114279/ http://www.imdb.com/title/tt0114279/ [3] http://www.imdb.com/title/tt0117509/ http://www.imdb.com/title/tt0117509/ [4] http://www.imdb.com/title/tt0184791/ http://www.imdb.com/title/tt0184791/ [5] http://www.imdb.com/title/tt0265713/ http://www.imdb.com/title/tt0265713/ [6] et cetera [7] et cetera [8] et cetera [9] ad nauseum [10] ad infinitum
- jfb 13y agoSICP isn't a book about Scheme. It's a book about writing computer programs. Scheme was used because it imposes the minimum additional cognitive load. Worrying about all the warts in, e.g. Common Lisp (to say nothing about Javascript or Scala, say) would detract from the pedagogical mission of the book.
- lispm 13y agoSICP did not use Scheme. SICP used a tiny subset of an early Scheme. You can use a subset of Common Lisp and the programs in SICP would mostly look the same when written in that CL subset. I have a surprise for you: Scheme has warts, too.
- gcr 13y ago> decreasing accessibility Scheme is super-easy to set up these days. Step 1: Download http://racket-lang.org/ http://racket-lang.org/ Step 2: Follow the quick start guide: http://docs.racket-lang.org/quick/ http://docs.racket-lang.org/quick/ Step 3: Click "Run" No "click through Visual Studio's project setup" phase, no "how do I open the text editor from IDLE" phase, no "open a command prompt" it's all right there. This makes the environment and the language perfect for beginner students.
- jimgardener 13y ago>>why, God, why? I really loved that response :)
- anaphor 13y agoMost of chapter 4 will be impossible to really translate to JS because JS has no macros (required to implement some of the special forms like delay) and isn't homoiconic.
- azakai 13y agohttp://sweetjs.org/ http://sweetjs.org/
- anaphor 13y agoOkay, that's cool, but I still think a lot of the explanations wouldn't make sense with code translated to JS, because of the lack of homoiconicity.
- Gonzih 13y agoCan it use JS for transformation logic?
- spacemanaki 13y agoIt's not about macros, it's about homoiconicity. I encourage you to read chapters 4 and 5 and think about how sweet.js would help you port those chapters to JS.
- vezzy-fnord 13y agoSome people will stop at nothing to convert the world to JavaScript and Ruby. (please don't do the latter... or is it too late?)
- davexunit 13y agoThe web developers have taken over, it seems. Edit: I say this as a web developer. I feel like it's often forgotten that Ruby and Javascript aren't the only languages worth using.
- camus 13y agoScala for the win. Most of the ruby goodness with non of the performance problems (at high scale (ie Twitter ...), because ruby is fine for most use cases ). Go is fine, but i dont like the syntax and some of the language design choices
- pjmlp 13y agoWell, I never used Ruby, besides to see what this Ruby on Rails was all about and I already knew Python since the version 1 days. For me the only place for JavaScript is on the browser. For anything else, there are endless languages to choose from.
- seiji 13y agoFor anything else, there are endless languages to choose from. The Americans have taken over and the Americans have, based on their own linguistic experience, decided most people can only handle one spoken language and one programming language. For some of us, we can handle six programming languages and be fine. For "average" people, they're lucky to get one programming language, so it was decided to fad-hype-hipster promote One Language To Rule Them All for fronted, backend, sideend, middleware, topware, bottomware, programming your embedded system, programming your car, scripting your operating system, and programming your blender. Look on github for how many people write shell scripts in ruby because they don't know how bash works. You can find the same over-syntax'd-programming-environment-as-shell-script with node too. We're the exceptions. They can't handle the truth.
- davexunit 13y agoWhat an abomination.
- indubitably 13y agoWow, stay classy.
- neilk 13y agoObvious objections - JS has no tail call elimination, no macros, and state-changing is managed with entirely different conventions in Scheme. Also the conceit of SICP (not really justified) is that they don't have to teach you syntax, because homoiconicity. Still, I think it's a worthy pursuit to try to bring the insights of this book to a wider audience. Side note: the navigation is really irritating. The back button only works sometimes, because it's replacing content without doing some kind of pushState. So you have to hunt for links. Another side note: Sean Burke and Piers Cawley have ported some of mjd's excellent book Higher-Order Perl to JavaScript. This might be even better, because both Perl and JS have C-like syntax hiding some impressive functional capabilities. I wish someone would finish that, but I guess few people even know about HOP, these days. http://interglacial.com/hoj/hoj.html http://interglacial.com/hoj/hoj.html http://www.bofh.org.uk/2010/11/18/higher-order-javascript http://www.bofh.org.uk/2010/11/18/higher-order-javascript
- deleted 13y ago[deleted]
- officialjunk 13y agotail call elimination can be implemented in javascript: http://raganwald.com/2013/03/28/trampolines-in-javascript.html http://raganwald.com/2013/03/28/trampolines-in-javascript.ht...
- jfb 13y agoTrampolines are a solution to the same problem that tail-call elimination solves; they're not transparent to the programmer.
- jessep 13y agoMacros in js: http://sweetjs.org/ http://sweetjs.org/ "Sweet.js brings the hygienic macros of languages like Scheme and Rust to JavaScript. Macros allow you to sweeten the syntax of JavaScript and craft the language you’ve always wanted."
- 13y ago
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- hepek 13y agoblasphemy!
- deleted 13y ago[deleted]
- dysoco 13y agoWhat's next? "Advanced Programming in the Unix Environment: Now with Javascript!" ? Or "Linux Device Drivers: Javascript edition" ? Can we just accept that JS is not for everything?
- jophde 13y agoI just want to meet one programmer who can work on server side code, client side code, etc who can't handle them being written in different languages. This fad just doesn't make any sense to me. Let's reinvent the wheel so we can have JSON literals instead of Ruby hashes!
- deleted 13y ago[deleted]
- erikpukinskis 13y agoI always thought this would be self-evident to people, but apparently not: The reason why I want to have Javascript on both the client and the server is so I can re-use code. My software has a fairly large chunk of code which is a gardening expert system. I'm hesitant to call it AI because it's so dumb, but it's along those lines. It knows things like "If you live in Phoenix and it's April, you should wait to plant your lettuce until September". It's useful to have it on the client, when you're in the garden and there's no connectivity, or when you tweak your settings and don't want to have to download a bunch of "conclusions" from the server. It's useful to have it on the server so that the server can send emails, pre-cache HTML for faster loading pages, etc. If my server is written in Ruby (which is is right now) then I have to re-implement that entire system twice. That's double the code. It feels gross. And I can't help but feel like most web-apps have code like this that could be shared between the client and the server.
- wpietri 13y agoYeah, I'm with you on this. Aesthetically, I'm in the "ugh, Javascript" camp. But practically, I recognize that I should just get over this. For web stuff, I fully expect that I'll be writing everything in JS in a few years.
- Gonzih 13y agoReally sad to see that such amazing book that uses such nice language is now transformed to monster with JS. Why would you do that? Painful to see all that...
- 10098 13y agoThis will only serve to perpetuate the stupid meme that "Javascript is basically Scheme with curly braces and semicolons"
- discreteevent 13y agohttp://journal.stuffwithstuff.com/2013/07/18/javascript-isnt-scheme/ http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt... (Note that the author intended this to be humourous/exaggerated - Some people took exception though.)
- mnemonicsloth 13y agohttps://news.ycombinator.com/item?id=6069159 https://news.ycombinator.com/item?id=6069159
- DanBC 13y agoCool - next they should try "How to Solve it by computer" (http://www.amazon.com/Computer-Prentice-Hall-International-Series-Science/dp/0134340019 http://www.amazon.com/Computer-Prentice-Hall-International-S...)
- agumonkey 13y agoPorting it to javascript kinda defeats the idea that principles described here transcends any current trend.
- francis- 13y agoBINGO!
- scorpion032 13y ago"An invasion of armies can be resisted; an invasion of ideas cannot be resisted" - http://en.wikiversity.org/wiki/Victor_Hugo_quote http://en.wikiversity.org/wiki/Victor_Hugo_quote This generation is going to be rewrite in Javascript/v8, everything that can be written in Javascript.
- qu4z-2 13y agoAnd a few things that can't, I suspect.
- joe5150 13y agoMeta-gripe: the navigation seems to use some kind of asynch loading without pushing to the browser history stack, and I'm finding it very difficult to move back and forth from the ToC to chapters. Maybe this can be addressed.
- mbillie1 13y agoCheck out my new library, SICPinJSnavigation.js
- deleted 13y ago[deleted]
- contingencies 13y agoWanted to care but the page wouldn't display without Javascript.
- aufreak3 13y agoBtw Prof. Martin Henz was one of the major contributors to the design of Oz.
- 011011100 13y agoIt's like you didn't even understand why it was done in scheme...
- snaky 13y agoWhy so square? Translating SICP to Forth would be at least eclectic and truly creative gesture.
- rspeer 13y agoJonesForth at least seems in the same spirit as SICP, though what it accomplishes is different. It explains and implements a Forth environment from scratch, initially in literate assembler code (yes, that exists) and then, once that's bootstrapped enough, in literate Forth that it runs using itself. http://sage.math.washington.edu/home/wstein/www/home/wbhart/jonesforth.S http://sage.math.washington.edu/home/wstein/www/home/wbhart/...
- zodiac 13y agoBackground: this is the textbook used for a class at NUS (National University of Singapore). Previous iterations of the class, CS1101S, used the original scheme version of SICP, but omitted chapters 4 and 5 in the interest of time. [1] I took the scheme version of the class and learned a ton. From what I've heard, the reasons for the switch included javascript being more practical and the previous professor deciding to take a break from teaching that class. Basically, many of the reasons overlap with that for Berkeley switching 61A from scheme to python [2]. I've also heard that the javascript version of the class is just as rigorous and challenging as the scheme version. Shameless plug: if you want an interactive version of SICP in the original scheme, check out http://xuanji.appspot.com/isicp/1-1-elements.html http://xuanji.appspot.com/isicp/1-1-elements.html [1] Which might explain why the lack of macros in javascript wasn't a concern [2] http://www.eecs.berkeley.edu/~bh/61a.html http://www.eecs.berkeley.edu/~bh/61a.html
- usmani99 13y agoNice
- usmani99 13y agoPlease Visit for gaming , software , news, webdevelopment http://usmanjameel.blogspot.com/ http://usmanjameel.blogspot.com/