Smalltalk Syntax

Smalltalk syntax is enjoyable for some similar reasons to PythonSyntax.

Smalltalk is completely message based. The only way to interact with an object is to send messages to it. So a good place to start is SmalltalkMessageRules.

 Java version
 Iterator it = myCollection.iterator();
 while (it.hasNext())
 {
 Myobject anObject = (Myobject) it.next();
 anObject.doSomething();
 }

Smalltalk version myCollection do: [:anObject | anObject doSomething].

 Java version
 myDictionary.put(key, value);

Smalltalk version myDictionary at: key put: value.

...or myString findString: 'foo' startingAt: 2

No. This is of course nice, but for decades, people have called everything you could imagine "self-documenting", up to and including C and assembler. No. Something is "self-documenting" only if it somehow includes multiple paragraphs of freeform English text. Everything is "self-documenting" if the programmer is sufficiently disciplined, and nothing is if they are the opposite. Example:

  Java version
  jkfdjkfjdk.xxxxrrrrr(yytytytde, qererere);

Smalltalk version jkfdjkfjdk xxxxrrrrr: 'yytytytde' qererere: 2;

Standard methods in standard classes can't go wrong to that extent, of course, but the standard methods/classes are not the real problem in languages, because they're well known and guaranteed to have thorough documentation, etc.


I am currently trying to write (with Lex/Yacc) a parser for Smalltalk. (Just for fun, because I like writing small interpreters and Smalltalk syntax seemed easy enough.) Fair enough, the resulting grammar is probably quite a lot simpler than a C++ grammar, but nevertheless I discovered the following syntactic warts that make Smalltalk somewhat more challenging to parse:

BuddsLittleSmalltalk solved these problems by bending the rules of the language a little. Would this be acceptable to you?

Uh, this would not be acceptable to me. Mostly because I view it as unnecessary. The "Smalltalk Interchange Format" (which I grew up calling "Chunk Format") is designed to be read by an object in a live Smalltalk environment, not a compiler -- the receiver unpacks the bang-delimited string and passes it to the compiler when needed. -- TomStambaugh

-- StephanHouben


Note, that Smalltalk has no special if, case and looping constructs, but the base-library contains methods implementing "if" and looping and they are usually optimized aggresively by the compiler. There is no SmalltalkCaseStatement and there is usually no need for it.


A nice demo of extreme simplicity in SmalltalkSyntax:


CategorySmalltalk


EditText of this page (last edited February 28, 2014) or FindPage with title or text search