by jedberg · 6y ago · 0 comments
It was truly mind blowing when they had us implement a Scheme interpreter in Scheme, and then add infix operators.
I think the original SICP was perfect for an intro course.
It was also the great leveler, because even if you entered college with programming experience, almost no one knew Scheme. So you were all on equal footing when it came to the language.
The final project was changed to a python interpreter in Scheme which I thought was fantastic.
That is fantastic! ;-)
Scheme implementations are that now, and maybe even standard Scheme is that now, but historically it has not been.
1998 was almost a quarter century after Scheme started. That year, R5RS came out, yet it defined no way to decompose a program into separately compiled files, and didn't specify what is an error (beyond saying that it's something that can happen that an implementation should diagnose) or how to recover from one. Even BASIC for 8 bit microcomputers had ON ERR GOTO.
(Good thing R5RS specified hygienic macros, because unwanted capture is a the real threat to your all-in-one-file program with no error handling.)
As far as I know it was taught in Scheme since SCIP came out in the 80s.
As a fan of Python, my reaction to seeing this course was: "oh cool, a course on interesting things in a language I'm comfortable with".
I was then somewhat discombobulated to see the Python bashing in the comments.
Scheme is a good language for SICP because it's simple. You can build a Scheme interpreter as a class project. You can analyze it formally. Etc.
Python is a good language because it's readable and writeable. But it doesn't work for SICP since it's too complex for that. Python also intentionally omits things critical to SICP (like tail recursion).
Calling this book "SICP in Python" would be like taking your favorite poem, releasing it into a different language, and finding that the translators wrote a completely different book, with a different theme, to make it rhyme and the rhythm hold. Just something different with the same name.
(It is still not the good fit for SICP, but that’s a different conversation)
def fun(listarg = [])
listlocal = []
listarg.append(3)
listlocal.append(3)
It turns out listarg is bound to a list which is not freshly instantiated each time the function is called (with no corresponding argument), unlike listlocal. The expression is evaluated at the time the function is defined, not at call time. The value is stashed somewhere and that value is used for initializing listarg by default.I learned about this from ... running pylint3 on some code which found a buggy use of such a list.
This is probably that way for performance because Python doesn't have true literals. [1] is more like (list 1) in Lisp; it's a constructor that has to be executed, producing a newly allocated object; it is not like '(1) which is just a literal object that can be embedded into the compiled program image. Python literature incorrectly refers to [] as a literal, which is bad education: a disservice to newbies who deserve to understand what is a literal. The fact that you can do "x = []" and then safely append to to it proves that it's not a literal, because literal is an abbreviation of "literal constant", which is also something newbies should be taught.
Students of CS must absolutely learn the crucial difference between variable initialization and assignment. Python conflates the two.
x = 42
def fun():
x = 43 # defines and binds local x.
This was not even fixed in Python for a long time; now you can assign to the global one with a global statement. The concept is bad here and damaging to newbie brains.After taking a course which used SICP, I was so inspired I wrote a functioning Scheme interpreter in a couple of evenings - in C, with no external libraries. It was pretty limited (no tail recursion), but could run examples from the book.
That is not going to work with python - even just parsing the program will need a whole bunch of extra knowledge.
Given:
def extendList(val, list=[]):
list.append(val)
return list
What do the following print:print(extendList(1))
print(extendList(1))
print(extendList(2))
print(extendList(3,[]))
I do not blame them. This sort of behavior is error-prone. You can make sure that you do not use such a code in production with code reviews but it would be also great to not having such things in the language.
The answer is:
[1]
[1, 1]
[1, 1, 2]
[3]
It relies on knowing something about how python applies default arguments.
I’ve only written about a hundred lines of python in my life, so possibly I just got lucky - still, I would have thought an actual Python programmer should get this?
(You’ll likely want to disable some of the more opinionated checks, but this is well documented and supported)
Python (go, rust...) aren't minimal, nor abstract enough to achieve above. For example, most of the SICP problems can be nicely solved in python, but if you are going to add evaluator, you'll need to pull parser/ast modules, which are story on it's own.
The web version appears to work though: http://sarabander.github.io/sicp/html/index.xhtml
verb [ T ]
UK
/ˌdɪs.kəmˈbɒb.jə.leɪt/ US
/ˌdɪs.kəmˈbɑː.bjə.leɪt/
informal mainly humorous
to confuse someone or make someone feel uncomfortable
When I took CS in school, these were not the central themes. On the last day of class the teacher showed us a short program in this funky new language called “Java” and we all had a good laugh at how it tried to make everything about objects, even where it made no sense.
Even if you’re only trying to teach object-oriented programming, I can think of better languages.
At the end of the day your average programming job at your average company is “all about classes, getters and setters, inheritance and so on”, and if you want to prepare students for that, you should probably focus on that.
I find much the same to often be true for many Java programmers. Programmers who start out with a course all about classes, getters and setters, inheritance and so on often end up with their minds wedged such that they never learn to program properly.
Java has one way to do everything. That's reasonable if you're running a large IT department and want programmers to be interchangeable between projects. That's a horrible way to have people understand the richness of computation.
You want new students to learn at least two ways to do abstraction and to structure code, and ideally, to learn many. Then, if they do Java for a random bank or something, they'll see where Java is on the spectrum. If you start with Java, you end with a closed mind.
Dijkstra was good at many things, but there's no need for an argument from authority when we have actual data and not just opinions made to sound stronger because they are phrased more aggressively.