[squeak-dev] DynamicObjects
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Sun Apr 26 18:10:06 UTC 2020
I agree with all your comments about confusion.
Still, there is one thing you could do with this approach of "DynamicObjects" which our usual meta protocol does not support afaik:
d := DynamicObject withMethods: {
'somePrefix*' -> [:sel | sel allButFirst: 'somePrefix' size].
'selector(Regex)+' asRegex -> [:match | match size - 'selector' size / 'Regex' size]
} asDictionary.
d somePrefixBanana. "'Banana'"
d selectorRegexRegexRegex. "3"
And you should *really* only use this in tests :-)
@Torge: Interesting point. I could only find a ReverseTrampoline<http://www.metaobject.com/downloads/Squeak/HOM.cs> (by googling for smalltalk "subclass trampoline"). :-)
Best,
Christoph
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Montag, 20. April 2020 11:03 Uhr
An: gettimothy via Squeak-dev
Betreff: Re: [squeak-dev] DynamicObjects
Uhh! This feels like JavaScript ... :o) I would rather work on improving Squeak's meta-object protocol and with it class construction and refinement. Especially for tests. Let's not undermine the idea of having classes in Smalltalk.
-1 for DynamicObject.
Objects in Squeak/Smalltalk are quite dynamic already. That name is misleading. :-)
Best,
Marcel
Am 18.04.2020 19:55:05 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
d := DynamicObject withMethods: {
#origin -> [2 @ 3].
#corner -> [3 @ 7] } asDictionary.
d origin "2 at 3"
Did we already have something like this for Squeak? May this become a pattern for situations where you actually don't need a class (e. g., when writing very small mock objects for tests)?
d := DynamicObject new.
d xxxMethodAt: #foo put: [self inform: 'Hi!'].
d xxxMethodAt: #foo: put: [:x | x halt].
d foo: 3.
Best,
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200426/5cdb8f02/attachment.html>
More information about the Squeak-dev
mailing list
|