[Cuis-dev] overriding doesNotUnderstand

Stephen Travis Pope stephen at heaveneverywhere.com
Mon Jun 10 13:14:41 PDT 2024


Hi All,

FYI, I use the technique of overriding DNU to create generic behaviors extensively in the Siren music package.
The base class of events has a property list (Dictionary), and overrides single-arg DNU as setters and no-arg DNU as getters. i.e., if the class Event has a dictionary called properties (lazily instantiated, of course), then

	anEvent color: red		becomes	 	anEvent properties at #color put: red

and

	anEvent color			becomes	 	anEvent properties at #color ifAbsent: [nil]


stp


--------

Stephen Travis Pope    Ojai, California, USA
    
     http://HeavenEverywhere.com
     http://FASTLabInc.com
     https://vimeo.com/user19434036/videos
     http://heaveneverywhere.com/Reflections



> On Jun 10, 2024, at 11:16 AM, Mark Volkmann via Cuis-dev <cuis-dev at lists.cuis.st> wrote:
> 
> On Mon, Jun 10, 2024 at 11:01 AM <ken.dickey at whidbey.com <mailto:ken.dickey at whidbey.com>> wrote:
>> On 2024-06-10 07:42, Mark Volkmann via Cuis-dev wrote:
>> 
>> > I'm learning about overriding the `doesNotUnderstand` method in a class 
>> > to support processing somewhat arbitrary messages. But the Smalltalk 
>> > editor is perhaps being too helpful. It doesn't want to let me send an 
>> > "unknown selector". So it's not clear to me how I can send a message 
>> > that will trigger my implementation of the `doesNotUnderstand` method. 
>> > Is there a way I can do this?
>> 
>> When you save the method, you can just `confirm` this selector is what 
>> you want.
>> 
>> It is useful to have unknown selectors, BTW to "debug code into 
>> existence".  Just keep running the code and write code for the selectors 
>> as they come up as missing into the debugger.
>> 
>> Use of #doesNotUnderstand is frequently the wrong thing to do.
> 
> Thanks Ken! I was finally able to get my demo code working. A fileOut is attached.
> 
> I see how the thing I implemented is not really a good idea. I was just trying to learn how `doesNotUnderstand` works.
> I have a class method `demo` that demonstrates using my `Map` class with the following:
> 
> map := Map new.
> map firstName: 'Mark'.
> map firstName print
> 
> The `Map` class has an instance variable that holds a `Dictionary`. Sending messages to a `Map` instance accessed the `Dictionary`. This lets me specify `Dictionary` keys with arbitrary messages. But an issue I discovered is that this breaks if the message name matches an existing method like `name`. I know I should just stick with sending `:at` and `:at:put` to a `Dictionary`. This was just a learning exercise.
> 
> -- 
> R. Mark Volkmann
> Object Computing, Inc.
> <Map.st>-- 
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240610/c7552f91/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.tiff
Type: image/tiff
Size: 2442 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240610/c7552f91/attachment-0001.tiff>


More information about the Cuis-dev mailing list