> < ^ Date: Tue, 23 Mar 1993 19:25:06 +0100
> < ^ From: Martin Schoenert <martin.schoenert@math.rwth-aachen.de >
< ^ Subject: Re: Inconsistencies in new string, list and range features.
Steve Linton writes in his e-mail message of 1993/03/23

1) While strings are lists, string literals do not appear to be
usable as such:

gap> "abc"[1];
Syntax error: ; expected
"abc"[1];
     ^

This is not a problem of strings. The same ``problem'' appears with any
list. I.e., '[2,3,5,7,11][3]' is also not allowed. The BNF syntax shows
you that left of the '[' there must be a *variable*, i.e., either
'<identifier>', '<variable>.<identifier>', or '<variable>.[<expr>]'. It
would be possible to change the parser to allow something like
'<list-literal>[<expr>]', but frankly this doesn't seem very important.

Steve Linton continues:

2) I think the following should work:

gap> [y := 9, y-1 ..1];
Syntax error: ] expected
[y := 9, y-1..1];
    ^
This may look stupid, but suppose 9 were replaced by an expensive
function call.

gap> y := 9; [y,y-1..1];
9
[ 9, 8 .. 1 ]

works, but seems unnecessarily long.

Actually, the best way to cope with this situation would be to be
able to specify the step explicitly in a range literal, something
like [start, end : step].

Since ranges are internally stored as triple <low>, <high>, <inc>, a
syntax of the form '[ <low> .. <high> by <inc> ]' would not pose any
difficulties. Maybe some day.

Martin.

-- .- .-. - .. -.  .-.. --- ...- . ...  .- -. -. .. -.- .-
Martin Sch"onert,   Martin.Schoenert@Math.RWTH-Aachen.DE,  +49 241 804551
Lehrstuhl D f"ur Mathematik, Templergraben 64, RWTH, D 51 Aachen, Germany

> < [top]