Category:Smalltalk: Difference between revisions

Line 247:
Message sends are dynamically resolved, by letting the receiver of the message determine the method (aka code to run). The message consist of a selector (= name of the message) and optional arguments. The message syntax as:
<lang smalltalk>receiver selector</lang>
a unary message, without arguments. <br>In a C-like language, this would be written as "receiver.selector()".
 
<lang smalltalk>receiver part1: arg1 part2: arg2 ... partN: argN</lang>
a keyword message; the selector consists of the concatenation of the keyword parts: 'part1:part2:...partN:'. <br>In a C-like language (assuming that colons are allowed in an identifier), this would be written as "receiver.part1:part2:...partN:(arg1, arg2,... argN)".
 
<lang smalltalk>receiver op arg</lang>
a so called ''binary message''. The selector 'op' consists of one or more special characters, such as '+', -', '@' etc.
These are actually syntactic sugar, especially to make arithmetic look more familiar (i.e. instead of "rcvr add: foo" we can write "rcvr + foo"). These would look the same in a C-like language, although almost any non-letter-or-digit character is allowed as operator in Smalltalk.
 
The precedence rules are unary > binary > keyword, thus
Anonymous user