From: psti@hki.wsoy.FI (Patrick Stickler)
Subject: Problem creating subclass for FileStream
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 21 Aug 1992 13:06:39 GMT

I'm trying to create a subclass of FileStream which defines several methods
for processing the particular file type (i.e. the file object is aware of
its own internal structure and how to extract particular elements and iterate
over those elements). Unfortunately, the inheritance from FileStream doesn't
seem to be working. The class definition code is as follows:

    FileStream variableSubclass: #WSOYDictionaryFileStream
        instanceVariableNames: 'tag'
        classVariableNames: ''
        poolDictionaries: ''
        category: nil!
    
    WSOYDictionaryFileStream comment:
    'I represent a class of file streams containing dictionaries which
    are encoded in ''WSOY House Standard SGML''. I provide various methods
    for accessing and enumerating over entire entries.' !
    
    !WSOYDictionaryFileStream class methodsFor: 'instance creation'!
    
    new
        ^super new init
    
    !!
    
    !WSOYDictionaryFileStream methodsFor: 'initializing'!
    
    init
        self entryTag: 'ENTRY'.
        ^self
    
    !
    
    entryTag: aString
        tag _ aString
    
    !!
    
    "lots of code and other methods deleted..."
    
    
The problem occurs when I create a new instance of WSOYDictionaryFileStream,
where the new instance does not understand the method init, i.e.:

    st> FileStream fileIn: 'WSOYDictionaryFileStream.st'!
    st> | foo | foo _ WSOYDictionaryFileStream new!
    WSOYDictionaryFileStream did not understand selector 'init'

    WSOYDictionaryFileStream class>>#new
    UndefinedObject>>#executeStatements
    UndefinedObject>>nil
    st> 

For some reason, the new method for WSOYDictonaryFileStream is
creating an instance of the *metaclass*, rather than an object
instance of the class itself, i.e. I removed the call to the init
method so that the new method would work, and the results clearly
show that an instance of the metaclass and not an instance of
the class is being returned (which is why it does not understand
the init method):

    st> WSOYDictionaryFileStream new species printNl!
    WSOYDictionaryFileStream class
    st> 

Why is an instance of the metaclass and not of the class being returned
by super new? What am I doing wrong (or what is smalltalk doing wrong ;-)

Also, shouldn't the new subclass WSOYDictionaryFileStream inherit the 
class instance creation methods from FileStream such that those same
instance creation methods if sent to WSOYDictionaryFileStream will create
an instance of WSOYDictionaryFileStream? The FileStream class method
open:mode: is understood by WSOYDictionaryFileStream but returns an instance
of FileStream *not* WSOYDictionaryFileStream:

    st> (WSOYDictionaryFileStream open: 'rasu-a.dat' mode: 'r')
    st> species printNl!
    FileStream
    st> 

Shouldn't the creation method create an instance of the reciever
class? Is it correct that the method open:mode: defined in FileStream
sends the new message to FileStream rather than self?, i.e.:

    open: fileName mode: fileMode
        | file |
        file _ FileStream new.
        file fileOp: 0 with: fileName with: fileMode.
        ^file

Shouldn't the method be something like the following?:

    open: fileName mode: fileMode
        | file |
        file _ self new.
               ^^^^
        file fileOp: 0 with: fileName with: fileMode.
        ^file


Any suggestions, solutions, or ideas would be greatly appreciated.
In case it matters, I'm using version 1.1.1 on an IBM RS/6000 running
AIX 3.2 with 64MB RAM.


//////////////////////////////////////////////////////////////////////////
  Patrick M. Stickler (psti@wsoy.fi)      The comments contained herein
  WSOY, Information Systems Division      do not necessarily reflect the
  Bulevardi 12, 00121 Helsinki Finland    official views of my employer.
//////////////////////////////////////////////////////////////////////////



Newsgroups: gnu.emacs.bug