Defining Double-Icon Methods (>>) in Smalltalk

In Kent Beck's Smalltalk Best Practice Patterns , double sign ( >>) is used to identify these methods:

Point class>>x: xNumber y: yNumber
    ^self new
        setX: xNumber
        y: yNumber

Point>>setX: xNumber y: yNumber
    x := xNumber.
    y := yNumber.
    ^self

However, I cannot run it in GNU Smalltalk.

Is this a valid syntax in some Smalltalk implementation? Or is it just pseudo code?

+5
source share
3 answers

This is actually pseudo code.

In other languages ​​you should use .to tell people that the method is in this class, but in smalltalk you write>>

What would you do in Smalltalk like Squeak or Pharo for

Point class>>x: xNumber y: yNumber
    ^self new
        setX: xNumber
        y: yNumber
  • Open the system browser
  • klick on class, , .
  • :

    x: xNumber y: yNumber
        ^self new
            setX: xNumber
            y: yNumber
    
  • Strg-s

Point>>setX: xNumber y: yNumber
    x := xNumber.
    y := yNumber.
    ^self

, class

+5

, , , # → - , , ( ). . , →

  >> selector 
"Answer the compiled method associated with the argument, selector (a 
Symbol), a message selector in the receiver method dictionary. If the 
selector is not in the dictionary, create an error notification."

^self compiledMethodAt: selector

, , ( )

  Point class >> #x:y:

, #class, #x: y: . , #normalized, :

  Point >> #normalized
+4

GNU Smalltalk :

Point class extend [
    x: xNumber y: yNumber [
        ^self new
            setX: xNumber
            y: yNumber ]
]

Point extend [
    setX: xNumber y: yNumber [
        x := xNumber.
        y := yNumber.
        ^self ]
]

GNU Smalltalk . .

+2

All Articles