Tuesday, September 26, 2006

Scheme Suicide Note?

Friedman gave me a bit of a shock today when he hinted that the new version of Scheme might be dropping set-car! and set-cdr! from the language. For those of you who don't know Scheme (but should!) - these are ways of modifying the values of variables. Truly Lexically Scoped languages do not allow this. Scheme is only mostly lexically scoped, which means it encourages you not to modify variables, but gives you the ability to do so if you must.

set-car! and set-cdr! provide this function for lists. Most of Scheme code is based on lists. The car of a list is the first item in the list, and the cdr is everything else in the list in a list of its own. So for the list '(1 2 3 4), 1 is the car and '(2 3 4) is the cdr. So these two keywords allow you to destructively change the values of lists (i.e. rather than recopying the list to get the new one you want you can just change the value of the old one).

So why would it bother me that these keywords were coming out? Well, as I've said before more than once, I believe that programming languages should leave the programmer as much control as possible. I don't have any problem with them encouraging any particular style of programming, but I want the ability to do things that are inconsistent with that style if that seems necessary. A programming language should leave the programmer free. I hate languages like Java that make most of the design decisions for you and leave you no way around its choices! Just like in human languages, in programming languages you want a language that lets you say whatever you want to say, not just what it approves of you saying.

So I am sorry to see set-car! and set-cdr! go. However, it's not the shock that I thought it was at first. When Friedman said that today, I got worried that perhaps they weren't going to allow variable clobbering at all, which would be a monumentally stupid design decision. And in fact, I was prepared to give up Scheme and even did a bit of reading up on ML as a precaution. But then I reasoned that it simply couldn't be that they were getting rid of all variable clobbering, so I had a look at the draft for the new language (linked above) and am pleased to say that, although set-car! and set-cdr! are indeed not in the report, set! is still there, so it's trivial to add set-car! and set-cdr! back in if you really need them.

That doesn't make taking them out OK, though. I don't really see the point. Again, in general programming languages should give the programmer as much power as possible. Granted, there's no particular motivating reason to give anyone set-car! and set-cdr!, necessarily. If you want to discourage programming with side effects, then just giving set! and not making a big deal about it is indeed the best way to go (of course, set! needs to stay because, as I said, it should at least be possible to add side-effects to your program). But it seems to me that since set-car! and set-cdr! are already with us, we might as well keep them around, if for no other reason than not to needlessly break any old code. Taking them out after we've already gotten used to them is a bit too heavy-handed/Javaesque for my taste.

But whatever. As long as they leave me set!, we're more or less good. I'll keep using Scheme.

I'm pleased to note, by the way, that contrary to what I thought, ML does allow variable clobbering. There's a builtin ref keyword that turns a variable into a reference, so if you really need to change one you can. So that removes my biggest objection to it. Of course, I'm not planning to switch from Scheme anytime soon (I do most of my coding in Scheme or C++. I'm a recovering Python addict and try to stay away from that language because the ease of programming in it makes it difficult for me to then switch back to the harder stuff!). But I thought it worth giving Haskell, ML and Ruby each a closer look.

Of the three, I'm most likely to be impressed by ML, I think. Haskell is interesting because of Monads and call-by-need semantics (Wikipedia article here). These are things I should get more comfortable with (and actually, I have no idea of Monads, so this is new territory), and so learning Haskell to practice them (and maybe get addicted to Haskell in the meantime? Who knows?) seems like a good idea. Ruby is just sort of fun. I've dabbled before in the language that dare not speak its name (OK, that's actually Oz. What a mess!), and it's lots of fun. But the insistence on absolutely bloody everything being an object gets really old. So yeah, sure, although I know that Ruby has yield and closures and continuations and monads all that (all of which are Very Cool Things that more languages should have), the slavish devotion to the Object-Oriented paradigm will probably turn me off of it before too long. But we'll see. There are objective viewers who say it's not just a fad, and I myself have said that I wouldn't exactly be surprised to see it as at least the new Perl, maybe even the Next Big Thing. We'll see. Can't hurt to learn it. But yeah, of these three, ML seems closest to Scheme - so it's an uphill battle for the other two.

But back to Scheme - I'm glad to know that set! is still with us, but I wish they would leave me set-car! and set-cdr! too. All I can really say about this is that we seem to be entering a decade where enforcing the paradigm of one's choice will be trend in PL design. More's the pity. Of course, this virtually guarantees that C++ will survive...


Post a Comment

Links to this post:

Create a Link

<< Home