This project has moved. For the latest updates, please go here.

Self expression syntax

A self expression is essentially a (possibly cascaded) message sent to self, except that the pseudo-variable "self" is omitted. The value of the "invisible self" that receives the message is established by configuring the compiler to set the pseudo-variable self to the desired value during execution of the self expression.

A self expression is allowed just one message chain having just one message receiver--and the receiver must not be specified syntactically.

Conceptually, the syntactically unspecified--and therefore implied--receiver of the message(s) in the message chain of a self expression is the pseudo-variable self. That's because the same compiler infrastructure used to set the pseudo-variable self to the correct value during the execution of a method or block is also used to set the value of the implied, unspecified receiver of the message(s) in the message chain of a self expression, and also because a self expression is parsed by the parser simply by adding an actual parse node for the pseudo-variable self as the receiver of the message(s) in the message chain of the self expression. That's possible because the parser implements self expressions as their own "root parse node" or "grammatical start symbol."

Any syntactically-valid expression which sends a message to an operand can be converted into a self expression simply be removing whatever syntactical construct is the receiver of the message (a.k.a, the leftmost operand in an expression.) The following examples show two pairs of expressions, where the first member of the pair uses self expression syntax and the second one does not:

Configuring a class

"Using 'self expression' syntax:"

        superclass: Object; 
        instanceVariableNames: #(red green blue)


"Using 'expression' syntax:"

        Color 
                superclass: Object; 
                instanceVariableNames: #(red green blue)

Adding methods to a class (using method literals to define the method):

"Using 'self expression' syntax:"

        protocol: #accessing 
        method:
                [## red
                        ^red
                ]


"Using 'expression' syntax:"

        aClass
                protocol: #accessing 
                method:
                        [## red
                                ^red
                        ]

Prior Art

The inspiration for self expressions comes from Tirade, a data representation language invented by Göran Krampe. The main reason that Essence# uses self expressions instead of Tirade is simply because, once you have a full parser/compiler, it is significantly simpler to implement self expressions than to implement Tirade. Given a full compiler, implementing self expressions only involves adding a few, relatively small methods to the parser and compiler. And it also technically doesn't require adding new syntax to the language, since self expressions only use syntactical forms that would have to exist in any case; the only innovation is to permit simpler syntax that omits an otherwise-required syntactical construct. So self expressions were "the simplest thing that could possibly work."

That said, Tirade would be a much superior solution to the problem of programming-language neutral data interchange. But that's not the problem that self expressions are intended to solve.


The essence of OOP: It's all messages, all the time.


Last edited Aug 11, 2014 at 12:05 AM by Strategesis, version 19