Rethinking the comma

This is a follow-up to the post about message chains from a few days ago. Like any syntax-related issue, the choice of the operator is one of those delightful things that encourage a lively exchange of opinions by virtue of being easy to have an opinion about. I ended the post half-seriously considering “:)”, but here is an interesting thought experiment.

Suppose we abolish a comma as a binary message. A + could just as well work as a generic “join these two things” message a comma usually is. Instead, suppose that the comma becomes the new chain operator. Here is what it would look like.

something thingsAt: aKey, includes: aThing,
    ifTrue: [...]
    ifFalse: [...]

This fits nicely with the original Smalltalk idea of using natural language punctuation for message control, and continues the line-up of a period and a semicolon by being the weakest message separator of them all.

6 thoughts to “Rethinking the comma”

  1. would be really nice to push this in squeak-dev a bit more forcefully :)
    personally i don’t like the “comma message” much:
    1. #+ seems more intuitive way of joining strings (anything) together and
    2. it’s a bit confusing, cause $. and $; are syntactic elements already

  2. This is a change which will break a lot of existing Smalltalk programs. However, I really, really like it. It should be done. :)

  3. I know you posted this a month-and-a-half ago… but… no matter what you choose, you’re going to need to modify the compiler, right? To have a message type that has a lower precedence than keyword? unary > binary > keyword … Or am I just slow, and that has already been discussed and I missed it?

  4. Yes, this can only be implemented by modifying the compiler. A comma interpreted this way isn’t a message send at all, however, just like a semicolon and a period aren’t messages in regular Smalltalk.

Comments are closed.