[Cuis-dev] clever or silly idea?

Andres Valloud ten at smallinteger.com
Tue Jun 11 16:35:25 PDT 2024


There should be a mirror-type virtual machine or perhaps debugger API to 
send a message to an object without using perform:withArguments:.

It doesn't seem to me it's a good idea, though.  For example, what 
happens when one of your instance variables has a name that matches a 
unary selector defined by a superclass?  Also, it's going to be very 
slow.  And debugging is impeded by coalescing a multitude of specific 
locations to place a breakpoint into an overly general one.

On 6/11/24 4:29 PM, Mark Volkmann via Cuis-dev wrote:
> A thought occurred to me that I could override the instance method 
> `doesNotUnderstand` in a class to avoid writing a bunch of basic 
> accessor methods. Setting aside whether it's ever a good idea to have a 
> getter and setter method for every instance variable in a class, I 
> thought I could do it like this:
> 
> doesNotUnderstand: aMessage
>      "gets or sets an instance variable"
> 
> | argCount getters key setters value |
> 
> argCount := aMessage numArgs.
> argCount > 1 ifTrue: [ ^super doesNotUnderstand: aMessage ].
> 
> key := aMessage keywords first.
> getters := self class allInstVarNames.
> setters := getters collect: [ :name | name, ':' ].
> (getters, setters includes: key) ifFalse: [ ^super doesNotUnderstand: 
> aMessage ].
> 
> argCount = 0 ifTrue: [ ^self perform: key ].
> 
> value := aMessage arguments first.
> self perform: key with: value
> 
> But this goes into an infinite loop because sending the `perform:` 
> message ends up hitting `doesNotUnderstand` again. Is there a way I 
> could make this work?
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
> 


More information about the Cuis-dev mailing list