SadBunny Posted February 19, 2015 Share Posted February 19, 2015 (edited) Hi there, In another thread Nitekram had a function returning either a populated array or False. I was about to suggest you could still use that as a boolean, but I'm happy I tested that assumption just to be sure. dim $a[1]; $a[0]="hello world"; if $a <> False then ConsoleWrite("it is something other than False" & @crlf) EndIf if $a then ConsoleWrite("it is true" & @crlf) Else ConsoleWrite("it is not true" & @crlf) EndIf if not $a then ConsoleWrite("it is false" & @crlf) Else ConsoleWrite("it is not false" & @crlf) EndIf Result: it is something other than False it is not true it is false Argh! What is the boolean truth value of a variable containing a perfectly fine array? Seemingly it's a meaningless question in AutoIt... Really?? Edited February 19, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Spider001 Posted February 19, 2015 Share Posted February 19, 2015 https://www.autoitscript.com/autoit3/docs/functions/IsArray.htm Link to comment Share on other sites More sharing options...
bogQ Posted February 19, 2015 Share Posted February 19, 2015 (edited) Argh! What is the boolean truth value of a variable containing a perfectly fine array?i think your missing the point.a variable doesnt containing a perfectly fine arraya array containing a perfectly fine array elementsso i googled this for you that i think it'll be satisfying for youhttp://www.answers.com/Q/What_is_the_difference_between_an_array_and_variableespecialy"it is true when the elements of the array are treated as individual entities"and"It is not generally right to distinguish between a variable and an array. You'd be comparing apples with pears." Edited February 19, 2015 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
SadBunny Posted February 19, 2015 Author Share Posted February 19, 2015 (edited) https://www.autoitscript.com/autoit3/docs/functions/IsArray.htm I understand that I can check whether a variable points to an array with IsArray(), but that's not the point. I myself would consider a situation where you use a variable both as a boolean and a pointer to an array bad code. I would not run into this problem in my work I just think it's weird that AutoIt works this way. i think your missing the point. a variable doesnt containing a perfectly fine array a array containing a perfectly fine array elements Thanks for the link, but I think you're missing the point I did and would not confuse a variable with an array. For the purposes of this question, a variable is a handle to a certain data structure. Whether that be a boolean or an integer or an array (itself a collection of handles to yet other data structures) or an Audi sports car is not important. If I put it behind an if, I expect the engine to either draw an understandable boolean from it (meaning based on an understandable algorithm), or error out with "invalid truth expression" or whatever. Take awk, mine gives a clear error if I try to use a variable "holding" an array as the truth expression: $ awk 'BEGIN {arr[1]=1; if (arr){print "yes";}}' awk: cmd. line:1: fatal: attempt to use array `arr' in a scalar context Or perl, which considers an empty array false and a non-empty array true, which also makes a lot of sence IMO: $ perl -e "@arr = (); if (@arr) {print 'yes'}" $ perl -e "@arr = (0,1,2); if (@arr) {print 'yes'}" yes AutoIt seems weird in this regard. Edited February 19, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
czardas Posted February 19, 2015 Share Posted February 19, 2015 (edited) It's a bit confusing. If I create an array with one False value, it still exists. I would return True (not False because the array contains information). What if an array has zero elements or a mixture of True and False values? Edited February 19, 2015 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2015 Moderators Share Posted February 19, 2015 Hi,It is well known that because of its lack of typing AutoIt can produce some apparently strange results when comparing variables - think of the number of times we have had to explain about the problems of comparing stings and numeric values. It seems to me that we have another case in point here - trying to compare arrays with Booleans is just not a sensible thing to do. The Help file does say for True/False: These keywords should not be used in expressions as AutoIt will not detect this 'misuse' and the results will be unpredictablewhich seems to sum up the results obtained here quite nicely. It seems to me that the entire matter could have been avoided had the function to which the OP referred used a more sensible error return value than False allowing for a simple and logical comparison to detect the failure case - for instance returning an empty string, or indeed setting the @error macro which is designed for this very case. M23 SadBunny 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
SadBunny Posted February 19, 2015 Author Share Posted February 19, 2015 (edited) It's a bit confusing. If I create an array with one False value, it still exists. I would return True (not False because the array contains information). What if an array has zero elements or a mixture of True and False values? If I had to choose, I'd agree with the Awk approach, and would prefer a language to throw some sort of type safety error, even a language without much of a type safety idea (which Awk also doesn't have). Perl is stupid anyway (apart from its stellar Regex support), but at least it's consistently stupid Lacking a null or a strict boolean type in the language, I could also live with considering any variable pointing to an empty string ("") or integer 0 a False, and anything else (including an array, even an empty one) as True. But defending that still leads to arguments that feel like deductive contradictions, so it would still itch Hi, It is well known that because of its lack of typing AutoIt can produce some apparently strange results when comparing variables - think of the number of times we have had to explain about the problems of comparing stings and numeric values. It seems to me that we have another case in point here - trying to compare arrays with Booleans is just not a sensible thing to do. The Help file does say for True/False: These keywords should not be used in expressions as AutoIt will not detect this 'misuse' and the results will be unpredictable which seems to sum up the results obtained here quite nicely. It seems to me that the entire matter could have been avoided had the function to which the OP referred used a more sensible error return value than False allowing for a simple and logical comparison to detect the failure case - for instance returning an empty string, or indeed setting the @error macro which is designed for this very case. M23 All very True of course (/edit: then again... what does True even mean given the subject matter of this thread? ) And I understood that, and there are multiple ways to improve that function I referred to. Yours is fancy, my own quite oneliner-y suggestion in that thread probably came from 10 hours of awk'ing radiation at the black hole that was my work today. Still I think it's kind of strange that you can have something of which you are allowed to ask the truth value, but still get a boolean paradox. Any choice for a default algorithm in this case is better than a paradox, I would say? Not that I am complaining here, mind you... I never ran into this situation, and I never would have if I wasn't inspired by someone else's code to deliberately test it I'm just somewhat surprised it's a feature instead of a bug. Edited February 19, 2015 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
czardas Posted February 19, 2015 Share Posted February 19, 2015 (edited) I don't understand this statement: These keywords should not be used in expressions as AutoIt will not detect this 'misuse' and the results will be unpredictable. Is the following not an expression? Not ($bBoolean = True) Edited February 19, 2015 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2015 Moderators Share Posted February 19, 2015 czardas,I read the statement to mean that you should not mix booleans with other datatypes in the same expression - so what you have there is perfectly valid as it is all boolean. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted February 19, 2015 Share Posted February 19, 2015 Melba23: What you said there is more comprehensive than the help file. Perhaps stating that as a caution would be okay, since a certain amount of internal casting does take place when performing a comparison using the equals operator. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 19, 2015 Moderators Share Posted February 19, 2015 czardas, What you said there is more comprehensive than the help fileI should have made clear that the comment is a purely personal opinion. As I have no access to the internal AutoIt code, I can only base my comments on my own experiences of coding in AutoIt. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now