[Cuis-dev] clever or silly idea?

Andres Valloud ten at smallinteger.com
Tue Jun 11 17:45:22 PDT 2024


Make a subclass of nil called Parrot.  Implement only

	doesNotUnderstand: aMessage

		^self

and then evaluate the following.

	Parrot new ifTrue: [#haha] ifFalse: [#hehe]

Explain the behavior you see.

Side comments...

1.  It should not be that hard to create a new subclass of nil, 
substituting in ProtoObject when it was not requested is unhelpful.

2.  I could not redefine an existing class to have a superclass of nil 
because the process sends removeObsoleteSubclass: to the superclass of 
the class in question, which in this case is nil.  Juan, this looks like 
new code you wrote recently, you may want to review what happened here.

On 6/11/24 5:12 PM, Mark Volkmann via Cuis-dev wrote:
> Yeah, I didn't really think it was a good idea. It just seemed like a 
> clever trick and a challenge to see if I could get it to work.
> 
> On Tue, Jun 11, 2024 at 6:35 PM Andres Valloud via Cuis-dev 
> <cuis-dev at lists.cuis.st <mailto:cuis-dev at lists.cuis.st>> wrote:
> 
>     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.
>      >
>     -- 
>     Cuis-dev mailing list
>     Cuis-dev at lists.cuis.st <mailto:Cuis-dev at lists.cuis.st>
>     https://lists.cuis.st/mailman/listinfo/cuis-dev
>     <https://lists.cuis.st/mailman/listinfo/cuis-dev>
> 
> 
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
> 


More information about the Cuis-dev mailing list