problem description
Here are several ways to update a val, for a dictionary key (some of which don't work)
vim9script
var key = 'foo'
var val = 'bar'
#g:[key] = val
# E1069: White space required after ':': :['foo']
#g: [key] = val
# E1241: Separator not supported: : ['foo'] = 'bar'
# works, but messy
execute "g:" .. key .. " = " .. string(val)
echo g:->get(key)
# works, non-intuitive and creating a tmp dictionary seems excessive
val = 'fubar'
g:->extend({[key]: val})
echo g:->get(key)
suggested fix:
A builtin set({dict}, {key}, {val}) is suggested
There currently may be direct ways of doing this that I have overlooked. But I have looked over (and over).
# It works with user defined function
def Set(d: dict<any>, k: string, v: any)
d[k] = v
enddef
val = 'baz'
g:->Set(key, val)
echo g:->get(key)
If this is something that has a reasonable chance of acceptance, I would take a look at implementing it. Since I've no experience patching vim, it would not be soon, especially considering the doc/testing requirement. And there's making sure the val type is OK.
For my reference
static argcheck_T arg1_dict_any[] = {arg_dict_any};
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
The simple way would be:
var key = 'foo'
var val = 'bar'
var gd = g:
gd[key] = val
Although for a dictionary set() would be a nice partner to get(), for other types it's harder.
Especially using set() on a list or blob with an invalid index would need some thinking.
Perhaps it should never produce an error but return true for success and false for failure?
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()