On 4/27/20 7:51 AM, Stéphane Ducasse wrote:
Hi

Doig the XP for magic literals I found

Symbol >> precedence
"Answer the receiver's precedence, assuming it is a valid Smalltalk
message selector or 0 otherwise.  The numbers are 1 for unary,
2 for binary and 3 for keyword selectors."

self size = 0 ifTrue: [^ 0].
(self first isLetter or: [ self first = $_ ]) ifFalse: [^ 2].
self last = $: ifTrue: [^ 3].
^ 1



#'_foo' precedence.
"1"
#'_+' precedence.
"1"
#'+' precedence.
"2"
#'foo' precedence.
"1"
#'foo:' precedence.
"3"
#'_foo:' precedence.
“3"

And I wonder why we are concerned with _

Underscores and letters are treated the same by the Smalltalk grammar. Unary, keyword and variables can all begin with letters or underscores. "_" is a valid variable and unary message name. As for your tests, you would get the same results if you replaced $_ with $a -- "#'a+' precedence = 1".


John Brant

Reply via email to