identity and equivalence in Squeak

Richard A. O'Keefe ok at
Fri Feb 14 00:12:46 UTC 2003

shane at has asked a FAQ:
	In a Workspace window I am doing a printit ( Alt-p ) of the
	following lines:
	'aaa' == 'aaa'
	which produces:
	'aaa' == 'aaa' true

	since 'aaa' and 'aaa' are equal but not identical (not the same 
	object).  Or perhaps they are, in the compiler?
	Since they are the same literal constants.

Here's what you need to know.
Each "CompiledMethod" has a literal dictionary.
Browse (Kernel-Methods|CompiledMethod|literals|...) to see some of
the operations; most of them are primitives.

The original idea was that on a byte-coded machine (and the Xerox
machines were microcoded to run these byte codes) using a literal
dictionary meant that you could use a short offset into the dictionary
instead of a full address to a separate object.  Interlisp-D on the
later Xerox machines also used this idea, for the same reason.

When the compiler builds a CompiledMethod, it ensures that each literal
is stored *once*; after all, the whole idea is to keep offsets into the
literal dictionary short.

Last step:  when you type something in and 'do it' or 'print it'
or whatever, the compiler creates a normal CompiledMethod for it.
The method is called and then removed.

To see if this is clear, try this:

    Type   a := 'aaa'.   <doit>  This compiles a method.
    Type   b := 'aaa'.   <doit>  This compiles a DIFFERENT method.
    Type   a == b        <printit>    This compiles yet a third method.

Each method has its own literal dictionary.  The first thing executed
will have its own copy of 'aaa'.  The second thing executed will have
ITS own copy of 'aaa', but the first method has gone now, so there is
nothing to share.  The final result from executing the third method is

Now select all three lines together and <print it>.
This time, they are all compiled as part of one method,
the literals are unified, and the result is "true".

One <do it> or <print it> or <inspect it> or <explore it>
means one compiled method
means one literal dictionary
means equal literals in the text you just selected are unified,
but NOT with literals in other text you may previously have evaluated.

	a := 'aaa'
	b := 'aaa'
	a = b
	a = b false

It doesn't for me.  I get "true" just like you expected.
Are you sure you had the same number of letters in each string?

More information about the Squeak-dev mailing list