ShawnAdministrator
(KiX Supporter)
2003-10-10 09:33 PM
Behavior of NOT "0"

Ruud,

Would like to submit that the current result of this expression:

NOT "0"

is incorrect. Currently this returns 0 (false) when it probably should return 1 (true). Just by way of a test, this VBS statement:

wscript.echo NOT "0"

returns a -1 (true)

-Shawn


LonkeroAdministrator
(KiX Master Guru)
2003-10-10 09:50 PM
Re: Behavior of NOT "0"

nope.
$true = not 0
$false = not 1

$this= NOT "0" ; 1 char string is not false thus it's true. true not, makes it false.
vartypename($this)
? "is it false = " iif($false=$this,1,0)
? "is it true = " iif($true=$this,1,0)
get $
exit 0


result is:
Boolean
is it false = 1
is it true = 0


just the way it should be.


ShawnAdministrator
(KiX Supporter)
2003-10-10 10:09 PM
Re: Behavior of NOT "0"

I see your point, but my argument is that if the expression 2 + "2" return 4 (because it starts with a number, and all subsequent strings get converted to numbers), then NOT "0" should return TRUE, because the expression starts with a unary operator ... just my two cents and the VBS script confirms the theory [ not that VBS is the gospel or anything [Wink] ]

[ 10. October 2003, 22:10: Message edited by: Shawn ]


Howard Bullock
(KiX Supporter)
2003-10-10 10:09 PM
Re: Behavior of NOT "0"

code:
$= SetOption("WrapAtEol","On")
? "KiXtart version = " @KIX
? "Not 0 = " + (not 0)
? "Not 1 = " + (not 1)
? "Not -1 = " + (not -1)

Results:
code:
KiXtart version = 4.02
Not 0 = 1
Not 1 = 0
Not -1 = 0

KiXtart version = 4.20
Not 0 = 1
Not 1 = 0
Not -1 = 0

KiXtart version = 4.21
Not 0 = 1
Not 1 = 0
Not -1 = 0

KiXtart version = KiXtart 2001 4.22 Release Candidate 1
Not 0 = 1
Not 1 = 0
Not -1 = 0

code:
$= SetOption("WrapAtEol","On")
? "KiXtart version = " @KIX
? "Not '0' = " + (not '0')
? "Not '1' = " + (not '1')
? "Not '-1' = " + (not '-1')

Results:
code:
KiXtart version = 4.21
Not '0' = 0
Not '1' = 0
Not '-1' = 0

KiXtart version = KiXtart 2001 4.22 Release Candidate 1
Not '0' = 0
Not '1' = 0
Not '-1' = 0

Shawn I would have to argue that (Not "0") does NOT equal 1 since a string is a true value and the the negation of something is nothing.

[ 10. October 2003, 22:10: Message edited by: Howard Bullock ]


LonkeroAdministrator
(KiX Master Guru)
2003-10-10 10:14 PM
Re: Behavior of NOT "0"

shawnie...
2+"2"
is integer plus string, thus the string will be translated to integer.

not "0"
not is boolean, thus "0" STRING will be translated to boolean. it can't be false as it has something in it (not nul) so it must be true.


ShawnAdministrator
(KiX Supporter)
2003-10-10 10:18 PM
Re: Behavior of NOT "0"

Well, this gets into to very messy "strings in expressions" debate, and tbh, if Ruud made the behavior more like VBS, might break some existing scripts, but it appears that the logic should be like the following string math:

2 + "2"

produces 4, but this:

2 + "A"

produces 2, so imagine that Ruud is doing a numeric conversion on strings in expressions, if they convert ok, then it used, else it's discarded. The same should hold true for this expression:

NOT "0"

but this:

NOT "BASTAH"

will still produce false. Its not like this is a biggy bug or anything, nothing that a well-placed VAL() couldn't fix ... this is just an on principle type thingy ...


Howard Bullock
(KiX Supporter)
2003-10-10 10:23 PM
Re: Behavior of NOT "0"

Shawn, I have to disagree with your conclusion and examples.

2 + "2" yields 4 because you have a numeric and addition which coerces the statement to be numeric.

Not "0" lacks both a leading numeric and a math function.

So you should be doing Not (0 + "0") to be on a level playing field.

[ 10. October 2003, 22:24: Message edited by: Howard Bullock ]


ShawnAdministrator
(KiX Supporter)
2003-10-10 10:27 PM
Re: Behavior of NOT "0"

NOT "0" is an expression that starts with a numeric operation (a mathmatical logic operation actually), therefore, the result of the expression will be numeric, therefore the strings inside should be converted to numeric if possible (like in 2+"2"), thats my argument.

Howard Bullock
(KiX Supporter)
2003-10-10 10:30 PM
Re: Behavior of NOT "0"

You Basta! You almost had me agreeing with that last statement. [Razz] [Eek!]

But try this:

? vartypename( 0 + "2")
? vartypename(+ "2")

The leading numeric is the key!

[ 10. October 2003, 22:32: Message edited by: Howard Bullock ]


ShawnAdministrator
(KiX Supporter)
2003-10-10 10:31 PM
Re: Behavior of NOT "0"

Actually, the result will be boolean not numeric ... but should expressions that return booleans be treated like ones that return numbers, guess thats the debate. They are obviously not treated the same today.

LonkeroAdministrator
(KiX Master Guru)
2003-10-10 10:32 PM
Re: Behavior of NOT "0"

yep.
just like hoby said.
yet again, talking of integer math and boolean stuff.
not related.


Howard Bullock
(KiX Supporter)
2003-10-10 10:35 PM
Re: Behavior of NOT "0"

I love this board. This is the BEST thread today. Thanks Shawn. [Cool]

ShawnAdministrator
(KiX Supporter)
2003-10-10 10:37 PM
Re: Behavior of NOT "0"

I dont know about that ... I think they are related somewhat, FALSE = 0 and TRUE = 1 but I am not sure if boolean math is real math (kinda like string math is not real math)

LonkeroAdministrator
(KiX Master Guru)
2003-10-10 10:39 PM
Re: Behavior of NOT "0"

lol.
dude, I'm a geek.
and I say there is no math other than boolean math!


ShawnAdministrator
(KiX Supporter)
2003-10-10 10:47 PM
Re: Behavior of NOT "0"

hehee, I know Boolean Math is real math, but obviously Kixtart doesn't think so [Wink]

LonkeroAdministrator
(KiX Master Guru)
2003-10-10 10:49 PM
Re: Behavior of NOT "0"

yet again.
don't know what's going in your brain.

I bet you are so sucked in VBS world that you really thing that:
not -1

will also produce false!


ShawnAdministrator
(KiX Supporter)
2003-10-10 11:07 PM
Re: Behavior of NOT "0"

eh you know me by now Jooel, i am a scr*wed up basta [Wink]

Howard Bullock
(KiX Supporter)
2003-10-10 11:07 PM
Re: Behavior of NOT "0"

I see that NOT behaves as expected when using bitwise operations on what is passed into it.

Not 0 is the same as Not 00000000 (bits) where Not "0" really equals Not 00110000 (bits) which truly is not "Not 0". [Wink]


LonkeroAdministrator
(KiX Master Guru)
2003-10-10 11:20 PM
Re: Behavior of NOT "0"

not sure hoby.
I think it's nul.
quess void could have similar rank too.

shawn, love ya.


Richard H.Administrator
(KiX Supporter)
2003-10-13 02:44 PM
Re: Behavior of NOT "0"

I've been away on holiday, so I'm a little late to this interesting thread.

Firstly I'd have to say that KiXtart's handling of "0" as being true is correct in context. An expression which is a zero length string is false, one which is not a zero length string is true.

quote:
NOT "0" is an expression that starts with a numeric operation (a mathmatical logic operation actually), therefore, the result of the expression will be numeric, therefore the strings inside should be converted to numeric if possible (like in 2+"2"), thats my argument.
No - not true, and perhaps the source of the confusion.
NOT is unary operator whose result and action is "logical" or boolean - it is quite explicitly not numeric.

If you check the KiXtart manual for operators you will find two listings. One is for numeric operators and the other is for "conditional and logical" operators which are valid for numeric and string expressions.

If you specifically want to check the truth of the numeric value of the expression rather than the truth of the expression you should quite rightly expect to have to explicitly cast/coerce the value:
code:
Not Val("0")

The difference with VBS is interesting. Does the VBS NOT operator only take numeric operands? If so there may be an implied cast to numeric.


Ruud van Velsen
(Hey THIS is FUN)
2003-11-06 01:49 PM
Re: Behavior of NOT "0"

In short: nothing to add to this... Which is why the kixtart.org forum users rock... ;-)

Ruud


LonkeroAdministrator
(KiX Master Guru)
2003-11-07 03:32 AM
Re: Behavior of NOT "0"

thanks Ruud.
these type of comments are always welcome [Wink]