[comp.lang.smalltalk] GNU Smalltalk-1.1 problems

peters@sirius.UVic.CA (Doug Peters) (06/20/91)

Is there a trick to this?

Granted, I am almost a novice at Smalltalk, but I thought that I was
asking GNU Smalltalk-1.1 to do some pretty basic things...

For example, I have a Complex class (I chose to make this a subclass
of Number because I wanted "isKindOf: Number" to still work)
So I have a file called "Complex.st", which looks like:
"------------------------------------------------>8"
Number variableSubclass: #Complex
        instanceVariableNames: 're im '
        classVariableNames: ''
        poolDictionaries: ''
        category: ''!

!Complex methodsFor:'accessing'!

re: aNumber im: anotherNumber
  re := aNumber.
  im := anotherNumber! !

!Complex class methodsFor: 'instance creation'!

re:aNumber im:anotherNumber "<- this is line 15"
  | a |
  a := super new.
  a re:aNumber im:anotherNumber. "<- this is line 18"
  ^a! !
"------------------------------------------------>8"
(it used to be a lot longer, but this gets the point across)
anyway,

st> FileStream fileIn:'Complex.st' !
produces:

"Complex.st", line 15: parse error
"Complex.st", line 15: Invalid message pattern
"Complex.st", line 18: Error in expression
"Complex.st", line 18: parse error
"Complex.st", line 18: Invalid message pattern
"Complex.st", line 19: Error in expression

The same errors occur even if I change the class method to real:imag:
(so much for polymorphism)... 
any hints (re:strategy _or_ implementation :-)?

Another example: I want a Matrix class, so I

st> ArrayedCollection variableSubclass: #Matrix
st> 	instanceVariableNames: 'nrow ncol '
st> 	classVariableNames: ''
st> 	poolDictionaries: ''
st>	category: ''!

and I get:

ArrayedCollection error: cannot create a variable subclass from a
non-pointer variable parent class

I am quite sure that that was the invocation in PP-ST80,
and I am not even sure what the error message is telling me...

again, any hints?

Thanks in advance
  Doug Peters      (peters@sirius.uvic.ca)

hsu_wh@jhunix.HCF.JHU.EDU (William H Hsu) (06/21/91)

	I am also new to SmallTalk -- I would like to know whether there has
been any work done in implementing data compression (or at least interfaces
to C code for compression) using SmallTalk.  I am using GNU 1.1.
	Also, what (when) is the most recent release of Macintosh SmallTalk?
	Finally, are there currently any tutorials in SmallTalk-80
programming other than the Krasner ("Green") and Goldberg/Robson ("Purple")
books, either in print, journal, or online (FTP'able) form?  I'd really
appreciate if anyone would mail me a list of sources.  Thanks.

William H. Hsu
hsu@cs.jhu.edu

sbb@laplace.eng.sun.com (Steve Byrne) (06/21/91)

In article <PETERS.91Jun19104522@yates.UVic.CA> peters@sirius.UVic.CA (Doug  Peters) writes:


   From: peters@sirius.UVic.CA (Doug  Peters)
   Newsgroups: comp.lang.smalltalk
   Date: 19 Jun 91 17:44:19 GMT

   Granted, I am almost a novice at Smalltalk, but I thought that I was
   asking GNU Smalltalk-1.1 to do some pretty basic things...

   For example, I have a Complex class (I chose to make this a subclass
   of Number because I wanted "isKindOf: Number" to still work)
   So I have a file called "Complex.st", which looks like:
   "------------------------------------------------>8"
   Number variableSubclass: #Complex
	   instanceVariableNames: 're im '
	   classVariableNames: ''
	   poolDictionaries: ''
	   category: ''!

   !Complex methodsFor:'accessing'!

   re: aNumber im: anotherNumber
     re := aNumber.
     im := anotherNumber! !

   !Complex class methodsFor: 'instance creation'!

   re:aNumber im:anotherNumber "<- this is line 15"
     | a |
     a := super new.
     a re:aNumber im:anotherNumber. "<- this is line 18"
     ^a! !
   "------------------------------------------------>8"

   st> FileStream fileIn:'Complex.st' !
   produces:

   "Complex.st", line 15: parse error
   "Complex.st", line 15: Invalid message pattern
   "Complex.st", line 18: Error in expression
   "Complex.st", line 18: parse error
   "Complex.st", line 18: Invalid message pattern
   "Complex.st", line 19: Error in expression

The problem here is that GNU Smalltalk's lexer is greedy: it really thinks
that if it's seen "foo:bar" that it's processing a keyword symbol and is
expecting to see a colon following it.  Unfortunately, there is no
colon at the end, so it yells.  You can argue with whether this is the
right behavior or not; I think the Blue Book indicated that this was the way
things were, but it could probably be a little smarter in the future (like,
say the 2.0 timeframe when the compiler code is written in Smalltalk). 

In this case, if you just put a space between the keyword and the argument
name, you should win.

   st> ArrayedCollection variableSubclass: #Matrix
   st> 	instanceVariableNames: 'nrow ncol '
   st> 	classVariableNames: ''
   st> 	poolDictionaries: ''
   st>	category: ''!

   and I get:

   ArrayedCollection error: cannot create a variable subclass from a
   non-pointer variable parent class

I've changed things related to this in 1.2.  The basic problem is that
isWords and isBytes are lying: isWords should only return true if it's not
pointers AND is has the proper bit set.  isBytes should not be a pointer
and should not be words.  These two methods are used by variableSubclass
for error detection, although the way they are implemented now, they're
more involved with error creation :-)

Change the definitions in Behavior.st of isWords and isBytes thus:

    isBytes
	^self isPointers not & self isWords not
    !

    isWords
	^self isPointers not & ((self instanceSpec bitAt: 29) ~= 0)
    !

And you'll win.

Steve