Wednesday, September 26, 2007

Reading SICP

I’ve had a long standing goal to read SICP, but it keeps conflicting with other goals, like mastering Ruby or learning Erlang (to name a couple of geeky ones). Recently I learned of a project to ‘translate’ SICP into Erlang (and other languages).

“Great! I can use this to help with both learning Erlang and reading SICP”, I thought and went to take a look at it. It turns out they also have a Ruby translation underway, so I went to look at that first. It turns out that the first couple of examples make me think that they either don’t understand Ruby or don’t understand SICP.

Page 5 of SICP shows that you can start up a LISP or scheme interpreter and type in an expression and it will return that expression, like this:


 > 486
 486
 >
The site recommends the following Ruby puts 486, which is not quite right:

irb(main):001:0> puts 486
486
=> nil
irb(main):002:0>
You see, this prints 486, but returns nil. A much better answer looks a lot more like scheme:

irb(main):002:0> 486
=> 486
irb(main):003:0>

With a problem like this early on, I’m not sure that I trust the Erlang or other translations. I do like the idea though, so I should probably stick with my idea of combining the ideas, and just post my own translations (and let everyone else find my mistakes).

3 comments:

Anonymous said...

It looks like this will have all the challenges of translating a book, e.g. maintaining the original spirit. Not all languages (programming or spoken) have the same features. It takes a truly multi-lingual (or even multi-cultural) writer to master a translation.

That said, it's a great effort being put forth to update a great book. And it appears it's open-source by virtue of being in a wiki, so we can fix issues like "486".

Levi said...

This falls right in line with a local programming languages interest group I'm trying to gauge interest in. For the last couple of days I've been gathering my thoughts and putting them online: http://plig.jottit.com/

I'd be very interested in hearing your thoughts on this, and also possibly working through SICP with you. Let me know what you think.

Chris Rathman said...

As the one that initially set up the translations on the CTM wiki, I think what tom says is basically correct. Feel free to to fix or improve the material - that's why it was put on a wiki. From a selfish standpoint, every time someone makes a correction, I learn something in the process. Any help and insight is appreciated.

As to why I chose puts... Well, the Python, Ruby, JavaScript and Lua translations were done in a fit of a couple of days sometime soon after I did the Oz translation. Oz does not have a REPL similar to Scheme, wherein you type an expression and it echoes back instantly. And not having the patience at the time I was doing the four scripting languages, I just fed them in as whole scripts - needing some feedback along the way.

However, you're not the first to make a complaint along this line. The E folks were asking something along the lines of why I was printing the expressions in E, but not in ML. Think I polished it in the E code, but haven't been back to Ruby or Erlang since.

As to whether this indicates a lack of understanding of the material or the languages... The lesson in SICP is geared towards building up layers of abstractions. The Scheme REPL is the tool at hand, but I'd think how one goes about echoing an evaluation of an expression is incidental to the larger lesson. The expressions themselves are the lesson, not the mechanics of Scheme programming. Of course, I'd agree that it might be considered bad form from a learning perspective in that it introduces the concept of a procedure too early on. But then you'll probably find that most Ruby and Python texts would introduce puts and print very early on, much sooner than one would do in Scheme.