One down side is that if you want case insensitive keys then you must:
Code: Select all
obj := Map()
obj.CaseSense := false
obj[key] := value
obj[key2] := value2
...
Code: Select all
obj := Map()
obj.CaseSense := false
obj[key] := value
obj[key2] := value2
...
Code: Select all
Mip(p*) {
m := Map()
m.CaseSense := false
loop p.Length//2
m[p[A_Index*2-1]] := p[A_Index*2]
return m
}
MsgBox Mip('A', 'b')['a'] ; b
Code: Select all
Mip(p*) {
m := Map()
m.CaseSense := false
return m.Set(p*)
}
Code: Select all
Mip(p*) => (m := Map(), m.CaseSense := false, m.Set(p*))
MsgBox Mip('A', 'b')['a'] ; b
Code: Select all
class Mip extends Map {
CaseSense := false
}
MsgBox Mip('A', 'b')['a'] ; b
BTW, I suppose CaseSense's "On"/"Off" needs to be addressed:
Nope.vvhitevvizard wrote: ↑24 Apr 2021, 05:35BTW, I suppose CaseSense's "On"/"Off" needs to be addressed ... Because u unified it and removed literal strings for such boolean switches overall.
I'm aware it has the 3rd option thus making it not suitable for binary logic.
Would you change the several functions I mentioned as well, splitting their CaseSense parameter into two parameters? If not, I suppose that's the opposite of unification. Even if things are "more unified", specifically how is it helpful?That would unify the overall pattern,
How so? Perhaps you can demonstrate.and dramatically alleviate filling these switches programmatically.
Code: Select all
a := Map("a", "AAPL", "b", "BA", "c", "CHWY")
fn(a*)
fn(p*) {
for i, v in p
MsgBox i ", " v
}
Code: Select all
map := [
"key1" : "value1",
"key2" : "value2",
...
]
Code: Select all
api.headers := Map("Content-Type", "application/x-www-form-urlencoded",
"WWW-Authenticate","Basic")
Code: Select all
api.headers := {"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
Code: Select all
; any of these modifications would be appreciated as there is less to type/modify after
; I foolishly wrote all my ad-hoc object in the old notation.
api.headers := ["Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"]
api.headers := ${"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
api.headers := map{"Content-Type": "application/x-www-form-urlencoded", "WWW-Authenticate":"Basic"}
I think these are very good pointsEverything that makes the programmer's intention clear is a good thing, and a "function call"-like statement does not convey the associative nature of a map.
That is close to what I do,I do understand that we could easily do this:Code: Select all
api.headers := Map("Content-Type", "application/x-www-form-urlencoded", "WWW-Authenticate","Basic")
Code: Select all
api.headers := Map(
"Content-Type", "application/x-www-form-urlencoded",
"WWW-Authenticate", "Basic"
)
Oh yeah dont get me wrong, i also do that... the annoyance comes when you are trying to convert a JSON object that you copy pasted or an existing v1 code to v2.Helgef wrote: ↑11 Apr 2022, 03:48I think it good enough.Code: Select all
api.headers := Map( "Content-Type", "application/x-www-form-urlencoded", "WWW-Authenticate", "Basic" )
Cheers.
Code: Select all
headers := { "Host" : "www.facebook.com"
, "Connection" : "keep-alive"
, "Origin" : "https://www.facebook.com"
, "Upgrade-Insecure-Requests": "1"
, "Content-Type" : "application/x-www-form-urlencoded"
, "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
, "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*"
, "Sec-Fetch-Mode" : "navigate"
, "Sec-Fetch-User" : "?1"
, "Sec-Fetch-Dest" : "document"
, "Referer" : "https://www.facebook.com/groups/agroup/member-requests"
, "Cache-Control" : "max-age=0"
, "Cookie" : cookie1
, "DNT" : "1"
, "Sec-Fetch-Site" : "same-origin"}
Code: Select all
headers := map{ "Host" : "www.facebook.com"
; ...
}
Code: Select all
Python: {"key": value}
Lua tables: {key = value}
Powershell: @{ key = value }
JavaScript: {key: value}
Json: {"key": "value"}
Dart: {key:value}
go: map[string]T {"key": T}
Code: Select all
{
"key1": 42,
"key2": "hello",
"key3": {
"innerKey": 3.14
}
}
Code: Select all
@{
key1: value1,
key2: value2
}
I think you mean reconsider, and no. It's too late, and I would stand by my original choice anyway.I hope you'll consider using the { } for map literals, and migrating the object literal to another syntax.
Don't expect v3 (for real) any time soon.v2.0 beta 1 was released in July 2021. Changes prior to the final v2.0.0 release should be of a minor nature (such as improvements to the error and warning dialogs), and should not affect the functionality of scripts. In other words, future releases are expected to be backward-compatible.
Source: AutoHotkey v2
Don't expect v3 (for real) any time soon.
I would definitely overcome my annoyance at how ugly it might look and use it for the convenience of copying JSON strings from anywhere on the web and having a native AHK object out of it.iseahound wrote: ↑03 May 2022, 11:05What about m := Map({key: value}) ? This doesn't add any new syntax, just converts from an object into a dictionary. It would be useful to have such a conversion, (perhaps for serialization?), regardless. It answers the main issue of the map shorthand question: copying a JSON object into AHK with minimal fuss.
Code: Select all
json := load(string)
value := json["key"]["anotherkey"]["someadditionalkey"]
I think thats where the problem might arise, handling arrays and keys in a logical way.