Add to a collection

Richard A. O'Keefe ok at
Tue Feb 4 04:25:08 UTC 2003

Janet Abdul-Karim <jn_karim at> wrote:
	I have made an instance instead of inheritence.
	when i try to print using transcript show it display all the
	objects only the last one.
	Is there a way for me to return every single object in the
	instance using transcript show:

I am having a bit of trouble understanding that.
The Transcript is a place where you can display text.
It is not the ONLY place where you can display text.

The normal way to see what is inside an object, at least for debugging
purposes, is to use "inspect" or "explore".  For small objects, you
might "print" it.

1.  Open a workspace.

2.  Type
	#((a) (b c d) (e f))
    Do NOT type a newline.

3.  Press and hold Option on the keyboard; while the option key is down,
    press and hold the mouse button.  On the menu, you see
	Do it (d)
	Print it (p)
	Inspect it (i)
	Explore it (I)
    Select the "Print it" line and release the mouse.

    You will see that the text #(#(#a) #(#b #c #d) #(#e #f)) is added to
    your text line and highlighted.

4.  Press the Delete key to make the new text go away.

5.  Press and hold the Command key; while the Command key is down,
    press and release the 'p' key.

    You will see that the text #(#(#a) #(#b #c #d) #(#e #f)) is added to
    your text line and highlighted.

    When you have typed an expression and it is on one line, or it is
    anywhere and you have selected that text, Squeak can evaluate it
    and insert its value in text form after it.  Now you know two ways
    to do that.

6.  Press the Delete key again.

7.  Now, either by using the option-mouse menu and selecting 'Inspect it',
    of by just typing Command-i (lower-case i), use the inspector to look
    at this array.  You get a window that looks like
	[X #         Array          # O]
	|self        |                 |
	|all inst var|                 |
	|1           |                 |
        |2           |                 |
        |3           |                 |
        |                              |
        |                              |
    The bottom pane is basically a mini-workspace where you can type
    expressions and have them evaluated (do it, print it, inspect it,
    explore it).  The special thing is that in that bottom pane 'self'
    is the object you are exploring.

    The title bar tells you what kind of object you are looking at.
    The other things in the title bar are the usual controls.

    The top left pane always has 'self' (the object being inspected)
    and 'all inst var' (all instance variables).  For most objects,
    you will see the individual instance variable names next.  For
    indexed collections, you will see the indices.  Select 'self'
    and the textual representation (self printstring) of the object
    will be displayed in the top right pane.  Select '2' and the
    textual representation of the 2nd element will be displayed in the
    top right pane.  When you have something selected in the top left
    pane, option-menu lets you inspect or explore what you have

8.  When you have finished playing with that example, click on the X of
    the title bar to make the inspector go away.

9.  'Explore' is like 'inspect' but basically gives you a 'tree' view
    of the object you are exploring.  It's particularly nice for this
    example, and may suit your needs.  Again, the bottom pane is a
    mini-workspace, where the thing you have selected is bound to 'self'.

The reason why I've gone through this mini-tutorial is that if you want
to debug your code by (amongst other things) looking at the object to see
if the state is right, then there isn't much point in printing things to
the transcript.  Use 'explore it' or 'inspect it'.  This WILL let you see
"every single object in the instance", and it is a much better way than
using the transcript.

Why is it better than using the transcript?
Because you can _interact_ with the object you are looking at;
you can easily send queries to bits of it to probe its state further.

More information about the Squeak-dev mailing list