[patch] Enhance to kernel/Behavior.st

View: New views
12 Messages — Rating Filter:   Alert me  

[patch] Enhance to kernel/Behavior.st

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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  <lee.duhem@...>

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


_______________________________________________
help-smalltalk mailing list
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Behavior.patch (8K) Download Attachment

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

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 27, 2009 at 12:48 AM, Paolo Bonzini <bonzini@...> 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 27, 2009 at 4:16 PM, Paolo Bonzini <bonzini@...> 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 27, 2009 at 5:17 PM, Paolo Bonzini <bonzini@...> 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 27, 2009 at 12:48 AM, Paolo Bonzini <bonzini@...> 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  <lee.duhem@...>

        * 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  <lee.duhem@...>

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


_______________________________________________
help-smalltalk mailing list
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

enhance_behavior.patch (6K) Download Attachment

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

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> * 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Oct 28, 2009 at 3:49 AM, Paolo Bonzini <bonzini@...> 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  <lee.duhem@...>

        * 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

remove_duplicate.patch (2K) Download Attachment

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

by Paolo Bonzini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 10/28/2009 04:01 PM, Lee Duhem wrote:
> On Wed, Oct 28, 2009 at 3:49 AM, Paolo Bonzini<bonzini@...>  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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk

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

by Lee Duhem :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Oct 28, 2009 at 11:29 PM, Paolo Bonzini <bonzini@...> 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
help-smalltalk@...
http://lists.gnu.org/mailman/listinfo/help-smalltalk