Show a variable name in Transcript

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

Show a variable name in Transcript

DougEdmunds
Is there a way to get to the name of a temporary variable used in a method
to show it in a Transcript without putting it in a string?

someMethod
 |builder|
  builder :=  #( 1 2 3).

where I want the Transcript to show the word 'builder', not it's value
(Transcript show: builder).


Reply | Threaded
Open this post in threaded view
|

Re: Show a variable name in Transcript

Marcus Denker-4

On Mar 29, 2011, at 2:03 AM, DougEdmunds wrote:

> Is there a way to get to the name of a temporary variable used in a method
> to show it in a Transcript without putting it in a string?
>
> someMethod
> |builder|
>  builder :=  #( 1 2 3).
>


you can ask the context for all defines temps and take the first:

thisContext tempNames first


--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


Reply | Threaded
Open this post in threaded view
|

Re: Show a variable name in Transcript

DougEdmunds
I came up with some code (see below) to help figure out the design of complicated objects.
I'd like to reduce the method to only one parameter, but I don't know if it's possible to do.

An example, showing how this can be used:

UITheme class >> exampleOtherControls has a large object (16 lines!), about 2/3rds down, that starts with:
   dialog newTitle: 'Expanders' for: (

which is one of the elements of inside this object (found way at the top)
        dialog contentMorph: (dialog newRow: {

What is that object?

Change it to:
   v1 :=    dialog newTitle: 'Expanders' for: (

And add this line at the end of the method:
   MyTool var: 'v1' class: v1.

(Also must add v1 to the method's temporary variables:
        |dialog builder image emboss fuzzy v1 | )

Now run UITheme exampleOtherControls with a Transcript window open.
It shows this:

v1 - PanelMorph


-----------------

'From Pharo1.2 of 14 March 2011 [Latest update: #12341] on 29 March 2011 at 9:06:15 am'!
Object subclass: #MyTool
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Sandbox'!

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

MyTool class
        instanceVariableNames: ''!

!MyTool class methodsFor: 'as yet unclassified' stamp: 'DougEdmunds 3/29/2011 08:52'!
var: aString class: anObject
        Transcript show: aString, ' - ', anObject class asString; cr.! !
Reply | Threaded
Open this post in threaded view
|

Re: Show a variable name in Transcript

DougEdmunds
In reply to this post by Marcus Denker-4
>>thisContext tempNames first

I can't rely on the position of the variable.