41 ms·
> If you can convey 95% of the basic ideas in Python But you cannot. Some of the ideas in SICP can nearly be conveyed in Python (like lexical scoping, closure
by jules 18y ago
> If you can convey 95% of the basic ideas in Python
But you cannot.
Some of the ideas in SICP can nearly be conveyed in Python (like lexical scoping, closures, data types, streams). You'll use built-in language features in Python (classes, generators) instead of implementing the functionality. I think that implementing these things is important if you want to really understand them.
An example, cons, car and cdr from nothing at all:
(define (cons a b) (lambda (f) (f a b)))
(define (car p) (p (lambda (a b) a)))
(define (cdr p) (p (lambda (a b) b)))
You can do this in Python in theory, but you can't throw this into a Python course.
Other ideas, like interpreters, require a lot of effort. Try writing a metacircular interpreter!
- sharkbrainguy 18y agodef cons(a, b): return lambda f: f(a, b) def car(p): return p(lambda a,b: a) def cdr(p): return p(lambda a,b: b) As well as in theory you can do this in practice. It's about as elegant (hard for me to judge as I have a strong pro-lisp bias). Aside from lack of tail safety and performance issues with writing scheme-ish code I don't see why you couldn't implement those things in Python. The main difference is that typically in a real world situation you wouldn't because there's a library or a language feature
- silentbicycle 18y agoIt's also counterbalanced by there being an obviously standard, reasonably portable distribution of Python. You go to Python.org, and there it is. It took me a while to find a Lisp that I liked, and it certainly wasn't a decision I was prepared to make while I was still trying to learn the basics. (I eventually settled on Chicken Scheme.)
- jules 18y agoThe problem is not that you can't do this in Python, but that this is out of place in a Python course (you don't use linked lists in Python, for example). SICP shows that you need only a very small number of primitives to get a full programming language. You don't get this elegance with Python. This may not be important if you teach programming to people who want use programming languages, but it is important for people who want to advance the state of the art in programming (i.e. CS students). Maybe it's better if you teach Scheme in a seperate class class for CS students.
- Kaizyn 18y agoYour definitions do not work. foo = (1,2,3) bar = (4,5,6) print cons(foo, bar) print car(foo) console output: <function <lambda> at 0x00B3F430> Traceback (most recent call last): File "./test.py", line 14, in <module> print car(foo) File "./test.py", line 5, in car return p(lambda a,b: a) TypeError: 'tuple' object is not callable
- danprager 18y agoThey do work; they just don't integrate with the built-in types: Why should they? Try instead: car(cons(1,2)) -> 1 cdr(cons(1,2)) -> 2 car(cons('a', cons(2, 3))) -> 'a'
- maggie 18y agoYou need to remember that 6.001 is an /introductory/ programming course. Presumably most of the people taking it at MIT have done some codework before : ] but an intro. course is an intro. course. The question of what language to use is a pedagogical one, not a question of thoroughness.
- abstractbill 18y agoBut the above examples are taken straight from SICP. Wasn't that the textbook for 6.001 before they switched to Python?
- jerf 18y agoWhich sort of wanders back around to begging the question; is that still the best way to start teaching, as Sussman talks about? I ask myself, "how would I teach my son to program?", and for all my copious academic and practical experience, "start with re-implementing car and cdr from lambda functions" isn't even remotely in the running. Sure, I'd introduce such things earlier than most people and SICP is still firmly in the running, but for that to be an introduction in the general case? Not so sure. There's definitely an argument to be made that robotics is in many ways a much more realistic starting point. While some people may find the idea that we should actually start out by making a case to the students that their major is cool and important and gives them the ability to affect things in the real world vaguely repulsive, I'd say that it's an idea at least worth considering. The student that can leap from lambda, car, and cdr, to realizing that right in the introductory course is so exceptional that you're not going to hold them back anyhow.
- abstractbill 18y agoYeah, I think I actually agree with the overall point. I got my first experience of programming using BASIC to get various Sinclair computers to paint stuff on the screen and make funny beeping noises. I'm all for instant gratification. On the other hand that was when I was 9. By 12 I was learning Lisp, and by college age I'd written my own little Lisp compiler. I've always had this image of MIT students that doesn't quite mesh with them needing a gentle introduction to programming, but maybe that's not really the case?
- newt0311 18y agoUm... Yes you can. Here is your above example: >>> def cons(a, b): ... def lm(f): ... return f(a, b) ... return lm ... >>> def car(cns): ... return cns(lambda a, b: a) ... >>> def cdr(cns): ... return cns(lambda a, b: b) ... >>> x = cons(1, 2) >>> car(x) 1 >>> cdr(x) 2 Most scheme code translates relatively cleanly into python code. The biggest problem in translation comes when code wants to modify variables in a closure. Since SICP is primarily concerned with functional programming, this is a non-issue. Furthermore, Python 3.0 includes the nonlocal statement which fixes this problem (details here: http://www.python.org/dev/peps/pep-3104/ http://www.python.org/dev/peps/pep-3104/). Python is not lisp but its pretty darn close and unlike lisp (or scheme in this case), it has a well designed, well tested standard library -- something extremely important in programming languages today. In light of this information, MIT's decision to move to Python is justified.