jguinch

Array declaration error (new behavior): Can not initialize a variable with itself

25 posts in this topic

Hello all.

Sometimes, i use this kind of array declaration :

Local $a = [1, $a[0] ]

This method of declaration worked before (I don't know which version, few monthes ago).

Is it a desired behavior, or a bug ?

Share this post


Link to post
Share on other sites



jguinch,

I am quite surprised that you say it used to work - I seem to remember this being discussed some time ago and the general consensus at the time was that such behaviour was not a good idea. So I would say: "feature", not "bug"

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Of course it worked. The feature was controlled by Opt("MustDeclareVars").

This is script breaking change, which apparently isn't documented. If there was "general consensus" on this, then I question the ability of participants to make decisions like that.

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

jguinch,

It seems my memory was not correct in this instance - sorry to have misled you.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ahh, note it is possible do use something like this to skip this restriction :

Local $a = [1, Execute("$a[0]") ]

That isn't a viable solution because Execute() interprets the input as if it were a string - who knows what kind of data that will return.

I also have to agree with trancexx: it seems odd that this doesn't simply work out of the box. I am surprised that this (apparently logical) syntax no longer works.

Edited by czardas

Share this post


Link to post
Share on other sites

Yes czardas, I tought about that. I made some tests before my previous post and it seems to be not so bad : 

#include <Array.au3>

Local $b = [1, "a", ObjCreate("shell.application"), WinList(), True, Binary("0x00204060") , DllStructCreate("int;"), WinGetHandle("[ACTIVE]"), MsgBox, 3.14159, 50, _ 
            Execute("$b[0]"), Execute("$b[1]"), Execute("$b[2]"), Execute("$b[3]"), Execute("$b[4]"), Execute("$b[5]"), Execute("$b[6]"), Execute("$b[7]"), Execute("$b[8]"), Execute("$b[9]") ]


ConsoleWrite("$b[11] is an integer ? "  & IsInt($b[11]) & @CRLF)
ConsoleWrite("$b[12] is a string ? "    & IsString($b[12]) & @CRLF)
ConsoleWrite("$b[13] is an object ? "   & IsObj($b[13]) & @CRLF)
ConsoleWrite("$b[14] is an array ? "    & IsArray($b[14]) & @CRLF)
ConsoleWrite("$b[15] is boolean ? "     & IsBool($b[15]) & @CRLF)
ConsoleWrite("$b[16] is binary ? "      & IsBinary($b[16]) & @CRLF)
ConsoleWrite("$b[17] is a structure ? " & IsDllStruct($b[17]) & @CRLF)
ConsoleWrite("$b[18] is a handle ? "    & IsHWnd($b[18]) & @CRLF)
ConsoleWrite("$b[18] is pointer ? "     & IsPtr($b[18]) & @CRLF)
ConsoleWrite("$b[19] is function ? "    & IsFunc($b[19]) & @CRLF)
ConsoleWrite("$b[20] is float ? "       & IsFloat($b[20]) & @CRLF)
ConsoleWrite("$b[21] is number ? "      & IsNumber($b[21]) & @CRLF)

_ArrayDisplay($b)

 

1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Duh you are right, now I see my mistake. It's rather odd that the elements can't be referenced directly, yet they can still be accessed using Execute().

Edited by czardas

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I wasn't aware of these restrictions on variable redeclaration. I thought the full expression was parsed evaluated before any impact on the original. That would seem consistent (syntax).

;Local $sStr = "string"
;Local $sStr = $sStr & $sStr ; error

$sStr = "string"
$sStr = $sStr & $sStr ; assignment works alright here


Edit: Perhaps it's just simpler for things to be the way they are.

Edited by czardas

Share this post


Link to post
Share on other sites

I revise what I said in post #8. This is less intuitive than I at first thought: self-referencing (previous post) is not the same as back-referencing (first post). The syntax simply looked as though it ought to do something, although I haven't used it myself. I can see it being useful in both cases, but I don't know how other languages deal with this kind of thing.

Share this post


Link to post
Share on other sites

^^ For example, intuitive as you are, do you think C/C++ allows this:

char czardas[] = { 99, 122, 97, 114, 100, czardas[2], 115, 0 };

 

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Hi,

I have been racking my ageing brain trying to come up with a use case when such a "self-initialisation" functionality would be required - and signally failing to do so. The other thread participants appear to believe that the functionality should still exist, so could one of them please provide a sensible real-world example - rather than the "fun" scripts linked to in post #4 above.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I would say that sensible real-world example would be any script that used to work and now it doesn't.

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

The code that was referenced earlier, my code, worked in v3.3.12.0 (just tested it a second a go). So seems to be a bug with the latest version.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now