
Dylan Tip #101: don't use keyword init-values with class allocated slots
Hi,
Since it is on topic, I thought I'd share a tip from a Dylan compiler hacker
who found an inefficiency in my code. Harlequin Dylan's keyword init values
work and they become rather {*filter*}ive after a while. However, I was using them
with a class allocated slot (actually each-subclass):
define class <foo> (<object>)
each-subclass slot quux = 0, init-keyword: quux:;
end class;
define class <bar> (<foo>)
keyword quux: = 1;
end class;
This means (in Harlequin Dylan) that the class allocated slot gets
reinitialized as each instance is made. This is obviously unnecessary as the
slot has the same value across the class.
Better would have been:
define class <foo> (<object>)
each-subclass slot quux = 0, init-keyword: quux:;
end class;
define class <bar> (<foo>)
inherited each-subclass slot quux = 1;
end class;
__Jason