SICP is hard to work through even if you're just reading but wow, the exercises are on another level! I wonder how it compares to, say, a physics or biology textbook
I don't remember exercises, but I expect they are as long as SICP, while maybe there is more emphasis on learning theory more than practicing coding
I barely survived Calc 3 and have never taken an engineering course. I was fine.
Did the author overthink it or are the simple solutions not correct?
If you aren't comfortable with recursion, I can see it taking a while.
It's basically a walk down a binary tree with some extra logic. You have to write two recursive functions, one each for (b) and (c) but they have basically the same structure with different return values. The function for (b) can be used for (c) (not the most efficient, but it does work). (d) requires minor modifications to the functions created in (a)-(c) so you can start with copies of the originals and make the change, I think it's a one symbol change in each function, or maybe two.
> Exercise 2.92. By imposing an ordering on variables, extend the polynomial package so that addition and multiplication of polynomials works for polynomials in different variables. (This is not easy!)
2.29 is what I described in my other comment, it's a pair of functions walking a binary tree with conditional logic based on if it's an interior or exterior node, returning either a sum or a true/false value. Which is not hard at all and their time was only 83 minutes. Versus their claimed time of 2400 minutes for 2.92.
The code is convoluted, in my opinion, because it tries to hue too closely to the Scheme code in the original giving some unnatural looking JS code as a result. For example:
function member(item, x) {
return is_null(x)
? null
: item === head(x)
? x
: member(item, tail(x));
}
There are examples which have even more but that was the first one I came across clicking the TOC randomly. In Scheme it would be expressed something like this: (define (member? item set)
(cond ((null? set) #f)
((equal? item (car set)) #t)
(else (member item (cdr set)))))
While the parens cause some brains to segfault, the structure of this (how each condition ties to each result) is clearer than that JS mess. (define (member? item set)
(cond ((null? set) #f)
((equal? item (car set)) #t)
(else (member? item (cdr set)))))
For bonus points, line up the key variable in the clauses, and it's easier to see visually that the `cond` is about that one variable: (define (member? item set)
(cond ((null? set) #f)
((equal? (car set) item) #t)
(else (member? item (cdr set)))))
Which accidentally also lines up with one of the procedure's arguments, though I didn't intend that one, but you could double down on that: (define (member? item set)
(cond ((null? set) #f)
((equal? item (car set)) #t)
(else (member? item (cdr set)))))
This isn't some deep thing; just a little example of how sometimes whitespace, other than just indenting at the beginning of the line, helps to exposure some of the structure visually.When I say Scheme is expression based, I am alluding to the fact that constructs such as `if`, `cond`, `case` etc. are all expressions. Scheme also has several binding constructs (let, letrec, etc) that allows in an expression context to bind the result of a computation in a subexpression. These are all expressions.
The expression version of `if` is in JavaScript called ternary if. A direct translation from Scheme to JavaScript therefore uses ternary if.
But why make a direct translation?
Well, later in the book one writes an interpreter for Scheme. This interpreter shows how the expression based language constructs are implemented. It is therefore necessary that the reader is very familiar with these constructs.
function member(item, x) {
return /* if */ is_null(x)
? /* then */ null
: /* elif */ item === head(x)
? /* then */ x
: /* else */ member(item, tail(x));
}
And in fact I _think_ some engines do have TCO (bun? javascriptcore?), but I could be wrong
So TCO is part of the language standard but not universally implemented. You are correct about the ones that support it.
Maybe reading this will help:
https://cseducators.stackexchange.com/questions/7478/which-b...
If you mean 'SICP but in a language that's more popular nowadays', there's SICP in JavaScript.
If you mean a newer book which teaches CS in Scheme, I don't really know. HtDP uses Racket, which is a spin-off of Scheme, but outside of that I'm not really aware of any books which could be called 'modern'. There's Concrete Abstractions, which I would call 'SICP-lite' as it's a fair bit lighter on the maths, so that would be my first go-to if the maths are a bit intimidating.
Peter Van Roy, Concepts, Techniques, and Models of Computer Programming, 2004
It uses the language developed in this book (Oz).
The book constructs many of the current programming paradigms, starting from almost nothing, with an emphasis on software design.
See the paradigms poster built http://www.info.ucl.ac.be/people/PVR/paradigmsDIAGRAMeng201....
I would mention Knuth, but many problems in his books are still yealding PhDs. Way above my grade.
There is a lot of problems I would like to look at hints.
Kudos to your achievement.
SICP is a graduate level text? That was literally the first CS book I had to buy as an undergrad.
Going at it alone is a thing for people that are already alienated by waged labour or whatever, and likely not the most efficient way to learn its lessons, thought it might be the only obviously available. Personally I prefer to dip in for a short while once or thrice a year or when I have something I'd like to get better at that I know it teaches.
Still, neat presentation.
One suggestion for the already complete and detailed post: what is the personal/professional gain you get for your time investment? In this case maybe: „program design became clearer after having worked through SICO.“ or „I can discuss design more formally now“ or just „It was interesting and everyone talked about it, so I needed to know“
It would be interesting to know what parts are pure gold and worth deep study and which parts can be skimmed or consulted as a reference.
I think finding someone that guide you through the book allows to go way faster than alone.
Now, while the concepts were extremely illuminating, I think following the book but doing the exercises in haskell is also a nice path. Haskell was another lecture following the one on SICP by the same teacher, and it uses most of the same ideas, sometimes formulated a little differently, but on a more modern language.
I still remember my exam where we received ~6 pages double column of printed lisp, no comments. The code was a compiler, and we needed to change it so that it can jump back in time using call with cc. Difficult to do in 3h and on paper but very fun.
One detail intrigued me. The author has a PhD in Informatics but "had never used any programmers’ editor other than Notepad++". He credits being able to touch-type for some of his efficiency and went about learning a swathe of tools including Emacs and several diagramming languages. These diagram files and the OrgMode file are a valuable reference in themselves.
But I think this is a useful critique of SICP, for those trying to teach from it or in particular for those trying to self-study it: it wasn't really designed to be done front-to-back (contrary to the nonsensical justifications given here); it's not a realistic demand of any student, or even necessarily a particularly productive use of their time unless they intended to move into compiler development. Its problem sets occasionally give the illusion that SICP itself will teach you what you need to solve these incredibly difficult problems and perform these incredible accomplishments, which is partially what's responsible for its legendary status. Not recognizing that - and it'd be hard to blame a solo learner for that - can be incredibly discouraging when one finds that they can't do things with the tools SICP has given and blame themselves for not appreciating those tools rather than SICP for asking too much and giving too little.
Here he shows 2 reviews he gave up on, that he resorted to data because he didn't know how to put it in words.