binary selectors ambiguity and space
Stephan Rudlof
sr at evolgo.de
Mon May 15 21:31:02 UTC 2006
Hello All,
I've just digged into
NCITS J20 DRAFT December, 1997 33 of ANSI Smalltalk Standard revision
1.9; in short:
- 'White space is allowed between the '-' and the <number>' for a
numeric literal; and
- 'If a negative <number literal> follows a binary selector there must
intervening white space.'
So your example
>>> On 13.05.2006 02:10, nicolas cellier wrote: nc>... nc> Funny, in
>>> current 3.9 spaces are ignored: nc> i have '1 +- 2' interpreted
>>> as (1) + (-2)
>>>...
is totally legal, but
x+-1
should not be parsed as
(x) + (-1)
. I'm interpreting the standard in this case - at least I think it can
be interpreted this way (see below for the definition of binary
operators) - as to parse it as
(x) +- (1)
, +- being a binary selector.
We should follow the standard IMO, this means to allow
x+-1
(here I have changed my mind after looking into it). In spite of this I
think it is not a good style to omit spaces here (and it gives a MNU
later, if +- is not defined)...
For points like
0 at -1
this could give the workaround of defining
@-
as operator (and @+ , too) much sense, because after the standard 0 at -1
could be parsed as
(0) @- (1)
. Moreover a compile warning - 'Please insert spaces! This will be
parsed as ...; is this your intention?' or so - would make sense then
(since the extra message send here decreases performance).
Snippets from the standard draft:
> 3.4.6.1 Numeric Literals
>
> Numbers are objects that represent numerical values. Numeric literals are used to create numeric
> objects which have specific values and numeric representations.
>
>
> <number literal> ::= ['-'] <number>
> <number> ::= integer | float | scaledDecimal
>
> If the preceding '-' is not present the value of the numeric object is a positive number. If the '-' is
> present the value of the numeric object is the negative number that is the negation of the positive
> number defined by the <number> clause. White space is allowed between the '-' and the
> <number>.
>...
> 3.5.5 Operators
>
> Three types of operator tokens are defined in Smalltalk: binary selectors, the return operator, and
> the assignment operator.
>
> .
> binaryCharacter ::=
> '!' | '%' | '&'' | '*' | '+' | ','' | '/' | '<' | '=' | '>' | '?' | '@' | '\' | '~' | '|' | '-'
> binarySelector ::= binaryCharacter+
>
> returnOperator ::= '^'
>
> assignmentOperator ::= ':='
>
> Binary selectors are method selectors that appear similar to mathematical operators. A binary
> selector may be any length greater than or equal to one. If a negative <number literal> follows a
> binary selector there must intervening white space.
>
> An implementation may define additional binaryCharacters but their use may result in a non-
> portable program.
Regards,
Stephan
PS: Nice that you already have code for finding critical cases.
On 15.05.2006 22:27, nicolas cellier wrote:
>...
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|