Page 1 of 2 12>
Topic Options
#79813 - 2003-10-10 09:33 PM Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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

Top
#79814 - 2003-10-10 09:50 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#79815 - 2003-10-10 10:09 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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 ]

Top
#79816 - 2003-10-10 10:09 PM Re: Behavior of NOT "0"
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#79817 - 2003-10-10 10:14 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#79818 - 2003-10-10 10:18 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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 ...

Top
#79819 - 2003-10-10 10:23 PM Re: Behavior of NOT "0"
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#79820 - 2003-10-10 10:27 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#79821 - 2003-10-10 10:30 PM Re: Behavior of NOT "0"
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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 ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#79822 - 2003-10-10 10:31 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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.
Top
#79823 - 2003-10-10 10:32 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
just like hoby said.
yet again, talking of integer math and boolean stuff.
not related.
_________________________
!

download KiXnet

Top
#79824 - 2003-10-10 10:35 PM Re: Behavior of NOT "0"
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I love this board. This is the BEST thread today. Thanks Shawn. [Cool]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#79825 - 2003-10-10 10:37 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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)
Top
#79826 - 2003-10-10 10:39 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lol.
dude, I'm a geek.
and I say there is no math other than boolean math!
_________________________
!

download KiXnet

Top
#79827 - 2003-10-10 10:47 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hehee, I know Boolean Math is real math, but obviously Kixtart doesn't think so [Wink]
Top
#79828 - 2003-10-10 10:49 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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!
_________________________
!

download KiXnet

Top
#79829 - 2003-10-10 11:07 PM Re: Behavior of NOT "0"
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
eh you know me by now Jooel, i am a scr*wed up basta [Wink]
Top
#79830 - 2003-10-10 11:07 PM Re: Behavior of NOT "0"
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#79831 - 2003-10-10 11:20 PM Re: Behavior of NOT "0"
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
not sure hoby.
I think it's nul.
quess void could have similar rank too.

shawn, love ya.
_________________________
!

download KiXnet

Top
#79832 - 2003-10-13 02:44 PM Re: Behavior of NOT "0"
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
Page 1 of 2 12>


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.073 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.