Suppose I've got an assoc-list like this:
(setq x '((foo . ((bar . "llama")
(baz . "monkey")))))
And I want the value at bar
. I can do this:
(assoc-default 'bar (assoc-default 'foo x))
But what I'd really like is something that accepts multiple keys, like
(assoc-multi-key 'foo 'bar x)
Does such a thing exist, perhaps in a package somewhere? I'm sure I could write it, but I feel like my Google-fu is just failing and I can't find it.
assoc-multi-key
. Presumably it looks for matches to both of its first two arguments, but that's really all that one could suppose, from what you've said. And it clearly cannot accept more than two keys, since the alist argument (presumablyx
) is the last one, not the first one - which suggests that it is not too useful in general. Try actually specifying what you are looking for.setq
form in the example confusing, so I edited it to use the common dot-notation for assoc-lists.assoc-multi-key
remains unspecified.assoc-multi-key
is to look up the first key in the assoc-list. This should resolve to a new assoc-list in which we look up the next key. And so forth. Basically a short-hand for digging values out of nested assoc-lists.let-alist
too? e.g.(let-alist '((foo . ((bar . "llama") (baz . "monkey")))) .foo.bar)
will return"llama"
. I guess you wrotelet-alist
after the question was asked, but it's in the spirit of the question and very worth mentionning IMO!