Hints and clues for a Pharo newb

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

Hints and clues for a Pharo newb

Peter Hugosson-Miller
Hi all,

So it's time for me to stop lurking and do some stuff. However, although I am an experienced Smalltalk programmer (VisualAge Smalltalk continuously since 1995), I am a complete newb when it comes to Pharo and Squeak, it's hard to find my way around, and it's going to take me some time to get up to speed.

I'm working on a small improvement to the testing framework, using ideas that I have found to be very useful in my daily job over the past 15 years. Note that I am doing this from scratch, so that I don't accidentally steal anything that I've done in my work, but I know how it all works in VisualAge, so I feel sure that I'll eventually be able to find the corresponding classes and methods in Pharo.

What I would like are a few hints, clues and nudges in the right direction for scenarios and questions that I will describe in this thread. What I *don't* want are full-blown solutions, because then I won't learn anything. I hope that some kind souls will be able to give me a little help in the beginning that will eventually bring me up to speed and let me be productive.

So to start with, one scenario and one question:

1) I want to find or write a method on Process that will print a stack trace onto a supplied Stream. Ideally I'd like to be able to decide the start and stop depth of the trace, so for example if I know that the top 4 stack frames will always be uninteresting, I would want to be able to write something like this:

      Processor activeProcess printStackFrom: 5 to: 15 on: aStream.

2) What *exactly* is "thisContext"? It appears to be a reserved word in Pharo, just like the familiar "self", "super", "true", "false", "nil" that are always reserved in Smalltalk. I'd also like to get an idea of what it's good for, and if anyone can describe it in terms of something that is in VisualAge, that would be nice too :-)

BTW, if this is not the appropriate place for a thread like this, then please tell me where I should put it (politely, of course :-p)

--
Cheers,
Peter

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Schwab,Wilhelm K
Peter,
 
Welcome aboard!  IMHO, this is a fine place for the discussion that will hopefully result.
 
 
as they allow searching of the lists.
 
Have you downloaded Pharo by Example?  You might also want to get a print copy from Lulu. 
 
Learning your way around the Monticello GUI will be important.  It has some quirks that I discovered the hard way; they should live in the pharo-dev archive above.  In short, class categories/package names are case-sensitive, but you might have to remove the working copy of a package that somehow (your fault or not) picked up an undesired capitalization, e.g. ThisORThat vs. ThisOrThat before you can create the one you want.  Method categoris (ab)used to package methods (*packageNameGoesHere) are apparently not case-sensitive.
 
That's about all the damage I have time to do at the moment.  What brings you to Pharo?  We're glad to have you, but your thoughts on the system, what it does well, and what needs to improve could be helpful.
 
Bill
 
 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Peter Hugosson-Miller
Sent: Wednesday, April 21, 2010 11:09 AM
To: [hidden email]
Subject: [Pharo-project] Hints and clues for a Pharo newb

Hi all,

So it's time for me to stop lurking and do some stuff. However, although I am an experienced Smalltalk programmer (VisualAge Smalltalk continuously since 1995), I am a complete newb when it comes to Pharo and Squeak, it's hard to find my way around, and it's going to take me some time to get up to speed.

I'm working on a small improvement to the testing framework, using ideas that I have found to be very useful in my daily job over the past 15 years. Note that I am doing this from scratch, so that I don't accidentally steal anything that I've done in my work, but I know how it all works in VisualAge, so I feel sure that I'll eventually be able to find the corresponding classes and methods in Pharo.

What I would like are a few hints, clues and nudges in the right direction for scenarios and questions that I will describe in this thread. What I *don't* want are full-blown solutions, because then I won't learn anything. I hope that some kind souls will be able to give me a little help in the beginning that will eventually bring me up to speed and let me be productive.

So to start with, one scenario and one question:

1) I want to find or write a method on Process that will print a stack trace onto a supplied Stream. Ideally I'd like to be able to decide the start and stop depth of the trace, so for example if I know that the top 4 stack frames will always be uninteresting, I would want to be able to write something like this:

      Processor activeProcess printStackFrom: 5 to: 15 on: aStream.

2) What *exactly* is "thisContext"? It appears to be a reserved word in Pharo, just like the familiar "self", "super", "true", "false", "nil" that are always reserved in Smalltalk. I'd also like to get an idea of what it's good for, and if anyone can describe it in terms of something that is in VisualAge, that would be nice too :-)

BTW, if this is not the appropriate place for a thread like this, then please tell me where I should put it (politely, of course :-p)

--
Cheers,
Peter

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Michael Roberts-2
In reply to this post by Peter Hugosson-Miller
thisContext reifies the activation contexts (if that is the exact way
to describe it?). I don't believe you have it in VA. So you can just
walk it. If you look for some of the fatal error handling logic you
can see how the debug log is written out on crash containing the
stack. Cheers mike

On Wednesday, April 21, 2010, Peter Hugosson-Miller
<[hidden email]> wrote:

> Hi all,
> So it's time for me to stop lurking and do some stuff. However, although I am an experienced Smalltalk programmer (VisualAge Smalltalk continuously since 1995), I am a complete newb when it comes to Pharo and Squeak, it's hard to find my way around, and it's going to take me some time to get up to speed.
>
>
>
>
>
> I'm working on a small improvement to the testing framework, using ideas that I have found to be very useful in my daily job over the past 15 years. Note that I am doing this from scratch, so that I don't accidentally steal anything that I've done in my work, but I know how it all works in VisualAge, so I feel sure that I'll eventually be able to find the corresponding classes and methods in Pharo.
>
>
>
>
>
> What I would like are a few hints, clues and nudges in the right direction for scenarios and questions that I will describe in this thread. What I *don't* want are full-blown solutions, because then I won't learn anything. I hope that some kind souls will be able to give me a little help in the beginning that will eventually bring me up to speed and let me be productive.
>
>
>
>
> So to start with, one scenario and one question:
> 1) I want to find or write a method on Process that will print a stack trace onto a supplied Stream. Ideally I'd like to be able to decide the start and stop depth of the trace, so for example if I know that the top 4 stack frames will always be uninteresting, I would want to be able to write something like this:
>
>
>       Processor activeProcess printStackFrom: 5 to: 15 on: aStream.
> 2) What *exactly* is "thisContext"? It appears to be a reserved word in Pharo, just like the familiar "self", "super", "true", "false", "nil" that are always reserved in Smalltalk. I'd also like to get an idea of what it's good for, and if anyone can describe it in terms of something that is in VisualAge, that would be nice too :-)
>
>
> BTW, if this is not the appropriate place for a thread like this, then please tell me where I should put it (politely, of course :-p)
> --
> Cheers,
> Peter
>
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Henrik Sperre Johansen
In reply to this post by Peter Hugosson-Miller

On Apr 21, 2010, at 6:09 02PM, Peter Hugosson-Miller wrote:

> Hi all,
>
> So it's time for me to stop lurking and do some stuff. However, although I am an experienced Smalltalk programmer (VisualAge Smalltalk continuously since 1995), I am a complete newb when it comes to Pharo and Squeak, it's hard to find my way around, and it's going to take me some time to get up to speed.
>
> I'm working on a small improvement to the testing framework, using ideas that I have found to be very useful in my daily job over the past 15 years. Note that I am doing this from scratch, so that I don't accidentally steal anything that I've done in my work, but I know how it all works in VisualAge, so I feel sure that I'll eventually be able to find the corresponding classes and methods in Pharo.
>
> What I would like are a few hints, clues and nudges in the right direction for scenarios and questions that I will describe in this thread. What I *don't* want are full-blown solutions, because then I won't learn anything. I hope that some kind souls will be able to give me a little help in the beginning that will eventually bring me up to speed and let me be productive.
>
> So to start with, one scenario and one question:
>
> 1) I want to find or write a method on Process that will print a stack trace onto a supplied Stream. Ideally I'd like to be able to decide the start and stop depth of the trace, so for example if I know that the top 4 stack frames will always be uninteresting, I would want to be able to write something like this:
>
>       Processor activeProcess printStackFrom: 5 to: 15 on: aStream.
>
> 2) What *exactly* is "thisContext"? It appears to be a reserved word in Pharo, just like the familiar "self", "super", "true", "false", "nil" that are always reserved in Smalltalk. I'd also like to get an idea of what it's good for, and if anyone can describe it in terms of something that is in VisualAge, that would be nice too :-)
>
> BTW, if this is not the appropriate place for a thread like this, then please tell me where I should put it (politely, of course :-p)
>
> --
> Cheers,
> Peter
> ________________

I haven't used VA, but for instance, 2) allows you to write 1) as:
Process >> printStackFrom: start to: end on: aStream
        ((thisContext stackOfSize: end) removeFirst: start; yourself  )
                do: [:each | each printOn: aStream. aStream nextPut: Character cr].

;)

Cheers,
Henry
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

hernanmd
In reply to this post by Peter Hugosson-Miller
2010/4/21 Peter Hugosson-Miller <[hidden email]>:

> Hi all,
> So it's time for me to stop lurking and do some stuff. However, although I
> am an experienced Smalltalk programmer (VisualAge Smalltalk continuously
> since 1995), I am a complete newb when it comes to Pharo and Squeak, it's
> hard to find my way around, and it's going to take me some time to get up to
> speed.
> I'm working on a small improvement to the testing framework, using ideas
> that I have found to be very useful in my daily job over the past 15 years.
> Note that I am doing this from scratch, so that I don't accidentally steal
> anything that I've done in my work, but I know how it all works in
> VisualAge, so I feel sure that I'll eventually be able to find the
> corresponding classes and methods in Pharo.
> What I would like are a few hints, clues and nudges in the right direction
> for scenarios and questions that I will describe in this thread. What I
> *don't* want are full-blown solutions, because then I won't learn anything.
> I hope that some kind souls will be able to give me a little help in the
> beginning that will eventually bring me up to speed and let me be
> productive.
> So to start with, one scenario and one question:
> 1) I want to find or write a method on Process that will print a stack trace
> onto a supplied Stream. Ideally I'd like to be able to decide the start and
> stop depth of the trace, so for example if I know that the top 4 stack
> frames will always be uninteresting, I would want to be able to write
> something like this:
>       Processor activeProcess printStackFrom: 5 to: 15 on: aStream.
> 2) What *exactly* is "thisContext"? It appears to be a reserved word in
> Pharo, just like the familiar "self", "super", "true", "false", "nil" that
> are always reserved in Smalltalk. I'd also like to get an idea of what it's
> good for, and if anyone can describe it in terms of something that is in
> VisualAge, that would be nice too :-)

thisContext is a special object for representing an activation in a
stack frame in a stack-based VM. There are two kinds of contexts:
Method Contexts and Block Contexts.

Context creation is optimized in the VM in most Smalltalks, so it's
only really created as an object in the environment (reified) when
it's specifically needed through "thisContext". You may emulate its
usage in VisualAge writing something like

[] homeContext

and in a method it would be

>>thisContext
      "returns the context of the sender"
      ^[] homeContext sender

although with some limitations.
There are several applications related with computational reflection
(Reflective Programming, Meta-Programming, MOP, etc) which makes use
of the current context.

Cheers,

Hernán

> BTW, if this is not the appropriate place for a thread like this, then
> please tell me where I should put it (politely, of course :-p)
> --
> Cheers,
> Peter
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Lukas Renggli
> thisContext is a special object for representing an activation in a
> stack frame in a stack-based VM.

Actually "thisContext" represents *the current* activation/stack-frame.

    foo: anObject
         ^ thisContext at: 1

is the same as

    foo: anObject
         ^ anObject

> There are two kinds of contexts:
> Method Contexts and Block Contexts.

Actually in Pharo images there are only instances of MethodContext.
Though you can ask the context if it comes from a block by sending the
message #isExecutingBlock.

> Context creation is optimized in the VM in most Smalltalks, so it's
> only really created as an object in the environment (reified) when
> it's specifically needed through "thisContext".

In Pharo contexts are not reified like that. Stack-frames are actual
objects at all times. However, for speed reasons, their creation and
garbage-collection is optimized by the VM. Stack frames get
automatically recycled if nobody refers to them.

> There are several applications related with computational reflection
> (Reflective Programming, Meta-Programming, MOP, etc) which makes use
> of the current context.

Also: exception handling, generators, continuations, co-routines, ...

For another fun use of "thisContext" check this Stack-Overflow question:

http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r

Lukas

--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Stéphane Ducasse

On Apr 21, 2010, at 7:11 PM, Lukas Renggli wrote:

>> thisContext is a special object for representing an activation in a
>> stack frame in a stack-based VM.
>
> Actually "thisContext" represents *the current* activation/stack-frame.
>
>    foo: anObject
>         ^ thisContext at: 1
>
> is the same as
>
>    foo: anObject
>         ^ anObject
>
>> There are two kinds of contexts:
>> Method Contexts and Block Contexts.
>
> Actually in Pharo images there are only instances of MethodContext.
> Though you can ask the context if it comes from a block by sending the
> message #isExecutingBlock.
>
>> Context creation is optimized in the VM in most Smalltalks, so it's
>> only really created as an object in the environment (reified) when
>> it's specifically needed through "thisContext".
>
> In Pharo contexts are not reified like that. Stack-frames are actual
> objects at all times. However, for speed reasons, their creation and
> garbage-collection is optimized by the VM. Stack frames get
> automatically recycled if nobody refers to them.

Hernan you used VW I see :)
In Pharo this is like lukas said, we got this discussion with him for some seaside papers :)

>
>> There are several applications related with computational reflection
>> (Reflective Programming, Meta-Programming, MOP, etc) which makes use
>> of the current context.
>
> Also: exception handling, generators, continuations, co-routines, ...
>
> For another fun use of "thisContext" check this Stack-Overflow question:
>
> http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r
>
> Lukas
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Stéphane Ducasse
In reply to this post by Peter Hugosson-Miller

On Apr 21, 2010, at 6:09 PM, Peter Hugosson-Miller wrote:

> Hi all,
>
> So it's time for me to stop lurking and do some stuff. However, although I am an experienced Smalltalk programmer (VisualAge Smalltalk continuously since 1995), I am a complete newb when it comes to Pharo and Squeak, it's hard to find my way around, and it's going to take me some time to get up to speed.

I'm happy to hear that.



_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

hernanmd
In reply to this post by Lukas Renggli
2010/4/21 Lukas Renggli <[hidden email]>:

>> thisContext is a special object for representing an activation in a
>> stack frame in a stack-based VM.
>
> Actually "thisContext" represents *the current* activation/stack-frame.
>
>    foo: anObject
>         ^ thisContext at: 1
>
> is the same as
>
>    foo: anObject
>         ^ anObject
>

Of course, "this" refers to "the current" in common language usage.

>> There are two kinds of contexts:
>> Method Contexts and Block Contexts.
>
> Actually in Pharo images there are only instances of MethodContext.
> Though you can ask the context if it comes from a block by sending the
> message #isExecutingBlock.
>

Actually in Pharo there is a BlockContext class, which is not
instantiated anymore after the introduction of the closure compiler?
In other Smalltalks aBlockContext is the resulting context of a block
activation during its evaluation and is activated by sending
#value,.this fills thisContext with the execution information inside
the block.

In Squeak (or the old compiler) block contexts were created using
#blockCopy:, now I see #closureNumCopied:numArgs:. Does this means
BlockContext could be completely removed and replaced with
MethodContext semantics? I've removed the BlockContext class and used
Pharo a little bit with no problems, maybe some Decompiler issues in
the Debugger...

Now, test yourself before evaluating :) what should be the result of
this expression?

[: arg | arg perform: #isExecutingBlock ] value: thisContext

Can somebody justify the result?

>> Context creation is optimized in the VM in most Smalltalks, so it's
>> only really created as an object in the environment (reified) when
>> it's specifically needed through "thisContext".
>
> In Pharo contexts are not reified like that. Stack-frames are actual
> objects at all times. However, for speed reasons, their creation and
> garbage-collection is optimized by the VM. Stack frames get
> automatically recycled if nobody refers to them.
>

I think is what I said :)

>> There are several applications related with computational reflection
>> (Reflective Programming, Meta-Programming, MOP, etc) which makes use
>> of the current context.
>
> Also: exception handling, generators, continuations, co-routines, ...
>
> For another fun use of "thisContext" check this Stack-Overflow question:
>
> http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r
>
> Lukas
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Hints and clues for a Pharo newb

Eliot Miranda-2


On Wed, Apr 21, 2010 at 4:34 PM, Hernán Morales Durand <[hidden email]> wrote:
2010/4/21 Lukas Renggli <[hidden email]>:
>> thisContext is a special object for representing an activation in a
>> stack frame in a stack-based VM.
>
> Actually "thisContext" represents *the current* activation/stack-frame.
>
>    foo: anObject
>         ^ thisContext at: 1
>
> is the same as
>
>    foo: anObject
>         ^ anObject
>

Of course, "this" refers to "the current" in common language usage.

>> There are two kinds of contexts:
>> Method Contexts and Block Contexts.
>
> Actually in Pharo images there are only instances of MethodContext.
> Though you can ask the context if it comes from a block by sending the
> message #isExecutingBlock.
>

Actually in Pharo there is a BlockContext class, which is not
instantiated anymore after the introduction of the closure compiler?

Right.
 
In other Smalltalks aBlockContext is the resulting context of a block
activation during its evaluation and is activated by sending
#value,.this fills thisContext with the execution information inside
the block.

and it is now with the closure compiler.  Or rather a new context is created when a BlockClosure is sent the value message.  The context is an instance of methodContext though.
 
In Squeak (or the old compiler) block contexts were created using
#blockCopy:, now I see #closureNumCopied:numArgs:. Does this means
BlockContext could be completely removed and replaced with
MethodContext semantics? I've removed the BlockContext class and used
Pharo a little bit with no problems, maybe some Decompiler issues in
the Debugger...

Yes.  But MethodContext behaves differently depending on whether its closureOrNil inst var is nil (a normal method) or a BlockClosure (an activation of a block).  If nil, ^-returns return to the context's sender.  If not nil ^-returns return from the home context, found by following the outerContext chain through the closureOrNil inst var.  So we no longer need BlockContext.

This also means we only need one context class, and some time I'd like to merge the two ContextPart and MethodContext classes into a single Context class.  Possibly the name should be ExecutionContext or MethodOrBlockContext or?  Suggestions?


Now, test yourself before evaluating :) what should be the result of
this expression?

[: arg | arg perform: #isExecutingBlock ] value: thisContext

It depends on whether the expression is executed at method level or at block level.  As a test this should be:

testIsExecutingBlock
    self assert: ([: arg | arg perform: #isExecutingBlock ] value: thisContext) == false.
    [self assert: ([: arg | arg perform: #isExecutingBlock ] value: thisContext) == true] value

Can somebody justify the result?

isExecutingBlock answers if the receiver is executing a block or not. It does not answer whether the context in which isExecutingBlock is sent is executing a block or not.  Remember that

    [:arg| arg == thisContext] value: thisContext

is false.  thisContext is rebound within every actual method or block scope.

HTH

Eliot


>> Context creation is optimized in the VM in most Smalltalks, so it's
>> only really created as an object in the environment (reified) when
>> it's specifically needed through "thisContext".
>
> In Pharo contexts are not reified like that. Stack-frames are actual
> objects at all times. However, for speed reasons, their creation and
> garbage-collection is optimized by the VM. Stack frames get
> automatically recycled if nobody refers to them.
>

I think is what I said :)

But its not a property of Pharo.  It is a property of the VM.  In Cog contexts are not actual objects all the time, only when needed.  And Cog runs Pharo images just as it runs Squeak images.  So it would be incorrect to say "in Pharo" and better to say "in the standard Squeak VM".


>> There are several applications related with computational reflection
>> (Reflective Programming, Meta-Programming, MOP, etc) which makes use
>> of the current context.
>
> Also: exception handling, generators, continuations, co-routines, ...
>
> For another fun use of "thisContext" check this Stack-Overflow question:
>
> http://stackoverflow.com/questions/2500483/is-there-a-way-in-a-message-only-language-to-define-a-whiletrue-message-without-r
>
> Lukas
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project