Re: [Pharo-users] Show a variable name in Transcript
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.
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.! ! -- View this message in context: http://forum.world.st/Show-a-variable-name-in-Transcript-tp3413379p3415532.h... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
thisContext tempNames first
I can't rely on the position of the variable. -- View this message in context: http://forum.world.st/Show-a-variable-name-in-Transcript-tp3413379p3415538.h... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (2)
-
DougEdmunds -
Marcus Denker