On 08/01/2024 18:46, pjw via Ql-Users wrote:

> 100 a$ = "1234567890"
> 105 b$ = a$(4 to 3): REMark This works
> 110 REMark c$ = a$(4 to 2): REMark This fails with an error.
> 115 c$ = a$( to 0) : REMark  no error returned
> 120 c$ = a$(0):    : REMark  no error returned  BUT ERROR IF QLIBERATED
> 125 pause:stop

Line 105: The construct a$(n to n - 1) represents the empty string (even when n = 1). Since it is replicated in JS, Minerva and SMSQ/E Im assuming it is by design.

If it's by design, it it actually documented anywhere? I do not recall it being in the QL Manual, as supplied with new QLs back in the day, and I don't recall Jan Jones mentioning it either.

My QL Manual is packed away ready for a house move---which fell through---Just checked with Jan Jones (the QUANTA version), she doesn't mention how this works (or doesn't!)

It also makes sense as there would be no other way to represent a string slice of null.

I'm wondering though, why you would need to get a "string slice of null"? If I want to obtain a an empty string, just assigne on A$="" for example.

To get a slice that is null, I need to determine that this is exactly what I need, and then make sure that my slicing parameters are specified with the end being exactly one less than the start? Too much faffing around, just assign an empty string (as above!)

Line 115: I guess a$( to 0) is read as a$(1 to 0) which fits the criteria above.

I agree with your observation. Jan Jones states that when slicing a string variable, the zeroth elephant cannot be accessed. (Page 28.)

Line 120: a$(0) should be fine also. It represents the string length. Assignment to this location is also acceptable:

Jan Jones documents this in her QL SuperBASIC Handbook, page 23.

I still think that returning "" for a specific string slice from (a to a-1) is a bug! Bite me!!! ;-)


Norman Dunbar.

QL-Users Mailing List

Reply via email to