Jump to content
c.haslam

A wish regarding assignment of arrays

Recommended Posts

c.haslam

Please consider:

; These are accepted
Local $vec = ['jack','suki']
For $el in $vec
    MsgBox(0,'',$el)
Next

Local $m[]
$m['cat'] = 'jack'
msgBox(0,'',VarGetType($m.cat))

; But these are not
For $el in ['jack','suki']
    MsgBox(0,'',$el)
Next

Local $m[]
$m['cat'] = ['jack']
msgBox(0,'',VarGetType($m.cat))

I am finding many instances where the expression in a For ... In ... is a vector or where a vector is assigned to a map key.

. I am now populating a map with about 200 entries. This takes 400 lines, rather than 200, and the code would be more readable if I could assign the vectors directly to map elements.

Thoughts?

Edited by c.haslam

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
jchd

No doubt that soon @trancexx will tell you more about this kind of initializers ;)


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
iamtheky

Is this cheating and/or missing the point completely?  is the question can you reduce the number of lines with which you get everything in there?  or wanting to declare things in a for loop (of which i would like to see an example if possible)?

Local $mMap[]
$mMap['cat'] = mapappend($mMap , 'jack')
$mMap['dog'] = mapappend($mMap , 'jeff')
$mMap['pig'] = mapappend($mMap , 'john')

msgbox(0, '' , $mMap[$mMap.cat])
msgbox(0, '' , $mMap[$mMap.dog])
msgbox(0, '' , $mMap[$mMap.pig])

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
c.haslam
For $el in ['jack','suki']
    MsgBox(0,'',$el)
Next

avoids the need for the temporary variable $vec but it gives me an error.

When I run

Local $m[]
$m['cat'] = ['jack']
msgBox(0,'',VarGetType($m.cat))

I get:

$m['cat'] = ['jack','suki']
$m['cat'] = ^ ERROR

So I cannot assign a literal vector to a map entry.But

Local $m[]
Local $vec[] = ['jack','suki']
$m['cat'] = $vec
MsgBox(0,'', VarGetType($m.cat))

works as expected.

So I wish ...

Again, I have to use a temporary variable, $vec

My wish is not to have to use a temporary variable for the For .. expression, and for assigning a value to a map entry, where it is a literal vector (1D array) I am assigning.

 

Edited by c.haslam

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
iamtheky

what about with stringsplit?

For $el in stringsplit('jack , suki' , "," , 2)
    MsgBox(0, "split" , $el)
Next

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
c.haslam

Yes, your approach works. May be one day AutoIt will grant me my wish!


Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Share this post


Link to post
Share on other sites
c.haslam

IMHO, there is a situation in which literal strings and numbers are accepted but not literal arrays: as an argument to a function. I can write myfunc($vec) but not myfunc([1,2,3,4]). This limitation is unfortunate for two purposes:

  • for testing myfunc(), and
  • in a script that sometimes calls myfunc() as in myfunc($vec) and sometimes as in myfunc([1,2,3,4])

 

Edited by c.haslam

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

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

×