[Cuis-dev] clever or silly idea?
Mark Volkmann
r.mark.volkmann at gmail.com
Tue Jun 11 17:12:33 PDT 2024
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> 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
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
--
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240611/c775489b/attachment.htm>
More information about the Cuis-dev
mailing list