10 ms·
SICP in JavaScript
- lispisok 3y agoWhy does everything have to be Javascriptified? Scheme is a big part of the SICP experience and trying to do it in another language you are losing a lot. Do people learn Javascript when starting their web development career then refuse to learn anything else? Getting stuck with JS in the browser is an artifact of history and given how bad the language is we should avoid spreading it yet the opposite is happening. Funny for an industry that's allegedly about doing things as smart as possible the lowest common denominator dominates.
- fuzztester 3y ago>Funny for an industry that's allegedly about doing things as smart as possible the lowest common denominator dominates. Yes. The key word here is allegedly. It's like how people rue the fact (a meme by now) that the (self-described) allegedly smartest minds in the world are desperately busy trying to, guess what, make people click more on ads(!), while largely ignoring ethics like giving people a choice about it, via opt-in rather than opt-out, confusing legalese in Privacy Policies and Terms and Conditions, fine print, etc.
- shaunxcode 3y agoThe only way this would work: chapter 0 writing a scheme in js. And the the rest of the chapters are just the standard SICP.
- retrocryptid 3y agoI believe you have misinterpreted the phrase "functional programming"
- paradite 3y agoI took this course as "CS101" back in 2013 in NUS. I've also been coding in JS for the past 10 years. Pretty happy with the content and the way it was taught.
- neilv 3y agoIf you want to work through SICP in Scheme, but don't have an easy way to run MIT Scheme, we made a compatibility thing, so you could do SICP using Racket (with your choice of editor/IDE, including DrRacket): https://docs.racket-lang.org/sicp-manual/ https://docs.racket-lang.org/sicp-manual/
- beeburrt 3y agoThat's awesome! I'd rather use DrRacket than this Docker image I was using https://hub.docker.com/r/stklos/stklos https://hub.docker.com/r/stklos/stklos
- deleted 3y ago[deleted]
- delta_p_delta_x 3y agoHeh, I took this class back in August 2018 where it originated, at the National University of Singapore (NUS), CS1101S[1] taught by Dr. Martin Henz. I was someone who thought he knew all about computers because I could program a tiny bit of C++ and Java, and thought this class would be a piece of cake. I couldn't have been more mistaken. The class kicked my arse so badly. I remember my score for the midterm: 34/75. I ended up getting a B– for it. I'll be honest, I hated it at first. Where were the loops, where were the arrays? Why was everything involving recursion? Why did some recursive code give rise to iterative algorithms, and others, recursive ones (the difference is tail-call optimisation to give constant stack space versus some growing stack space)? Why were lists this weird nested square bracket syntax??? The irony is that in my fifth year last year, I ended up becoming a teaching assistant for the very same module itself, because I realised how useful the module would be. There was truly a little bit of everything: from algorithmic complexity, to data structures, to even a bit of compilers and garbage collection, with the environment model of execution, meta-circular evaluator at the end of the textbook, respectively. I had to prove to the lecturer that despite my rather lousy grade in the module itself, my experience in everything else counted as something. A compilers class that was conducted entirely in OCaml was a great refresher on functional programming techniques, as was my internships where I learnt C#'s LINQ. I read the textbook end-to-end while preparing to teach the class—something I ought to have done as a student in the first place. My opinion of the class has changed drastically: it's one of the best introductory CS modules there is, and the fact that NUS chose to use SICP as a textbook is one reason why its CS department has skyrocketed. I have no comment about emulating Scheme with JS. I neither like nor use either language. [1]: https://nusmods.com/courses/CS1101S/programming-methodology https://nusmods.com/courses/CS1101S/programming-methodology
- tomcam 3y agoGreat how you not only understood where you messed up, but that you used it to level up, master the material, and help others to master the material.
- andai 3y agoOn my phone I just get a drawing of an alien spaceship? I tried loading it through an archive (and I do get the front page of a web book) but none of the links work there.
- mi_lk 3y agoit's supposed to redirect to https://sourceacademy.org/sicpjs/index https://sourceacademy.org/sicpjs/index
- andai 3y agoThat's the page I'm on: https://files.catbox.moe/kyql13.png https://files.catbox.moe/kyql13.png
- bryanrasmussen 3y agoseems to be some sort of loader, I got that but then it turned to the SICP in JavaScript cover - I did scroll so maybe it was the onScroll event.
- rmbyrro 3y agoI might be wrong, but I feel like writing SCIP on JS is like "Sustainable Energy using Oil." Not quite the right analogy... JS isn't as bad as Oil. But you get the idea... Kinda... don't make sense?
- fuzztester 3y ago>writing SCIP ... Then you should probably SCIP SCIP.
- Zambyte 3y agoDid you mean to say "SCIP SICP"? :-D
- fuzztester 3y agoNo. I say what I mean, and I mean what I say, like that quote by (maybe) the Mad Hatter in Alice in Wonderland :) To be more precise, as Thomson and Thompson (of Tintin comics) would say, I meant it as a double irony on the GP's misspelling or typo.
- fuzztester 3y agoDouble irony may be the wrong term, but I'm tired, and SICP(SICP) ;-) Only the math and Lisp / Scheme cognoscenti will get that one.
- fuzztester 3y ago>Did you mean You sound like Google.
- fuzztester 3y ago>You sound like Google. not just by the literal text "Did you mean" that you used, but also due to being like Google in telling us what and how to think and read, or in (mis)interpreting the meaning of what we type. You have a bright future.
- rambojohnson 3y agowhy
- decafbad 3y agoI thought my hatred of Javascript was at its peak.
- LiamPowell 3y agoIt seems like they have attempted to write scheme using JavaScript syntax to avoid having to make any significant changes to the non-code sections of the book. Here is an excerpt, it's not good: function deriv(exp, variable) { return is_number(exp) ? 0 : is_variable(exp) ? is_same_variable(exp, variable) ? 1 : 0 : is_sum(exp) ? make_sum(deriv(addend(exp), variable), deriv(augend(exp), variable)) : is_product(exp) ? make_sum(make_product(multiplier(exp), deriv(multiplicand(exp), variable)), make_product(deriv(multiplier(exp), variable), multiplicand(exp))) : error(exp, "unknown expression type -- deriv"); } Here is the original code: (define (deriv exp var) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) (else (error "unknown expression type -- DERIV" exp))))
- Animats 3y agoUh oh. That's like the original Numerical Recipes in C. All the arrays had their first value as 1, instead of 0. It was a conversion from FORTRAN, where arrays really did start at 1. The Numerical Recipes authors provided an array allocator which generated an address offset before the beginning of the array to make that work. It was awful. I rewrote the algorithms I needed with sane layout. The whole point of SCIP was mathematical beauty. Losing that in translation is not good.
- blagie 3y agoNo. If you think that's the whole point, you missed the point. Mathematical beauty was one of the ways to make the point, but far from the most important. As a footnote, one of the changes which happened since publication is the victory of functional. Note that both JavaScript and Python now embody many of the principles, design patterns, and best practices from SICP. As a second footnote, you're right: SCIP reads better than SICP. "Skippity do da..." (and if you want a third footnote, I know in the original it's zippity, but that's how kids in MY elementary school sang it, so to me, it will always be skippity"
- eelhazred 3y agoThere is also the interactive version of SICP[0]. [0]: http://xuanji.appspot.com/isicp/ http://xuanji.appspot.com/isicp/
- chris_wot 3y agoWasn’t JavaScript influenced by Modula-3?
- marcus0x62 3y agoAnd Scheme, but the code in this book makes clear the limits of that influence (or, perhaps, proves the idea of “the medium is the message” in the context of language design.)
- graypegg 3y agoIf you're using Safari, ironically there's a JS syntax error preventing the site from redirecting from a picture of a spaceship to the actual book. https://sourceacademy.org/sicpjs/index https://sourceacademy.org/sicpjs/index is the URL you get redirected to in other browsers. (It still doesn't work in safari.)
- lolinder 3y agoI started this book with coworkers and it fell really flat. I haven't read the original, but knowing Scheme I could see why the book would be structured the way it is. In JavaScript, though, it really just doesn't work. The code is horribly non-idiomatic for JS, and because JS isn't actually Scheme the order of the concepts introduced doesn't make sense. When it does talk about JavaScript, it's condescending towards it in ways that were off-putting to my coworkers (we're a TS shop), which is weird given that it's a book in JS. Someday I'm going to get around to reading the original, but I can't recommend this one.
- Tade0 3y agoThanks for the heads-up - I'm not going to bother with this piece then. Anyone with strong opinions about mainstream programming languages is automatically suspicious to me. I mean, I get it - plenty more elegant and better thought-out languages than JavaScript, with their practitioners pounding the floor, saying "it should have been me - not him!". But, ultimately, who can't write good code just because they're not using their favourite language?
- Sterm 3y agoIndeed which is why I write everything in machine code. What sort of elitist could possibly think this is a bad idea?
- jedberg 3y agoWhat I loved most about my class based on SICP was that I learned a whole new way to reason about code, and that came from using Scheme. They changed the intro class at Berkeley to use Python a while back, when the folks who knew lisp/scheme retired, and I think it made the class much worse. This is really the death knell of SICP isn't it?
- mathisfun123 3y agoYou know how people love to repeat that old saw about how computer science is no more about computers than astronomy is about telescopes (or whatever it is)? Well ironically (because it's the same exact people but this time on the other side of the misunderstanding) SICP is no more about scheme/lisp than computer science is about computers.
- jedberg 3y agoSICP is not about scheme or lisp, but its concepts are best understood in scheme in lisp. Just like the best way to understand what Saturn looks like is to look at it though a telescope. Sure you can use a spectrum scan or the output of a radio telescope, but it's really not the same as looking at in a telescope. Same thing here -- SICP just isn't the same if it's not in scheme or lisp.
- mathisfun123 3y ago> Just like the best way to understand what Saturn looks like is to look at it though a telescope. So then astronomy is about telescopes...? I'm happy to accept SICP is intimately related to lisp (which means it is less general than people claim) but just as long as we're consistent.
- deleted 3y ago[deleted]
- jedberg 3y ago> So then astronomy is about telescopes...? No? I never said that. SICP teaches concepts, those concepts are better understood with lisp. Astronomy teaches concepts, those concepts are better understood with telescopes. In neither case is the subject about the tool, it's just better understood with the tool.
- anon115 3y agooverrated asf in my opinion
- dang 3y agoRelated: SICP – JavaScript Version (2022) [pdf] - https://news.ycombinator.com/item?id=30033052 https://news.ycombinator.com/item?id=30033052 - Jan 2022 (2 comments) SICP: JavaScript Edition available for pre-order - https://news.ycombinator.com/item?id=30016323 https://news.ycombinator.com/item?id=30016323 - Jan 2022 (117 comments) SICP – Upcoming JavaScript Edition - https://news.ycombinator.com/item?id=27737942 https://news.ycombinator.com/item?id=27737942 - July 2021 (2 comments) Structure and Interpretation of Computer Programs – JavaScript Adaptation - https://news.ycombinator.com/item?id=21822903 https://news.ycombinator.com/item?id=21822903 - Dec 2019 (180 comments) SICP JavaScript Going Public - https://news.ycombinator.com/item?id=21779397 https://news.ycombinator.com/item?id=21779397 - Dec 2019 (1 comment) SICP translated to JavaScript - https://news.ycombinator.com/item?id=6385617 https://news.ycombinator.com/item?id=6385617 - Sept 2013 (107 comments)
- baz00 3y agoAt no point in my entire existence would I subject myself to JavaScript voluntarily ever again. I would write my own damn scheme environment and use that instead of this.
- baq 3y agoTypescript is very nice. Too bad the JavaScript underneath is so… unprofessional.
- jll29 3y agoI think SICP and Scheme go together like horse and carriage, and neither Python, JavaScript or other "real world" languages should taint the insight gained from that wonderful pairing. Because Scheme - being a LISP - has the same syntax for code and data, metalinguistic abstraction is facilitated. Nobody should have to read through boilerplate code to dig up the core message of SICP. I took the Algorithmics I course based on SICP/Scheme in 1993 at the University of Erlangen, and although I never used Scheme or CommonLISP in production, it made me a better programmer regardless in what language. Thanks to Abelson and Sussman!
- zelphirkalt 3y agoIn most implementations neither Python nor JS (except perhaps partially in Safari) is up to the task of even running the code of SICP properly, due to not having things like TCO. So the code for versions of the book written using those languages would need to be restructured, losing a big chunk of elegance and possibly destroying the actual lessons about how to express oneself as a computer programmer.
- hinkley 3y agoI think SICP would be just peachy in Elixir, but I’m coming around to the notion that keeping functional programming for functional programmers is a form of professional neglect. Functional core, imperative wrapper is one of the few sane ways to build a large (Conway’s Law afflicted) system, and too many of my peers never studies SICP in school. They don’t even know the damage they do, and as we’ve learned in many, many other circles, vilifying people does not get them to change. It’s a tool of last resort, and most often used to publicly label someone for ostracism, not help. So excuse me, but y’all are crazy. We need SICP for JavaScript developers more than we need SICP for every functional language in the world, combined. And JavaScript is only one corner of the programming world. Write functional code in a language that does not force you to write functional code. Take the training wheels off. Live in the real world.
- Sterm 3y agoScheme is not a functional programming language. The last 2/3rds of sicp are possible only because you can mutate state.
- lispm 3y agoThe early sad parts of "SICP in JavaScript" are especially section 2.2.1 Representing Sequences and chapter 2.3 Symbolic Data: "All the compound data objects we have used so far were constructed ultimately from numbers. In this section we extend the representational capability of our language by introducing the ability to work with strings of characters as data." In SICP there were Lisp's symbolic expressions (s-expressions). They were removed without even mentioning them...
- IAmPaigeAT 3y agoI don’t know if anyone has bothered to point this out but you could keep your schemey SICP and go clojurescript if you wanna run on JavaScript but then again you still have to contend with cycles and reverse polish