A quick test with emulated Oric BASIC (Tangerine, 1983), shows L-value (I had to acquaint myself via the wiki linked) MID$ to generate a syntax error.
Apple ][ integer BASIC responded the same.
The thing about Sinclair ZX BASIC is that they already had the keyword "TO" as used in FOR...NEXT so they didn't have to assign a character code and keyboard combination to LEFT$, MID$ and RIGHT$, and a programmer doesn't have to remember which keyword to use as TO can be used for any of them thus:
LEFT$(a$,n) > a$( TO n)
MID$(a$,n,l) > a$(n TO n+l-1)
RIGHT$(a$,n) > a$(LEN a$-n+1 TO )
Either parameter omitted defaults to 1 or LEN a$; a$( TO ) is equivalent to a$.
And yes, Sinclair BASIC a$(n TO m) can be used as L-value.
LEFT$ (etc.) as an L-value
-
- Posts: 42
- Joined: Sat 28 May 2022, 22:40
Re: LEFT$ (etc.) as an L-value
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.
Re: LEFT$ (etc.) as an L-value
Except that there's a big price to pay: Sinclair BASIC has no (conventional) string arrays! As I understand it (from the author of SpecBAS, so he should know) the closest you can get to a string array is as follows:nvingo wrote: ↑Sat 19 Nov 2022, 20:19 The thing about Sinclair ZX BASIC is that they already had the keyword "TO" as used in FOR...NEXT so they didn't have to assign a character code and keyboard combination to LEFT$, MID$ and RIGHT$, and a programmer doesn't have to remember which keyword to use as TO can be used for any of them
Code: Select all
DIM a$(10,100)
Other BASICs which use a similar syntax for slicing typically don't use parentheses but square brackets. That's more sensible, because the slicing syntax doesn't interfere with the array syntax.
Although BASIC isn't standardised, and no two BASICs are fully compatible, LEFT$, MID$ and RIGHT$ were well established in the 1970s.
-
- Posts: 42
- Joined: Sat 28 May 2022, 22:40
Re: LEFT$ (etc.) as an L-value
You are correct in that array handling in ZX BASIC is quite different than other dialects. Remember ZX BASIC fitted into 8K ROM which was the design restriction of the ZX81 (I can't comment on the ZX80, other than it could have the ZX81 ROM and keyboard overlay fitted upgrading its BASIC), and the Spectrum remained largely compatible.Hated Moron wrote: ↑Sat 19 Nov 2022, 21:57Except that there's a big price to pay: Sinclair BASIC has no (conventional) string arrays! As I understand it (from the author of SpecBAS, so he should know) the closest you can get to a string array is as follows:
Which is an array of 100 strings each of which has 10 characters, but it's not a string array in the normal sense because the individual elements are not conventional (variable-length) strings.Code: Select all
DIM a$(100,10)
String and floating point arrays can be multidimensional; DIM A$(10,10,10,10) creates 1000 strings of 10 characters fixed length, whereas the same command in BBC BASIC creates (memory permitting) 14641 strings of length 0, which can then be assigned values upto 255 characters length.
Yes, BBC BASIC includes element 0 but ZX BASIC starts at element 1.
In ZX BASIC, the indexes a$(i,j,k,l) and a$(i,j,k)(l) are equivalent.
So it's swings and roundabouts, in ZX BASIC the maximum size of a string array is reserved at declaration and the program cannot proceed if there is insufficient memory, in other dialects it proceeds until such time as a value is assigned that increases the string length beyond the available storage.
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.
Re: LEFT$ (etc.) as an L-value
There were 8K BASICs from Microsoft at the time (both Z80 and 6502), although I don't know if the interpreter used the entire 8K or whether there was anything left for a primitive OS.
Early (8-bit) BBC BASIC provided both! You could choose to initialise strings to their maximum length at the start of the program, guaranteeing (like Sinclair BASIC) that memory wouldn't run out at some unpredictable future time, or you could leave them uninitialised and rely on the dynamic string allocation.So it's swings and roundabouts...