Hi Kevin, > I'm wondering why this is not running as expected? > > (for @Cls '(+A +B) > (run > (fill > '((class @Cls) > (println 'define '@Cls) # prints: "define +A", then "define +B" > (dm c> () (println (type This) 'default)))))) > .. > (extend +B) > (dm c> () (println (type This) 'extended)) # prints: "c> +B redefined"
It is because 'dm' stores the whole method definition as it is, i.e. (c> NIL (println ...)), without doing an extra copy. If later called again with another definition for the same message, it modifies the existing definition destructively. Normally this is not a problem, as the definitions are read from a source file and are thus fresh in each definition. In the above 'for' loop, the method entry (c> NIL (println ...)) is re-used, so that both classes point to the same cell. Then, when you redefine 'c>' in '+B' you also modify it in '+A' as a side effect. To avoid this behavior, you can call (undef 'c> '+B) before redefining 'c>' in '+B'. Or, even better, use a common superclass which defines 'c>', and then override it in '+B'. ☺/ A!ex -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe