The Inbox: Environments-jr.70.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Environments-jr.70.mcz

commits-2
A new version of Environments was added to project The Inbox:
http://source.squeak.org/inbox/Environments-jr.70.mcz

==================== Summary ====================

Name: Environments-jr.70
Author: jr
Time: 12 February 2017, 3:42:16.327498 pm
UUID: cbbca4a2-6a97-2b40-92b8-631bbfa519d0
Ancestors: Environments-jr.69

add hasClassOrTraitNamed:

useful for lists of behaviors

=============== Diff against Environments-jr.69 ===============

Item was added:
+ ----- Method: Environment>>hasClassOrTraitNamed: (in category 'classes and traits') -----
+ hasClassOrTraitNamed: aString
+ Symbol hasInterned: aString ifTrue:
+ [:symbol | | value |
+ ^ ((value := declarations at: symbol ifAbsent: [nil])
+ isKindOf: Class) or: [value isKindOf: Trait]].
+ ^ false.!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Environments-jr.70.mcz

Bert Freudenberg
On Sun, Feb 12, 2017 at 4:56 PM, <[hidden email]> wrote:
A new version of Environments was added to project The Inbox:
http://source.squeak.org/inbox/Environments-jr.70.mcz

==================== Summary ====================

Name: Environments-jr.70
Author: jr
Time: 12 February 2017, 3:42:16.327498 pm
UUID: cbbca4a2-6a97-2b40-92b8-631bbfa519d0
Ancestors: Environments-jr.69

add hasClassOrTraitNamed:

useful for lists of behaviors

=============== Diff against Environments-jr.69 ===============

Item was added:
+ ----- Method: Environment>>hasClassOrTraitNamed: (in category 'classes and traits') -----
+ hasClassOrTraitNamed: aString
+       Symbol hasInterned: aString ifTrue:
+               [:symbol | | value |
+               ^ ((value := declarations at: symbol ifAbsent: [nil])
+                       isKindOf: Class) or: [value isKindOf: Trait]].
+       ^ false.!

Please do not introduce #isKindOf tests. All the other classOrTrait* methods use #isBehavior tests, which is way more general ... and also in line with your commit message ;)

I'd rather implement this along the lines of "^(self classOrTraitNamed: aString) notNil" which would also make the argument compatible with the range of strings allowed by classOrTraitNamed:.

We may want to add a Symbol internment check to that method, however.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Environments-jr.70.mcz

Jakob Reschke-2
In reply to this post by commits-2
Agreed. I based this on hasClassNamed: which uses the isKindOf: check as well.

classNamed: OTOH does not check the type and will also return a Trait.

2017-02-13 12:01 GMT+01:00 Bert Freudenberg <[hidden email]>:

> On Sun, Feb 12, 2017 at 4:56 PM, <[hidden email]> wrote:
>>
>> A new version of Environments was added to project The Inbox:
>> http://source.squeak.org/inbox/Environments-jr.70.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Environments-jr.70
>> Author: jr
>> Time: 12 February 2017, 3:42:16.327498 pm
>> UUID: cbbca4a2-6a97-2b40-92b8-631bbfa519d0
>> Ancestors: Environments-jr.69
>>
>> add hasClassOrTraitNamed:
>>
>> useful for lists of behaviors
>>
>> =============== Diff against Environments-jr.69 ===============
>>
>> Item was added:
>> + ----- Method: Environment>>hasClassOrTraitNamed: (in category 'classes
>> and traits') -----
>> + hasClassOrTraitNamed: aString
>> +       Symbol hasInterned: aString ifTrue:
>> +               [:symbol | | value |
>> +               ^ ((value := declarations at: symbol ifAbsent: [nil])
>> +                       isKindOf: Class) or: [value isKindOf: Trait]].
>> +       ^ false.!
>
>
> Please do not introduce #isKindOf tests. All the other classOrTrait* methods
> use #isBehavior tests, which is way more general ... and also in line with
> your commit message ;)
>
> I'd rather implement this along the lines of "^(self classOrTraitNamed:
> aString) notNil" which would also make the argument compatible with the
> range of strings allowed by classOrTraitNamed:.
>
> We may want to add a Symbol internment check to that method, however.
>
> - Bert -

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Environments-jr.70.mcz

Bert Freudenberg
On Mon, Feb 13, 2017 at 1:08 PM, Jakob Reschke <[hidden email]> wrote:
Agreed. I based this on hasClassNamed: which uses the isKindOf: check as well.

Yep, it predates isBehavior. I bet there's a lot of cargo-culting going on here ...  
 
classNamed: OTOH does not check the type and will also return a Trait.

That's because it predates traits and has not been updated.

- Bert - 


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Environments-jr.70.mcz

Jakob Reschke-2
In reply to this post by Jakob Reschke-2
I also wondered, what if another kind of behavior comes along one day?
Then ...classOrTrait... might be the wrong choice (or name, depending
on the implementation) again.

After more thought, I would rather like to scrap this patch and change
MCMockPackageInfo>>classes in the other patch to use #hasBindingOf:.
It looks up its own "well known" symbols anyway, that's why I think it
can even forgo the behavior type check. And if the other patch is not
accepted, this one will not be required anyway.

To fullfill my commit message, there should rather be a
hasBehavior:/behaviorNamed:/behaviors triple, shouldn't it?

2017-02-13 15:57 GMT+01:00 Bert Freudenberg <[hidden email]>:
> On Mon, Feb 13, 2017 at 1:08 PM, Jakob Reschke
> <[hidden email]> wrote:
>>
>> classNamed: OTOH does not check the type and will also return a Trait.
>
>
> That's because it predates traits and has not been updated.

Actually, it seems to have been updated in SystemDictionary to be "^
self classOrTraitNamed: className", and then was copied over to
Environment later.