About method comment evaluation

Ned Konz ned at bike-nomad.com
Sun Dec 1 15:50:16 UTC 2002


On Sunday 01 December 2002 02:29 am, Stephane Ducasse wrote:

> I would like to find the person who did the following:
>
> you can select a comment and evaluate it. In VW and Squeak now you
> can write "self ..." in the comment and in such a case it refers to
> the ***class***
>
> I was so used to this browser trick that I never realized how it
> could be dangerous for newbie.
> Imagine self in comment and in the code represent different object:
> instance and its class.

Which object instance? You don't have a specific one if you're working 
with code.

> So I would like to know if we could change or introduce another
> browser trick class
> selfClass
>
>
> this way we could have
>
> 	"selfClass new xxx"
>
> and not
>
> 	"self new xxx"

Do you mean you want to get rid of "self" in that context?

> Is the author of the previous trick around?

Looks like it's Dan Ingalls, from early code:

di 5/10/1998 21:38 ‚ do-its ‚ 4 implementors ‚ in no change set ‚ 

ParagraphEditor>>doIt
	"Set the context to include pool vars of the model.  Then evaluate."
	^ self evaluateSelection.

Though on ParagraphEditor>>evaluateSelection we see Bob Arning's 
initials:

RAA 2/5/2001 10:43 ‚ do-its ‚ 1 implementor ‚ in no change set ‚ 

Looking at this, we see that it's possible for the browser model 
itself to specify the context for the evaluation:

Browser>>doItReceiver
	"This class's classPool has been jimmied to be the classPool of the 
class 
	being browsed. A doIt in the code pane will let the user see the 
value of 
	the class variables."

	^ self selectedClass ifNil: [FakeClassPool new]

So the attached is a simple hack that does just this. Maybe I'm 
missing something important here.

This is a browser in which doIt, printIt, etc. contexts are made safe 
with respect to "self".
Evaluating "selfClass" will give you the class being browsed.

try:
SafetyBrowser fullOnClass: SafetyBrowser

Note that the class pools and shared pools are NOT copies, so changes 
to them can affect the original class. This is due to the use of 
FakeClassPool all over the place (though FakeClassPool could be 
changed to use copies, of course, or could be made like 
SafeFakeClassPool is here to make these changes throughout the 
environment).

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SafetyBrowser-nk.1.cs
Type: text/x-squeak-changeset
Size: 1417 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20021201/f62b4b81/SafetyBrowser-nk.1.bin


More information about the Squeak-dev mailing list