[comp.lang.smalltalk] How Do I Track Globals In Smalltalk/V?

Will@cup.portal.com (Will E Estes) (06/04/91)

I'm curious as to how I keep track of all of the globals I've
allocated in Smalltalk/V.  I've created quite a few in learning
the language, and I have no doubt saved the image before setting
many of these to nil.  Is there a way that I can get a list of
user-allocated globals that are still lying around?

Thanks,
Will Estes        Internet: Will@cup.portal.com
                  UUCP: apple!cup.portal.com!Will

CWatts@BNR.CA (Carl Watts) (06/06/91)

Will Estes asks, "Is there a way that I can get a list of user-allocated globals...?"

Yes of course, all globals are just entries in the global Dictionary called "Smalltalk".

Printing "Smalltalk keys" will give you a list of all global variables.  This list contains all classes by name as well since they are available through globals.

So if you want just the globals that aren't classes then print "(Smalltalk reject: [:each | each isBehavior]) keys".
This will give you just the globals that aren't classes (Classes are Behaviors).

Smalltalk comes with several global variables already defined.  Things like "Transcript" and "Display" and "Smalltalk" itself.

In my Smalltalk-80 2.5 image that last expression prints (Smalltalk OpcodePool SystemOrganization IOConstants SourceFiles Sensor Transcript Processor ScheduledControllers IpcConstants Display TextConstants Undeclared).  All of these are global variables that Smalltalk makes itself.

Hope this helps...

susser@Apple.COM (Joshua Susser) (06/07/91)

In <42944@cup.portal.com> Will@cup.portal.com (Will E Estes)
inquires about cleaning up global variables.

CWatts@BNR.CA (Carl Watts) supplies the expression
    (Smalltalk reject: [:each | each isBehavior]) keys
as a way to find the names of all the non-class globals.  This is
great for finding the names, but
    (Smalltalk reject: [:each | each isBehavior]) inspect
gives you an dictionary inspector on all non-class globals.  Even
better, since the associations in this dictionary are the same
ones used in Smalltalk, the values are always current.

Will, you should remember that setting a global to nil doesn't
get rid of it - it's just left with a value of nil.  To remove
an obsolete global from the Smalltalk dictionary, use this:
    Smalltalk removeKey: #GlobalName.

Joshua Susser, Object Percussionist
Apple Computer, Advanced Technology Group
inet: susser@apple.com | link: susser.j | bell: 408/974-6997

Macintosh Jr. - The power to crush the other kids.

new@ee.udel.edu (Darren New) (06/08/91)

In article <53721@apple.Apple.COM> susser@Apple.COM (Joshua Susser) writes:
>To remove >an obsolete global from the Smalltalk dictionary, use this:
>    Smalltalk removeKey: #GlobalName.

And be *really* careful that GlobalName isn't a class.  I once screwed
an image beyond recovery by doing this to a class.   Ooops.   -- Darren

-- 
--- Darren New --- Grad Student --- CIS --- Univ. of Delaware ---
----- Network Protocols, Graphics, Programming Languages, FDTs -----
+=+ Nails work better than screws, when both are driven with hammers +=+