[patch] Enhance to kernel/Behavior.st

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

[patch] Enhance to kernel/Behavior.st

Lee Duhem
Hi,

This patch add some new methods, and a few category name fix.

1. lookupAllSelectors: aSelector

        Answer all the compiled methods associated with aSelector
        from local method dictionary and all of the superclasses.

2. printFullHierarchy

        Similar to printHierarchy, but also print superclasses.

3. superclasses and printSuperclasses: level using: aBlock

        Make the method set of Behavior more consistent and
        predictable.

If some (or all) of these methods don't appropriate to put in
kernel/Behavior.st, you can put them to ~/.st/init.st, sometimes
they are pretty useful.

lee

ChangLog

2009-10-27  Lee Duhem  <[hidden email]>

        * kernel/Behavior.st: Add #lookupAllSelectors:, #printFullHierarchy,
        #superclasses and #printSuperclasses:level:using:.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Behavior.patch (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Paolo Bonzini-2
I'll answer to both messages in one.

> 3. superclasses Make the method set of Behavior more consistent and
> predictable.

I don't like this very much and did not apply it.  Everything else is a
nice addition, but I'd be grateful if you move #printSuperclasses:using:
and #printSubclasses:using: into a "private" category since you're
touching this file.

> This patch provides some extensions to Parser package of
> packages/stinst/parser.
>
> Extensions to Behavior: 1. lookupFormattedSourceString: aSelector
>
> Lookup and return the formatted source codes of a method.

That should be #formattedSourceStringAt:, no?  Also, it could be in
kernel/Behavior.st since the #methodFormattedSourceString is present in
kernel/CompildMeth.st (though disabled until Parser is loaded).  Right
now, however, I'm inclined to omit this.

> Extensions to Symbol: 2. implementors and printImplementors
>
> Method implementors returns all the compiled method which implements
> the selector named by the receiver, printImplementors print these
> compiled methods to the stdout.

#implementors is a nice addition, but you're missing class methods and
subclasses of nil.  Also there's nothing in it that requires Parser, or
am I wrong?

You would need something like this:

        Class allSubclassesDo: [:c | | m |
            m := c compiledMethodAt: self ifAbsent: [nil].
            m ifNotNil: [ implementors add: m].
            m := c asClass compiledMethodAt: self ifAbsent: [nil].
            m ifNotNil: [ implementors add: m]].

#printImplementors is not very useful.  A method like this in Collection
(#printLines for example) would be useful instead:

     self implementors do: [:each | Transcript display: each; nl ]

You could add that instead.

Also, please include a ChangeLog entry with your patches.

Thanks in advance!  Don't be put off by the comments, it's good stuff.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
On Tue, Oct 27, 2009 at 12:48 AM, Paolo Bonzini <[hidden email]> wrote:
> #implementors is a nice addition, but you're missing class methods and
> subclasses of nil.

Subclasses of nil? I didn't understand what this means,  can you explain further
or point to some documents?

> Also there's nothing in it that requires Parser, or am I
> wrong?

Yes, Symbol>>#implementors doesn't need Parser. Actually, I put it in
kernel/Symbol.st
in the first place.

>
> Also, please include a ChangeLog entry with your patches.
>

I did, at the last of my post.

lee


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Paolo Bonzini-2
On 10/27/2009 04:40 AM, Lee Duhem wrote:
> Subclasses of nil? I didn't understand what this means,  can you explain further
> or point to some documents?

While 99% of the classes are subclasses of Object, it is also possible
to create classes that do not inherit from anything (or equivalently,
whose subclass is nil).  In this case, the metaclass will be a subclass
of Class; so I used in my example "Class allSubclassesDo:" to get the
metaclasses (which provide class-side methods), and go to the classes
(which provide the instance side) by sending #asClass.

There is a small part in the tutorial on this topic; alternatively, you
may see if you find a presentation called "The Behavior of Behavior".

By the way, the reason why I didn't like #allSuperclasses is the
following.  The #superclass and #subclasses methods return the classes
that are "adjacent" (one level up or one level down) in the hierarchy.
Prefixing "all" gives also the indirect superclasses/subclasses.
#superclasses then would be a method that returns an array of direct
superclasses (which would have a single element, since Smalltalk only
has single inheritance).

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
On Tue, Oct 27, 2009 at 4:16 PM, Paolo Bonzini <[hidden email]> wrote:

> On 10/27/2009 04:40 AM, Lee Duhem wrote:
>>
>> Subclasses of nil? I didn't understand what this means,  can you explain
>> further
>> or point to some documents?
>
> While 99% of the classes are subclasses of Object, it is also possible to
> create classes that do not inherit from anything (or equivalently, whose
> subclass is nil).  In this case, the metaclass will be a subclass of Class;
> so I used in my example "Class allSubclassesDo:" to get the metaclasses
> (which provide class-side methods), and go to the classes (which provide the
> instance side) by sending #asClass.

The only classes I can found whose superclass is nil are Object, Autoload and
Kernel.AutoloadClass, which all can be accessed through subclass of Class and
#asClass, as you said. So for Symbol>>#implementors, your suggested
implementation
is enough.


>
> By the way, the reason why I didn't like #allSuperclasses is the following.

Do you mean #subclasses?

>  The #superclass and #subclasses methods return the classes that are
> "adjacent" (one level up or one level down) in the hierarchy. Prefixing
> "all" gives also the indirect superclasses/subclasses. #superclasses then
> would be a method that returns an array of direct superclasses (which would
> have a single element, since Smalltalk only has single inheritance).
>

lee


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Paolo Bonzini-2
On 10/27/2009 10:15 AM, Lee Duhem wrote:
>> >  By the way, the reason why I didn't like #allSuperclasses is the following.
> Do you mean #subclasses?

I meant #superclasses. :-)

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
On Tue, Oct 27, 2009 at 5:17 PM, Paolo Bonzini <[hidden email]> wrote:
> On 10/27/2009 10:15 AM, Lee Duhem wrote:
>>>
>>> >  By the way, the reason why I didn't like #allSuperclasses is the
>>> > following.
>>
>> Do you mean #subclasses?
>
> I meant #superclasses. :-)

oops!

lee


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
In reply to this post by Paolo Bonzini-2
On Tue, Oct 27, 2009 at 12:48 AM, Paolo Bonzini <[hidden email]> wrote:
> I'll answer to both messages in one.

New patch for enhance to kernel/Behavior.st

ChangeLog for kernel
2009-10-28  Lee Duhem  <[hidden email]>

        * kernel/Behavior.st: Add #formattedSourceStringAt:, #lookupAllSelectors:,
        #printFullHierarchy, and #printSubclasses:using:.
        * kernel/Collection.st: Add #printLines.

ChangeLog for packages/stinst/parser

2009-10-28  Lee Duhem  <[hidden email]>

        * Extensions.st: Add Behavior>>#formattedSourceStringAt: and
Symbol>>#implementors.

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

enhance_behavior.patch (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Paolo Bonzini-2
> * kernel/Collection.st: Add #printLines.

This still did not use Transcript and #display:.

> * Extensions.st: Add Behavior>>#formattedSourceStringAt: and
> Symbol>>#implementors.

This should have been (partly) in kernel/Symbol.st.

I adjusted the patch and committed it, thanks.

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
On Wed, Oct 28, 2009 at 3:49 AM, Paolo Bonzini <[hidden email]> wrote:
>>        * kernel/Collection.st: Add #printLines.
>
> This still did not use Transcript and #display:.

#printHierarchy and #printFullHierarchy in kernel/Behavior.st still
using stdout,
and there are some duplicate codes in them, the attached patch fix those
problems.

ChangeLog

2009-10-28  Lee Duhem  <[hidden email]>

        * kernel/Behavior.st: Add #hierarchyPrintBlock to remove duplicate codes
        in #printHierarchy and #printFullHierarchy.


>
>>        * Extensions.st: Add Behavior>>#formattedSourceStringAt: and
>> Symbol>>#implementors.
>
> This should have been (partly) in kernel/Symbol.st.
>
> I adjusted the patch and committed it, thanks.

Thank you.

lee

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

remove_duplicate.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Paolo Bonzini-2
On 10/28/2009 04:01 PM, Lee Duhem wrote:
> On Wed, Oct 28, 2009 at 3:49 AM, Paolo Bonzini<[hidden email]>  wrote:
>>>         * kernel/Collection.st: Add #printLines.
>>
>> This still did not use Transcript and #display:.
>
> #printHierarchy and #printFullHierarchy in kernel/Behavior.st still
> using stdout,
> and there are some duplicate codes in them, the attached patch fix those
> problems.

I opted for inlining the block in the methods.  The pluggability was not
really necessary.

Thanks,

Paolo


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Enhance to kernel/Behavior.st

Lee Duhem
On Wed, Oct 28, 2009 at 11:29 PM, Paolo Bonzini <[hidden email]> wrote:
>> #printHierarchy and #printFullHierarchy in kernel/Behavior.st still
>> using stdout,
>> and there are some duplicate codes in them, the attached patch fix those
>> problems.
>
> I opted for inlining the block in the methods.

Ok.

lee


_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk