Last updated at 3:44 pm UTC on 3 January 2018
Citation from: http://web.cecs.pdx.edu/~harry/musings/SmalltalkOverview.html#Keyword%20Messages
Third, we discuss "keyword" messages. These are the most unusual and cause the most confusion. Let's start with this Java message-send:
x.addKeyValue(a, b) // Java
Here, there are 2 arguments and the message name is "addKeyValue". Here is the Smalltalk equivalent:
x addKey: a value: b "Smalltalk"
The message name in Smalltalk is "addKey:value:" and you will notice that it contains the colon character. The colon character is used in keyword message sending and is syntactically significant in understanding the keyword syntax.
Note that the message name is not one contiguous token. When used, the message name will be spread out, with intervening argument expressions. Nevertheless, it is one message-send, with one receiver and two arguments.
By looking at the message name, you can tell exactly how many arguments the message takes: just count the colons! "addKey:value:" will take 2 arguments while "add:" will take one argument.
Keyword messages take one or more arguments and will therefore always have at least one colon in them. (If you want a message with no arguments, you would use a unary message.)
Here is another example keyword message.
x addKey: a value: b useMap: myMap ifError: errCode
The message name is "addKey:value:useMap:ifError:" Four colons mean four arguments.