Modify

Opened 3 years ago

Last modified 2 years ago

#3969 new Feature Request

Map Initializer List

Reported by: anonymous Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Map, Initializer List Cc:

Description (last modified by mLipok)

; For Arrays, we can use
Global $a = [1, 2, 3]
; or
Global $a[] = [1, 2, 3]
; or
Global $a[3] = [1, 2, 3]

; But if we create a Map, it is always empty, and there is no good way to initialize Maps. So here is a suggestion:

Global $a["key1", "key2", "key3"] = [1, 2, 3]

; is the same as

Global $a[]
$a["key1"] = 1
$a["key2"] = 2
$a["key3"] = 3

; I'm sure we do not "need" this feature, but it would be nice to have. (the same argument could be made for Array-Initialization with initializer list... we do not "need" it, but it is nice that it exists)

Attachments (0)

Change History (8)

comment:1 by anonymous, 3 years ago

; Addition: If the right side is missing, the map is initialized with empty strings for every key.

Global $a["key1", ..., "keyN"]
If MapExists($a, "key1") -> True.

; This enables compact and easy to use string lookup-tables.

comment:2 by mLipok, 3 years ago

Description: modified (diff)

comment:3 by Andreik, 2 years ago

I use maps very often and I would like to see a map initializer but I don't know if it's possible without introducing a new operator, a keyword or something. It will be a total confusion. Take this as example:

Global $Var[1] = [5]

Right now this is a valid syntax to initialize an array with one element but it could be as well a map with the key name 1 (according to proposed syntax).

comment:4 by vanowm <fromautoitscript.comid240211@…>, 2 years ago

Another reasoning to have such feature is ability create constant maps. Currently we have to create a temporary map, populate it, then copy it to a constant.:

; create temporary map
Local $a[]
$a["key1"] = 1
$a["key2"] = 2
$a["key3"] = 3

; copy to a constant
Global Const $b = $a
; clean up
$a = null

comment:5 by anonymous, 2 years ago

Please consider this proposition of a good non-ambiguous syntax:

Dim $map["prime": 101,  -1: "-one",  $hMyGUI: $aSomeAssociatedData]

-- or (which can be an allowed alternative, just like arrays have two ways to define 'em) --

Dim $map[] = ["prime": 101,  -1: "-one",  $hMyGUI: $aSomeAssociatedData]

comment:6 by anonymous, 2 years ago

also

Dim $map = ["prime": 101,  -1: "-one",  $hMyGUI: $vSomeAssosiatedData]

comment:7 by Andreik, 2 years ago

The syntax might work but the examples are bad since AutoIt maps are designed to work with integers and strings, not with handles or other data types as keys.

comment:8 by anonymous, 2 years ago

Andreik, that only means that the maps are poorly designed -- and NOTHING else. It's not necessarily anyone's fault/guilt; after all, obtaining perfection(or even just good-enough-ness) is a progress (and i hasten to say that the maps in their current form are NOT good-enough: to be blunt, they're literally a worser version of Scripting.Dictionary -- that's it.) We're all now got involved(if only in spirit) in making maps progress further making them the best they can be(in bed AutoIt); now lets be optimistic and hope/believe it will be crowned with a resounding success!! :]

Modify Ticket

Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.