Eliminating assignments and variable syntax (accessors)

agree at carltonfields.com agree at carltonfields.com
Mon Aug 2 18:42:45 UTC 1999

Perhaps I'm stating the obvious, but isn't there a potential problem here?  In particular, let us consider:

	instvar := <expression>

Presently, this unambiguously means munge instvar and replace it with the answer to the expression.  That's fine so far as it goes, and we've discussed at length the upside/downside of using it in raw form.

But sometimes we MUST be able to articulate precisely this function.  For example, in the accessor:



and the setter:

	instvar: anExpression

		^instvar := anExpression

Clearly, if every reference to instvar is treated as a call to method instvar, and every "assignment" to instvar is treated as a recusive call to method instvar:, neither of the definitions above will serve, resulting in infinite recursive regress.  (Now that's inefficient!)

Of course, we could simply check before doing the substitution that has been proposed here, and use the ordinary Smalltalk semantics for "instvar" when referenced within a message of the form "instvar" or "instvar:"  This seems to me cumbersome and ugly, because it means that the expression

	x := y

depends entirely on its context.  Further, should you adopt this solution, you no longer have a way to make a recursive call within a setter or getter without the ugly expedient of a call to a second service method to do the recursion (though I can't at all imagine an exemple where I would want to do so).

Am I missing the point, or is this "solution" harder than it seems at first blush?

More information about the Squeak-dev mailing list