Using superPerform

I’m looking for a quick example, or a basic understanding, on how to use superPerform an instance method defined in

perform { arg selector ... args;

	// super.perform(selector,arg) doesn't do what you might think.
	// \perform would be looked up in the superclass, not the selector you are interested in.
	// Hence these methods, which look up the selector in the superclass.
	// These methods must be called with this as the receiver.

	superPerform { arg selector ... args;

I don’t fully understand why everything evaluates the same… I initially expected super to refer to the superclass of the object in the current state of reference, however, I believe I may be missing something rudimentary.

this // -> an Interpreter
super // -> an Interpreter
this perform: \value // -> an Interpreter
this superPerform: \value // -> an Interpreter
this // -> an Interpreter
super // -> an Interpreter

Mostly seeking to gain a first order of understanding regarding use within sc-code… versus writing classes, however, a holistic explanation may also serve the question, which is mostly driven by the notion of using the method superPerform from within the client interpreted code, on any practical object, if it would ever be useful, in any way.

Thanks in advance.

this and super make sense only within a method definition. They are essentially meaningless in interactive code. You’re testing with interactive code, hence, getting a meaningless result.


In a method body ‘this’ (‘self’) refers to the receiver, the object that received the message.

‘super’ refers to the same object.

The difference is where message lookup begins.

This is one of the few subtle parts of Smalltalk.

There are lot’s of books on Smalltalk, there’s also this perspicuous remark by Eliot Miranda:

About perform, the comments from the parallel methods in Squeak are perhaps a bit clearer, copied below.

Note that the first message can be implemented in terms of the second.

perform: selector withArguments: argArray
“Send the selector to the receiver with arguments in argArray.
Fail if the number of arguments expected by the selector
does not match the size of argArray.
Primitive. Optional. See Object documentation whatIsAPrimitive.”
<primitive: 84>
^ self perform: selector withArguments: argArray inSuperclass: self class

perform: selector withArguments: argArray inSuperclass: lookupClass
“NOTE: This is just like perform:withArguments:, except that
the message lookup process begins, not with the receivers’s class,
but with the supplied superclass instead. It will fail if lookupClass
cannot be found among the receiver’s superclasses.
Primitive. Essential. See Object documentation whatIsAPrimitive.”
<primitive: 100>

1 Like