Forum
Compounded Let statments - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+--- Thread: Compounded Let statments (/showthread.php?tid=786)



Compounded Let statments - emook - 02-02-2017

Hello,

I've noticed that somthing that is possible is Sinclair Basic doesn't seem possible in Boriel....

eg:

Sinclair Basic

10 LET x=0
20 LET x=x+1-(50 AND x=50)
30 PRINT AT 0,0;x,
40 GOTO 20

As you can see x=x+1 will increment minus 0 unless x=50 then it will subtract 50. Great for loops and counters. In ZXB I am having to expand this into IF THEN statements.

x=0
x=x+1
myloop:
IF x=50 THEN
x=0
END IF
Print at 0,0;x,
GOTO myloop


Re: Compounded Let statments - boriel - 02-03-2017

True Confusedhock:
I didn't know this behaviour.
Where can I find more info about this?

anyway, the fastest way to this is:
Code:
DIM x AS Byte = 0
myloop:
x=(x+1) MOD 50
PRINT AT 0,0;x,
GOTO myloop



Re: Compounded Let statments - emook - 02-05-2017

It is mentioned very briefly in the ZX Basic manual, <!-- m --><a class="postlink" href="http://www.worldofspectrum.org/ZXBasicManual/zxmanchap13.html">http://www.worldofspectrum.org/ZXBasicM ... hap13.html</a><!-- m -->

But turns out to be far more useful. See this program that creates the +2 test screen :

10 FOR l=0 TO 21 : FOR i=7 to 0 STEP -1 : PRINT INK (l and l<8); PAPER i;("19" AND l<8); (" " AND l>= 8 ) ; BRIGHT 1; ("86" AND l<8); (" " AND l>=8);: NEXT i : NEXT l

You can see a live version of it here :
Run demo


Re: Compounded Let statments - boriel - 02-05-2017

Ok. I see.
I'll try to implement that, but with only in "--sinclair" mode. Otherwise bool comparisons will be slower :roll:

Perhaps it would be better to implement the ? : operator like in C??
What do you people think?


Re: Compounded Let statments - Haplo - 02-07-2017

boriel Wrote:Perhaps it would be better to implement the ? : operator like in C??

I think that is a good idea, it could help to do more readable the code.


Re: Compounded Let statments - britlion - 09-19-2018

Just following up a few threads. Not sure if this got implemented. It's a /very/ common way to do things like keys:

Code:
LET x=x+(Inkey$="P")-(Inkey$="O")

And depends on the fact that in Sinclair basic, False equates to zero and true equates to 1. This is not stricktly speaking true in Boriel's Basic. It probably should work in sinclair mode.

Perhaps

Code:
x=x+(SGN (key="p") - (SGN (key="o"))

might be the same logical result, given false=0 and I think true is > 0 ?


Re: Compounded Let statments - boriel - 09-20-2018

Or using --strict-boolean which ensures true is always 1 (with a little performance overhead). Anyway, boolean operations where slightly optimized upon 1.7.x+
So even without --strict-boolean many of them returns 1 for true.