Search code examples
methodssmalltalk

Should'nt there be a colon (':') in the method declaration?


I see following code from here:

+ val [
    <category: 'math'>
    ^Complex real: (realpart + val real)
        imaginary: (imagpart + val imaginary)
]
- val [
    <category: 'math'>
    ^Complex real: (realpart - val real)
        imaginary: (imagpart - val imaginary)
]

These define methods/function of + and -. I generally find the functions/methods are defined as follows (from here):

spend: amount [
    <category: 'moving money'>
    balance := balance - amount
]

Why there is no : (colon) after + and - in code mentioned above?

Thanks for your insight.


Solution

  • There are three types of messages, unary, binary, and keyword. Only the keyword message has a colon. I suggest that you try out the short, on-line, tutorial at https://amber-lang.net/learn.html.