[comp.lang.smalltalk] Please Explain Difference Between $A And 'A'

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

In learning Smalltalk, I am finding cases where semantically identical, 
but logically distinct, object types do not get treated the same.  One
case is point is the difference between single character objects (e.g.,
$C) and single character string arrays (e.g., 'C').

The following code, for example, blows up in Smalltalk V/Windows:

	|c|
	c: = '3'.
	c < $3.

Ideally, you would like the last expression to return false.  But instead
string array objects don't seem to like dealing with character objects and
the last expression blows up.  Being new to Smalltalk, I would like to
understand this phenomenon better.  Specifically:

1) Is this example evidence of bad implementation on Digitalk's part,
or is this considered good Smalltalk style?  In other words, should
it be a goal in writing Smalltalk methods to make semantically identical
things work together.  Or does good Smalltalk live by the "separate,
but equal" rule?

2) Are there many other instances of this sort of thing in Smalltalk?
Maybe someone could review the most common gotchas....

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

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

In article <40923@cup.portal.com> Will@cup.portal.com (Will E Estes) writes:
>In learning Smalltalk, I am finding cases where semantically identical, 
>but logically distinct, object types do not get treated the same.  One
>case is point is the difference between single character objects (e.g.,
>$C) and single character string arrays (e.g., 'C').

'C' and $C are clearly not "semantically identical" or you wouldn't be
having this problem, eh? :-)

The problem is the 'C' is a string which happens to be one character long
and $C is a single character.  (The distinction is there in most lower-
level languages, too.)  Would you want '3' = 3 to work?  How 
about '18.2' = 18.2 or '3/4' = 0.75 ?  

>1) Is this example evidence of bad implementation on Digitalk's part,
>or is this considered good Smalltalk style?  In other words, should
>it be a goal in writing Smalltalk methods to make semantically identical
>things work together.  Or does good Smalltalk live by the "separate,
>but equal" rule?

See above.  Where do you stop?  It's good Smalltalk.  That's why it is
possible to redefine equality operators on a class-by-class basis.

Try ('C' at: 1) < $C or something like that. Maybe $C asString < 'C'.
Depends on exactly what conversions your particular image includes.

>2) Are there many other instances of this sort of thing in Smalltalk?
>Maybe someone could review the most common gotchas....

Lots of them.  You'll find them.
                       -- Darren
-- 
--- Darren New --- Grad Student --- CIS --- Univ. of Delaware ---
----- Network Protocols, Graphics, Programming Languages, FDTs -----
  +=+=+ My time is very valuable, but unfortunately only to me +=+=+
+ When you drive screws with a hammer, screwdrivers are unrecognisable +

scrl@otter.hpl.hp.com (Simon Lewis) (04/08/91)

I think I would argue that $A and 'A' are NOT semantically identical objects
(although let's not start a debate about what `semantics' means).  The
point is that they are distinct.  One is an `atom', the other is a collection
containing an `atom'.  Thus it doesn't make much sense to compare them in
the way you are trying to do.

Simon Lewis,
HP Labs, Bristol, UK.