[Pharo-project] support for flattening-out traits for export?

Eliot Miranda eliot.miranda at gmail.com
Tue Jun 7 13:48:52 EDT 2011

On Mon, Jun 6, 2011 at 11:11 PM, Mariano Martinez Peck <
marianopeck at gmail.com> wrote:

> On Tue, Jun 7, 2011 at 12:47 AM, Eliot Miranda <eliot.miranda at gmail.com>wrote:
>> Hi All,
>>     if I want to export a package (Fuel!!) to a dialect without traits is
>> there anything to help me remove the trait info and just file-out the
>> composed code?
> Hi Eliot. Traits are only used in Fuel for testing. And really used for
> testing methods for classes and traits (not the basic methods). So, of
> course, you can directly fileout the Fuel package only without traits.

Hmm, at least in Fuel stable 1.4 there exists FLTWithClass trait which is
used by FLObjectCluster and FLRawArrayedCollectionCluster.  This seems
reasonable to me; Pharo and Squeak currently support traits.  But I'm trying
to use Fuel in Newsqueak (the Squeak Newspeak implementation) and we
eliminated traits from that system.  So...

Turns out there is a facility to remove traits, and had I browsed before
asking (lazy man, me) I would have found it (I'm in an updated 1.2):


and so one can theoretically eliminate traits from Fuel by e.g.

#('Fuel' 'FuelTests') do:
(SystemNavigation new allClassesInPackageNamed: pn) do:
c isTrait
ifTrue: [c category: #Unpackaged]
[{c. c class} do: [:b| b flattenDownAllTraits]]]]

but there's a couple of bugs, one weird.  The first bug is that
basicLocalSelectors can answer nil and so Behavior>>flattenDown: (find
attached) needs to read:

flattenDown: aTrait
| selectors |
[self hasTraitComposition and: [self traitComposition allTraits includes:
aTrait]] assert.
selectors := (self traitComposition transformationOfTrait: aTrait)
self basicLocalSelectors: (self basicLocalSelectors
ifNil: [selectors]
ifNotNil: [:bls| bls , selectors]) asSet.
self removeFromComposition: aTrait

But the weird bug, which I suppose could be a Cog VM bug, and that I don't
have time to track down right now, is that if I try the doit
above FLRawArrayedCollectionCluster class ends up losing its #for: method
from FLTWithClass classTrait but FLObjectCluster does not.  But if I

FLRawArrayedCollectionCluster class flattenDownAllTraits.

manually before the doit then FLRawArrayedCollectionCluster class does /not/
lose its #for: method and everything is ok.

BTW, I find adding a literal selector mode to the finder is really useful.
 Being able to look for just #for: instead of all the selectors containing
for: makes finding for: much easier (try it and see) ;)  So find attached a
modification to the finder that matches exactly that selector if one
surrounds it with double quotes.  i.e. searching for "for:" finds only the
implementors of #for:.

> One of the things I always wanted is what you are really asking, a way to
> fileout forgetting traits, just letting those methods directly in the
> classes. But I have no idea if that's possible.

Well, if we can track down and fix the bug then a package-level
flattenDownAllTraits could be constructed and provided from a menu.  That
would be useful and as you can see, at least theoretically its easily done

> Finally, I was never really convinced about the Traits usage in Fuel.
> Mostly because some tools seem not to be happy with them...We should check
> how much difficult and what we loose removing them now....

At least in Fuel core you'd loose almost nothing.  The FLTWithClass trait
adds 6 methods but is used only by two subclasses of FLCluster,
(FLObjectCluster and FLRawArrayedCollectionCluster).  So you could add a
subclass of FLCluster, e.g. FLClusterWithClass, and then
move FLObjectCluster and FLRawArrayedCollectionCluster under it.  At least
that's what I'd do.


P.S.  Fuel looks well-factored.  I like the idea of abstracting the code for
marshalling specific kinds of classes into the FLCluster hierarchy.  I look
forward to providing more feedback once we're using Fuel.

> Cheers
> --
> Mariano
> http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20110607/82a0a411/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Behavior-flattenDown.st
Type: application/octet-stream
Size: 534 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20110607/82a0a411/attachment.st>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Finder-messagesNameSearch.st
Type: application/octet-stream
Size: 1726 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20110607/82a0a411/attachment-0001.st>

More information about the Pharo-dev mailing list