getitem* and hasitem*
Runtime builtins for chained item access. These complement the
compile-time item* macro: keylist is a runtime sequence, and
failed lookups do not expand to nested item forms.
getitem*
Syntax: (getitem* ELEMENT KEYLIST) or (getitem* ELEMENT KEYLIST DEFAULT)
Walk ELEMENT through each key in KEYLIST left to right (same
nesting shape as item*).
When DEFAULT is supplied, return it on LookupError at any step
(including KeyError and IndexError). When DEFAULT is
omitted, LookupError propagates. Other exceptions always propagate.
An empty KEYLIST raises ValueError.
(getitem* tbl #["a" "b"])
(getitem* tbl #["a" "b"] missing)
(getitem* vec #[0 1])
Keys are passed through as written, so a nested list or tuple takes integers.
hasitem*
Syntax: (hasitem* ELEMENT KEYLIST)
Walk ELEMENT through each key in KEYLIST left to right. Return
true only when every step succeeds; return false on the first failed lookup
without raising.
Any exception during lookup is treated as absent.
An empty KEYLIST raises ValueError.
(hasitem* tbl #["a" "b"])
(hasitem* vec #[0 1])
Comparison
Form |
Kind |
On missing link |
|---|---|---|
|
compile-time macro |
raises (via |
|
runtime builtin |
|
|
runtime builtin |
false |
|
runtime builtin |
chained attribute access (see getattr* and hasattr*) |
See also compile/item* and compile/attr*.