[OT] Writing a parser for BASIC in Smalltalk/Squeak ? (<CSOTD > included)

Richard A. O'Keefe ok at atlas.otago.ac.nz
Thu Jan 10 05:05:00 UTC 2002


	Does anyone really think that it is _proper_ that
	| m n  |           
	n := 2.            
	m := 3.            
	n := m + (m := n).
	
	gives a different answer to
	| m n  |           
	n := 2.            
	m := 3.
	m := n.            
	n := m + m.
	??
	
Yes, of course.  OF COURSE!

Let's get rid of the parentheses, because they have nothing to do with
the case.  Let's invent a class with instance variables m n and methods

    initialise
        n := 2.
        m := 3.

    saveNinM
        ^m := n

    n: value
	n := value
	^self

    m
	^m

    version1
	self initialise.
	self n: m + self saveNinM.

    version1a
	self initialise.
	self n: self m + self saveNinM.

    version2
	self initialise.
	self saveNinM.
	self n: m + m.

The issue here is that we have a message with at least one argument
which modifies state that is accessed in another argument or in the
determination of the receiver.  It doesn't matter whether the state
is accessed using variables and assignments or by message sending.
It doesn't matter whether there are parentheses or not.  It's just
the plain old imperative impediment:  accessing and modifying state
in a single construct.  The "move stuff in parentheses first" kluge
will do nothing to address the difference between version1 and
version2.

The Larch annotation language, the SPARK verifier for Ada, Euclid,
and the Clean and Mercury languages pretty much fix this problem, at
the expense of introducing a "type" system in which such interference
can be detected.  Smalltalk can't really do anything about it without
ceasing to be Smalltalk.





More information about the Squeak-dev mailing list