[squeak-dev] isSelfEvaluating
Bert Freudenberg
bert at freudenbergs.de
Sat Oct 31 14:35:14 UTC 2009
On 31.10.2009, at 09:50, Stéphane Rollandin wrote:
>>> If the meaning of #isLiteral is to indicate that what is printed
>>> can be read back (i.e. will be correctly parsed) then I think it
>>> is a very useful message that we should keep.
>> #isLiteral mainly indicates which objects can be created at compile
>> time. They are literally inserted in the compiled method. This must
>> match the syntax definition of Squeak. There is no question about
>> not keeping it.
>
> now I'm confused. are all objects anwering true to #isLiteral also
> have a printed form that can be read back ? should they ?
>
> Stef
It's the other way around - the objects that are recognized
syntactically in a literal array #(...) must also answer true from
#isLiteral. See Array>>isLiteral. This of course implies their printed
form is recognized by the parser.
isSelfEvaluating goes beyond literals - e.g., you cannot put a Point
into a literal array because of syntactical restrictions, "#(3 at 4)" is
parsed as "#(3 #@ 4)". But its print string can still be made self-
evaluating as "{3 at 4}" which is readable. If you want to force a self-
evaluating expression to be printed you need to use storeString
In older Squeak versions like 3.8 you had this:
{3 at 4} printString
'#(3 at 4)'
But that is not self-evaluating even if to a novice it might look like
it was, which is a source of confusion. To avoid that you would need
this
{3 at 4} storeString
'((Array new: 1) at: 1 put: 3 at 4; yourself)'
which does evaluate to an object equal to the original one, but looks
ugly. Now try the same expressions in a more recent Squeak and it's
much nicer :)
- Bert -
More information about the Squeak-dev
mailing list
|