Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String Slicing (*solved*)
#2
britlion Wrote:Not sure whether this is as intended, but it's not quite compatible with Sinclair Basic:

LET K$="1234567890"
PRINT K$(TO 3)
PRINT K$( 3 TO)

All seems to compile - though strings are numbered from 0, whereas Sinclair basic numbers them from 1.
That's right. They start from 0. The reason is it's a little faster to compute string index starting from 0 (otherwise, a "dec" asm instruction would be needed). In the future, the --sinclair compatibility flag would enable strings starting from 1 (as it does currently with arrays).

Quote:So ZX Basic gives the output:

1234, where Sinclair basic would give the output 123

If the aim is to be able to compile Sinclair Basic, we're not there with that one. (Perhaps a switch, or configurable option?)
Well, that's the idea above. On the other hand, the compiler tries to be somewhat Sinclair compatible, but it's more similar to FreeBasic. The reason is, FreeBasic, like ZX Basic is a standard, and it's oriented to compiled execution, whilst Sinclair Basic is more designed to be used as an interpreted language. Hence, emulating some Sinclair Basic instructions like VAL or VAL$ are almost impossible (VAL$ is not implemented, and VAL behaves as a in FreeBasic).

Quote:Also:

Print K$(3) fails. We would need to use k$(3 TO 3). Is this a bug?

PRINT K$( TO ) also fails, and ZX Basic allows it. It's an unusual corner case, though - it means the same thing as just K$. If it was to be supported for compatibility, a preprocessor tweak ought to be able to optimize it to disappear before the compiler saw it.
Could be a grammar bug. I will try to include these grammar cases.

Thanks a lot for your feed back. :wink:


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)