#79815 - 2003-10-10 10:09 PM
Re: Behavior of NOT "0"
|
Shawn
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 ] [ 10. October 2003, 22:10: Message edited by: Shawn ]
|
Top
|
|
|
|
#79816 - 2003-10-10 10:09 PM
Re: Behavior of NOT "0"
|
Howard Bullock
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 ]
|
Top
|
|
|
|
#79818 - 2003-10-10 10:18 PM
Re: Behavior of NOT "0"
|
Shawn
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
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 ]
|
Top
|
|
|
|
#79821 - 2003-10-10 10:30 PM
Re: Behavior of NOT "0"
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You Basta! You almost had me agreeing with that last statement.
But try this:
? vartypename( 0 + "2") ? vartypename(+ "2")
The leading numeric is the key! [ 10. October 2003, 22:32: Message edited by: Howard Bullock ]
|
Top
|
|
|
|
#79824 - 2003-10-10 10:35 PM
Re: Behavior of NOT "0"
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I love this board. This is the BEST thread today. Thanks Shawn.
|
Top
|
|
|
|
#79827 - 2003-10-10 10:47 PM
Re: Behavior of NOT "0"
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
hehee, I know Boolean Math is real math, but obviously Kixtart doesn't think so
|
Top
|
|
|
|
#79829 - 2003-10-10 11:07 PM
Re: Behavior of NOT "0"
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
eh you know me by now Jooel, i am a scr*wed up basta
|
Top
|
|
|
|
#79830 - 2003-10-10 11:07 PM
Re: Behavior of NOT "0"
|
Howard Bullock
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".
|
Top
|
|
|
|
#79832 - 2003-10-13 02:44 PM
Re: Behavior of NOT "0"
|
Richard H.
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
|
|
|
|
Moderator: ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 566 anonymous users online.
|
|
|