Self Uses Capitalization For Syntax

It's not immediately obvious from a quick skim of the documentation, but SelfLanguage uses capitalization as a part of its syntax.


From:

http://research.sun.com/research/self/release_4.0/Self-4.0/Tutorial/Language/SyntaxAndSemantics/Messages.html

The syntax of the SelfLanguage is very similar to that of the SmalltalkLanguage. One difference is that in Self, the first keyword of a message must start with a lowercase letter, and the remaining keywords must start with an uppercase letter:

        array at: 3 put: 'banana'.    "Smalltalk"
        array at: 3 Put: 'banana'.    "Self"

The reason for this restriction is that it allows Self to get away with fewer parentheses. This is especially important because Self doesn't have a special syntax for assignment, like Smalltalk's := operator; Self just uses ordinary keyword messages for assignment.

        kids  :=  people select: [  :p|  p age < 18 ].     "Smalltalk"
        kids:     people select: [ |:p|  p age < 18 ].     "Self"
        kids:    (people select: [ |:p|  p age < 18 ]).    "Also Self, but the parentheses are unnecessary."

Without the capitalization restriction, the second line would get parsed as a call to a method called "kids:select:". As it is, Self can parse it as a call to "kids:", passing in the result of the call to "select:".


Other languages also use CapitalizationForSyntax


Wow -- I'm looking at the above explanation, and simultaneously think it's cool and a pain in the butt to read/maintain. It's cool in that, in the simplistic case of slot assignment, it eliminates a pair of parentheses. However, it's a pain in the butt to maintain because it opens up the opportunity for abuse in more complex expressions.

From a language parsing point of view, this looks like it's really hard to parse and get right. Does anyone have experience writing a Self parser? What difficulties have you run into?


This syntax has a problem if Unicode selectors are to be used. For example:

        array at: 3 put: 'banana'.    "Smalltalk"
        array at: 3 Put: 'banana'.    "Self"
        array 於: 3 置: 'banana'.    "Smalltalk, in Chinese"
        array 於: 3 置: 'banana'.    "Self, in Chinese?"
Suggestion for a new syntax:
        array at( 3 )put( 'banana').    "NEW. Please note there is no space before the word put"
        array 於(3)置('banana').    "NEW, in Chinese."

youngster := people aging: 8 to: 18. "Smalltalk" youngster: people aging: 8 To: 18. "Self" youngster( people aging(8)to(18)). "NEW" youngster( people 年(8)到(18)). "NEW, Chinese"

It appears nice to me. --JimGuo? 郭宏


CategorySelf


EditText of this page (last edited August 5, 2010) or FindPage with title or text search