LEFT$ (etc.) as an L-value

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Hated Moron

LEFT$ (etc.) as an L-value

Post by Hated Moron »

To settle a question at another forum, what other BASICs support using the string-slicing functions (LEFT$, MID$, RIGHT$) as L-values?

Code: Select all

      LEFT$(a$,2) = "ab"
When this feature was added in ARM BBC BASIC V (1986 or thereabouts) I'm sure it wasn't something dreamt up by Sophie, there were other BASICs of the era that supported it too. But which BASICs? And what BASICs still in use today do so, apart from BBC BASIC?
Hated Moron

Re: LEFT$ (etc.) as an L-value

Post by Hated Moron »

Hated Moron wrote: Wed 16 Nov 2022, 18:22 what other BASICs support using the string-slicing functions (LEFT$, MID$, RIGHT$) as L-values?
Nobody? Surely somebody can remember back to 1986 better than I can (that shouldn't be difficult)! Did Sinclair BASIC or Amstrad (Locomotive) BASIC perhaps support it? I've got the Locomotive BASIC manual and I can't find it there. I thought perhaps it was QBASIC, but it doesn't seem to work in that either. Yet I'm fairly certain it wasn't Sophie's invention.
xbones
Posts: 2
Joined: Sat 19 Nov 2022, 12:13

Re: LEFT$ (etc.) as an L-value

Post by xbones »

TrueBasic offers a$[2:3] = b$, for example
Phil_Thatcham
Posts: 4
Joined: Tue 03 Apr 2018, 11:59

Re: LEFT$ (etc.) as an L-value

Post by Phil_Thatcham »

I'm pretty sure Sinclair's BASIC for the ZX80, ZX81 and SPECTRUM had none of the string functions listed. Instead, they sliced strings using an all-purpose TO, e.g.:

Code: Select all

A$ = B$(X TO Y)
where X = start, Y = finish.

As a complete newcomer to BASIC with the ZX80, at the time it seemed neater to me than the RIGHT$(), etc., I found in program listings in more standard BASICs.

I have no idea what happened to Sinclair BASIC after the SPECTRUM.

PT
Hated Moron

Re: LEFT$ (etc.) as an L-value

Post by Hated Moron »

Phil_Thatcham wrote: Sat 19 Nov 2022, 12:20 I'm pretty sure Sinclair's BASIC for the ZX80, ZX81 and SPECTRUM had none of the string functions listed. Instead, they sliced strings using an all-purpose TO
That's correct, but in so doing they were incredibly non-standard. It led to anomalies like the following:

Code: Select all

  DIM a$(10)
  a$(5) = "x"
In all 'conventional' BASICs this is a declaration of a string array and an assignment to the fifth element, but in Sinclair BASIC it modifies the fifth character of a scalar string of length 10! The standard string-slicing functions (LEFT$, MID$, RIGHT$) go back to the 1970s, and were thoroughly established long before Sinclair's BASICs came along, so it was a very strange decision.

Sinclair complained for years afterwards that he hadn't been awarded the BBC Micro contract, but this is something that would have needed to be changed had he done so, because the BBC required good compatibility with Microsoft BASICs.
I have no idea what happened to Sinclair BASIC after the SPECTRUM.
There is Paul Dunn's SpecBAS as I mentioned here only recently.
Phil_Thatcham
Posts: 4
Joined: Tue 03 Apr 2018, 11:59

Re: LEFT$ (etc.) as an L-value

Post by Phil_Thatcham »

Found the BASIC manuals for Locomotive, Amstrad CPC6128 and QBASIC online. They all offer (e.g.) MID$() as both function and statement.

PT
xbones
Posts: 2
Joined: Sat 19 Nov 2022, 12:13

Re: LEFT$ (etc.) as an L-value

Post by xbones »

PowerBasic 10 still has MID$ function and statement.
Hated Moron

Re: LEFT$ (etc.) as an L-value

Post by Hated Moron »

On 19/11/2022 13:07, R NBW wrote (cross-posted from the Discussion Group):
I'm in one of my thick modes. Can you explain exactly what you mean by LEFT$ (etc) as L-value.
I included an example in the first post of this thread, which I thought would explain it to those (I would hope very few) not familiar with the terms l-value and r-value in the context of programming languages:
To settle a question at another forum, what other BASICs support using the string-slicing functions (LEFT$, MID$, RIGHT$) as L-values?

Code: Select all

      LEFT$(a$,2) = "ab"
See also https://en.wikipedia.org/wiki/Value_(co ... d_r-values
Hated Moron

Re: LEFT$ (etc.) as an L-value

Post by Hated Moron »

Phil_Thatcham wrote: Sat 19 Nov 2022, 13:09 Found the BASIC manuals for Locomotive, Amstrad CPC6128 and QBASIC online. They all offer (e.g.) MID$() as both function and statement.
Ah, the rub is in the "e.g.". I tried LEFT$ in QBASIC and it doesn't work, so I concluded that it didn't support this feature, but having now tried it with MID$ it does! Maybe the same is true of the other BASICs.
Hated Moron

Re: LEFT$ (etc.) as an L-value

Post by Hated Moron »

Hated Moron wrote: Wed 16 Nov 2022, 18:22 When this feature was added in ARM BBC BASIC V (1986 or thereabouts) I'm sure it wasn't something dreamt up by Sophie, there were other BASICs of the era that supported it too.
I think we have the answer. It's been confirmed that GW-BASIC supported it (MID$ only) and although that hadn't been released in 1986 Microsoft's BASICA was around, and that is substantially identical. Locomotive BASIC (Amstrad) also had it in 1984. So my recollection that it was already a feature supported by other BASICs in 1986 was correct.