Christian J. Robinson wrote:
> vim9script
>
> def Foo(bar: dict<string>)
> if exists('bar["a"]')
> echo "it exists"
> else
> echo "it doesn't exist"
> endif
> enddef
>
> Foo({'a': '...'})
> Foo({'b': '...'})
>
> This should echo:
>
> it exists
> it doesn’t exist
>
> But it echoes:
>
> it doesn’t exist
> it doesn’t exist
>
> I have tried all kinds of combinations, including checking for
> l:bar[“a”] and a:bar[“a”]. The only thing that works is to assign the
> bar argument to a global variable and testing that instead, but that’s
> a kluge.
Correct, function arguments are not visibile to exists() in a compiled
function. I notice that this isn't mentioned in the help, I'll update
that.
You should has has_key():
if bar->has_key("a")
echo 'it exists'
--
hundred-and-one symptoms of being an internet addict:
255. You work for a newspaper and your editor asks you to write an
article about Internet addiction...in the "first person."
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202107280952.16S9qQTj1824954%40masaka.moolenaar.net.