Array literals: ANSI vs. Blue Book
Boris Gaertner
Boris.Gaertner at gmx.net
Tue Dec 31 18:35:07 UTC 2002
This note refers to Squeak3.4beta but I think it applies also to all
earlier versions of Squeak.
In the literal
#('Hello' true false nil)
the four elements are:
1. the string 'Hello'
2. the symbol #true (not the sole instance of class True)
3. the symbol #false (not the sole instance of class False)
4. the symbol #nil (not the sole instance of class UndefinedObject)
This is traditional "Blue Book" Smalltalk. The Blue Book says
(on page 21):
"The literal representation of an array is a sequence of other
literals - numbers, characters, strings, symbols, and arrays -
delimited by parentheses and preceded by a pound sign. The
other literals are separated by spaces. Embedded symbols and
arrays are not preceded by pound signs."
This traditional denotation was implemented in both Smalltalk-80
and Digitalk Smalltalk/V.
But then there came a change with one of the releases of Smalltalk-80
(I think it was release 2.5, but I cannot find documentation that
proves this). The literal expression #('Hello' true false nil) was
now interpreted as the writing form of an array with these
elements:
1. the string 'Hello'
2. the sole instance of class True (not a symbol)
3. the sole instance of class False (not a symbol)
4. the sole instance of class UndefinedObject (not a symbol)
An array with symbols was now written as:
#('Hello' #true #false #nil) The use of the pound symbol with
embedded symbols was introduced to be able to distinguish
between the symbol #true and the value true.
All major Smalltalks changed to the interpretation that allows
the use of the values true, false, nil in array literals. Squeak is,
as far as I can see, the sole Smalltalk that follows the "Blue Book"
interpretation.
Here is what a draft of the ANSI specification from 1997 says:
5.4.6.6 Array Literals
An array literal is a sequenced collection with numeric keys
which may contain any number of other literals.
<array literal> ::= '#(' <array element>* ')'
<array element> ::= <literal> | identifier
The value of an array literal is an object that implements the
<sequencedReadableCollection> protocol. The elements of
an array literal can consist of any combination of literal forms.
If an identifier appears as an <array element> and it is one of
the reserved identifiers nil, true or false the value of the
corresponding element of the collection is the value of
that reserved identifier. The meaning is undefined if any
other identifier is used as an <array element>. If an
<array literal> has no <array element>clauses the
collection has no elements.
My question to the community:
Should we adopt the ANSI interpretation of array
literals or should we keep the 'Blue Book' interpretation?
Note that we can use curly brackets to create an array with
logical values and with the value nil:
{'Hello'. true. false. nil. #true. #false. #nil}
The curly brackets are not part of the 'Blue Book' Smalltalk.
They are, to the best of my understanding, also not part of
the ANSI specification, but at times they are very useful.
The attached change set is perhaps(!) sufficient to change
to ANSI. It should be seen as an experimental change;
please try it only with an image that does not contain
work that you cannot restore after a fatal crash.
Greetings and best wishes for a successful new year
Boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ArrayLiterals.1.cs
Type: application/octet-stream
Size: 2724 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20021231/7d65f340/ArrayLiterals.1.obj
More information about the Squeak-dev
mailing list
|