Sujet : Re: basic BASIC question
De : bqt (at) *nospam* softjar.se (Johnny Billquist)
Groupes : comp.os.vmsDate : 02. Apr 2025, 16:37:38
Autres entêtes
Organisation : MGT Consulting
Message-ID : <vsjlk2$p94$1@news.misty.com>
References : 1
User-Agent : Mozilla Thunderbird
On 2025-01-31 16:18, Arne Vajhøj wrote:
Is it common to use:
declare integer constant TRUE = -1
declare integer constant FALSE = 0
?
After reading through this thread, I can offer a comment or two that I've not seen anyone else bring up (and sorry for reviving a thread that had stopped).
But first of all, while I haven't often seen those declarations as such, they make perfect sense in BASIC.
What noone seems to have brought up is that BASIC don't really have a boolean type, or logical operations on booleans.
There is no boolean AND for instance. There is only the numerical one.
If you do a statement like:
IF 1% AND 2% THEN PRINT "All true" ELSE PRINT "All false"
you'll get "All false".
Because while 1 and 2 both will be regarded as true (or rather not false), AND isn't dealing with them that way. It just does a binary and of the two values, and then you have an IF on the resulting value (which would be 0 in this case).
So in that sense, it is good practice to use -1 for true, because then at least TRUE and (whatever not false) is still (sortof) true.
It's also easy to observe that BASIC actually generally use -1 to represent true.
Just try:
PRINT 1=1
for example. The output will be -1.
Here are the cut-n-paste from BASIC+2 for this:
.bp2
PDP-11 BASIC-PLUS-2 V2.7-C
BASIC2
print 1=1
-1
BASIC2
IF 1% AND 2% THEN PRINT "All true" ELSE PRINT "All false"
All false
BASIC2
Johnny