Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ${(k)widgets} v. 'zle -la'



On Jul 7,  2:00am, Daniel Shahaf wrote:
}
} Is the following behaviour also intentional?  Testing a key's presence
} in the associative array in different ways gives different results:
} 
}     % bindkey foo bar
}     % () { print $(( $argv[(I)bar] > 0 )) } ${(k)widgets}
}     1
}     % print ${+widgets[bar]}
}     0

It's intentional in that hash table entries are parameter values and
parameters can exist but be unset, like declaring something local and
then unsetting it; $widgets[bar] returns a "value" that is equivalent
to "unset" when the widget doesn't exist.

It's not intentional in that for normal hash tables there's no way to
create such an entry, so the ramifications on e.g. ${+...} of having
a special hash where a key that is present is only a placeholder, were
not fully thought through.

On the other hand it's the only result that accurately represents the
situation.

-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author