Author Topic: Basic Logic  (Read 4843 times)

B+

  • Guest
Basic Logic
« 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
« Last Edit: May 17, 2019, 01:30:33 PM by B+ »

ZXDunny

  • Guest
Re: Basic Logic
« Reply #1 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.

B+

  • Guest
Re: Basic Logic
« Reply #2 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

« Last Edit: May 17, 2019, 05:16:21 PM by B+ »

Aurel

  • Guest
Re: Basic Logic
« Reply #3 on: May 17, 2019, 06:56:13 PM »
My main point about this is :

That shouldn't be valid Basic

and that is TRUE

n00b

  • Guest
Re: Basic Logic
« Reply #4 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.

Aurel

  • Guest
Re: Basic Logic
« Reply #5 on: May 18, 2019, 05:50:54 AM »
Boolean is RESULT of comparison expression..
if we can call such a operation expression.

ZXDunny

  • Guest
Re: Basic Logic
« Reply #6 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.

Aurel

  • Guest
Re: Basic Logic
« Reply #7 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
« Last Edit: May 18, 2019, 07:15:06 PM by Aurel »

ZXDunny

  • Guest
Re: Basic Logic
« Reply #8 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?

Aurel

  • Guest
Re: Basic Logic
« Reply #9 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..  ::)

ZXDunny

  • Guest
Re: Basic Logic
« Reply #10 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?

B+

  • Guest
Re: Basic Logic
« Reply #11 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?
« Last Edit: May 19, 2019, 03:56:31 PM by B+ »

Aurel

  • Guest
Re: Basic Logic
« Reply #12 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..

Aurel

  • Guest
Re: Basic Logic
« Reply #13 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
« Last Edit: May 19, 2019, 06:02:24 PM by Aurel »

ZXDunny

  • Guest
Re: Basic Logic
« Reply #14 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.