RetroBASIC

Basicprogramming(.org) => General questions and discussions => Topic started by: B+ on May 17, 2019, 01:07:02 pm

Title: Basic Logic
Post by: B+ on May 17, 2019, 01:07:02 pm
Found at SdlBasic forum:
Quote
'Hey, folks. While porting some code from Python, I accidentally discovered that sdlBasic accepts this syntax for comparison expressions:


'Code:
'dim x = 0
'print 1 <= x <= 10


'That shouldn't be valid Basic, and indeed it returns true when it's not supposed to, but sdlBasic compiles and runs the code. Beware!


Code: [Select]
x = 0
PRINT "     1 <= x <= 10  is "; 1 <= x <= 10, " not supposed to return True???"
PRINT
PRINT "It is supposed to be True, Proof:"
PRINT "            1 <= x is "; 1 <= x '           > 0
PRINT "          0 <= 10  is "; 0 <= 10 '          > -1
PRINT "  ((1 < x) <= 10)  is "; ((1 < x) <= 10) '  > -1
PRINT
PRINT " See Basic knows the difference!"
PRINT "                 x is"; x '                 > 0
PRINT "1 <= x AND x <= 10 is"; 1 <= x AND x <= 10 '> 0
Title: Re: Basic Logic
Post by: ZXDunny on May 17, 2019, 01:46:38 pm
Depends on the BASIC, I suppose.

Sinclair BASIC uses 0 = False, 1+ = True.

So the line 1<=x<=10 will always return true regardless of what x actually is - if 1<=x then we get 1 (true). If x=0 then we get false (0). 1 and 0 are less than 10, so it will always evaluate to true.
Title: Re: Basic Logic
Post by: B+ on May 17, 2019, 02:21:01 pm
Oh yeah, SmallBASIC uses 1 for True too and it also returns True for
Code: [Select]
PRINT "     1 <= x <= 10  is "; 1 <= x <= 10, " not supposed to return True???"

Wether 1 <= x returns -1, 0, or 1 all those are less than 10. 

Is the Spell Checker working for you guys? it seems to have died for me on a couple of forums.

weather whether whatever what whaat whaaat :P

Title: Re: Basic Logic
Post by: Aurel on May 17, 2019, 06:56:13 pm
My main point about this is :

That shouldn't be valid Basic

and that is TRUE
Title: Re: Basic Logic
Post by: n00b on May 17, 2019, 10:49:58 pm
It actually is valid in pretty much every programming language.  Comparisons are still numerical operators and boolean is just a value that denotes 0 and NOT 0.
Title: Re: Basic Logic
Post by: Aurel on May 18, 2019, 05:50:54 am
Boolean is RESULT of comparison expression..
if we can call such a operation expression.
Title: Re: Basic Logic
Post by: ZXDunny on May 18, 2019, 10:22:09 am
So you're saying that "=", "<=", "<>" etc should not return a numerical value, yes? So what should they return, and how should it be represented in memory? As something other than a value? If so, I have some very bad news for you.
Title: Re: Basic Logic
Post by: Aurel on May 18, 2019, 07:13:24 pm
If so, I have some very bad news for you.

What kind of bad news?

Paul
I just confirm what man above stated.
and that shouldn't be valid BASIC statement
print 1 > 2 -> show  -1 (true)

what a heck is that in BASIC world...
Of course that i understand what that mean but is stupid..

should be ;( with more sense ..with boolean type )

print BOOL(1>2) ->  -1
Title: Re: Basic Logic
Post by: ZXDunny on May 18, 2019, 10:26:24 pm
If so, I have some very bad news for you.

What kind of bad news?

In computing, everything is a number. Including booleans.

Quote
Paul
I just confirm what man above stated.
and that shouldn't be valid BASIC statement
print 1 > 2 -> show  -1 (true)

what a heck is that in BASIC world...
Of course that i understand what that mean but is stupid..

should be ;( with more sense ..with boolean type )

print BOOL(1>2) ->  -1

But a boolean is just a number - usually 1 or 0 for true or false (or in some dialects it's all bits set, so $FF if 8bit etc which yields -1 when viewed as a signed value) so the above statement is perfectly valid. But people who don't understand how a CPU works under the hood will often be surprised that 1<=x<=10 will always result in a true (non-zero) value.

I was puzzled that you said it shouldn't be valid BASIC. Why not?
Title: Re: Basic Logic
Post by: Aurel on May 19, 2019, 06:23:26 am
Because is stupid and unlogical and as i show should be typed
As Boolean .

In computing, everything is a number. Including booleans.

Of course that i know that..  ::)
Title: Re: Basic Logic
Post by: ZXDunny on May 19, 2019, 02:53:25 pm
Because is stupid and unlogical and as i show should be typed
As Boolean .

In computing, everything is a number. Including booleans.

Of course that i know that..  ::)

I was wondering if you did, given what you're posted here tbh. So you want a new type to be created, "Boolean" which all BASICs should be using instead of numerical equivalents? How would we represent these at the assembly language level? How would we handle "LET a=(b>c)"? Would that particular case be disallowed, as a numeric variable cannot hold a boolean value, or would the variable (a) be converted to hold a boolean value? Would we allow users to cast booleans as integers? And how would they be converted?
Title: Re: Basic Logic
Post by: B+ on May 19, 2019, 03:50:10 pm
If so, I have some very bad news for you.

What kind of bad news?

Paul
I just confirm what man above stated.
and that shouldn't be valid BASIC statement
print 1 > 2 -> show  -1 (true)

what a heck is that in BASIC world...
Of course that i understand what that mean but is stupid..

should be ;( with more sense ..with boolean type )

print BOOL(1>2) ->  -1

What a heck!?!?
1>2 is False = 0
Is there a Basic that returns True?
Title: Re: Basic Logic
Post by: Aurel on May 19, 2019, 05:36:46 pm
Yo Mark yes i made mistake because of stupid talk about things we know.
Both me and Paul and i don't know why he insist on this .. :o

This BOOL or BOOLEAN already exists in Oxygen Basic compiler
and i am not sure in some others too (maybe VB)
so....what a heck is this time with you ?
So i must repeat again ...I just agree with the statement above..
and your insinuation that i don't know or don't understand is really silly.. ;D
and you UNDERSTAND

Mark yeah

print BOOL(1<2)  -> TRUE or -1( on Windows) or if author of progrmming language decide
can be 1.
Also you can easy change booleans to integers because are integers ... 0,1
I have used many times so called boolean logic to confirm TRUE or FALLSE.

simple example in o2
both functions are valid without any problem ,only difference is what is TRUE ( -1 or 1)
depend how you define them:

FUNCTION isdigit(S AS STRING) AS INT
     If (asc(S)>47 And asc(S)<58) Or asc(S)=46
     Return 1
     End if
     Return 0
END FUNCTION

FUNCTION isdigit(S AS STRING) AS BOOL
     If (asc(S)>47 And asc(S)<58) Or asc(S)=46
     Return TRUE
     End if
     Return FALSE
END FUNCTION 

..so ZXdunny do you maybe need compiled example ;D
pih..
Title: Re: Basic Logic
Post by: Aurel on May 19, 2019, 05:58:40 pm
By the way when we "talk" Dunny
long time i don't visit your site/forum ...
where are all that people  :o
last post 2018.....

hmmm same thing everywhere...
it looks to me that all gone
maybe are on qb64 forum  ;D
Title: Re: Basic Logic
Post by: ZXDunny on May 19, 2019, 07:06:03 pm
Trust me, Aurel, I know how booleans work - I really wouldn't be spending most of my days writing complex audio processing software if I didn't :D

As for the forum - we've moved to other places now. There's SpecBAS on Discord, Facebook, Twitter, IRC as well as web sub-forums integrated into various retro places. I don't work on SpecBAS as much as I used to because work generally takes precedent, but I do commit new changes to the repo from time to time. I'm also getting started on my older projects such as ZXSpin and BASin which badly need to be updated to work in Windows 10 these days.
Title: Re: Basic Logic
Post by: Richly on May 23, 2019, 06:32:25 am
I don't work on SpecBAS as much as I used to because work generally takes precedent, but I do commit new changes to the repo from time to time. I'm also getting started on my older projects such as ZXSpin and BASin which badly need to be updated to work in Windows 10 these days.

Hi D  :)

Sounds great. Where can I get the latest SpecBas build and where will you announce updates to BASin and ZXSpin (I'm not on Facebook)? Is / will BASin be available for MacOS too?
Title: Re: Basic Logic
Post by: ZXDunny on May 23, 2019, 10:19:57 am
I don't work on SpecBAS as much as I used to because work generally takes precedent, but I do commit new changes to the repo from time to time. I'm also getting started on my older projects such as ZXSpin and BASin which badly need to be updated to work in Windows 10 these days.

Hi D  :)

Sounds great. Where can I get the latest SpecBas build and where will you announce updates to BASin and ZXSpin (I'm not on Facebook)? Is / will BASin be available for MacOS too?

I'll get a new build of SpecBAS up later today, I have some new stuff been added that should probably be available to all.

I'll announce new builds of BASin and ZXSpin on WOS and Spectrum Computing forums, but it will be a while. I'm currently working through ZXSpin's code getting it to build in a more modern IDE at present.
Title: Re: Basic Logic
Post by: Richly on May 23, 2019, 09:55:41 pm
Ok, thanks D I'll keep a look out.

Will the latest SpecBAS build be posted to the SpecBAS web page or forum?