You could borrow syntax from PHP maybe.
Code: Select all
myMap := [
"name" => "Tedd",
"age" => 34
]
Code: Select all
myMap := [
"name" => "Tedd",
"age" => 34
]
Code: Select all
myMap := [
"name" => "Tedd",
"age" => 34
]
Code: Select all
myMap := [
name => "Tedd"
]
Code: Select all
oMap := StrSplitMap("key1,value1,key2,value2,key3,value3", ",")
oMap := StrSplitMap("1,1,2,2,3,3", ",")
oMap := StrSplitMap("1.0,1.0,2.0,2.0,3.0,3.0", ",")
vOutput := ""
for vKey, vValue in oMap
vOutput .= vKey " " vValue " " Type(vKey) " " Type(vValue) "`r`n"
Clipboard := vOutput
MsgBox(vOutput)
return
;StrSplitToMap
StrSplitMap(oParams*)
{
oArray := StrSplit(oParams*)
for vKey, vValue in oArray
{
if (vValue is "Integer")
oArray[vKey] := Integer(vValue)
else if (vValue is "Float") && !(A_Index & 1)
oArray[vKey] := Float(vValue)
}
return Map(oArray*)
}
;StrSplitToMapSimple
StrSplitMapSimple(oParams*)
{
return Map(StrSplit(oParams*)*)
}
Code: Select all
myMap := {
name: "Tedd",
age: 34
}
Code: Select all
myMap := {
(name): "Tedd",
(age): 34
}
Code: Select all
myMap := {
name: "Tedd",
age: 34
}
Code: Select all
arr := {("(key)"):value} ;marvelous :)
arr := {%"%key%"%} ;even better :D
Code: Select all
obj := object()
lexikos wrote: {a: b, c: d} is most often used to create ad-hoc objects with known properties, so these should be properties.
...
Associative arrays most often start out empty, so new syntax for an "associative array literal" seems unnecessary. The primary advantage of {x: y} is that the property names do not need to be quoted - this is consistent with obj.x and not with obj["x"]. On the other hand, the current rules also allow {"x": y} and any other expression which isn't a plain variable. Perhaps properties can require a literal_identifier: or %variable_identifier%: while array elements require [index]:.
https://github.com/Lexikos/Object.ahk
Code: Select all
adHoc := Object('dumbProp', 'plainString')
adHoc.DefineProp('smartProp', Object('get', this => "Today's date is " FormatTime(A_Now, 'MM/dd/yyyy'),
'set', (this, value) => MsgBox('Immutable property')))
adHoc.DefineMethod('printProps', Func('printProps'))
printProps(this) {
for name, value in this.OwnProps()
MsgBox name ": " value
}
Code: Select all
adHoc := {dumbProp: 'plainString'}
adHoc.DefineProp('smartProp', {get: this => "Today's date is " FormatTime(A_Now, 'MM/dd/yyyy'),
set: (this, value) => MsgBox('Immutable property')})
adHoc.DefineMethod('printProps', Func('printProps'))
printProps(this) {
for name, value in this.OwnProps()
MsgBox name ": " value
}
Code: Select all
adHoc := Object()
adHoc.DefineProp({'dumbProp': 'plainString'})