I was wondering how I could find a value in an association list recursively, even if this value is inside a vector. Let me give you an example. I have this list (response from the Discogs API), let's call it discogs
Code: Select all
((resp (version . "2.0")
(release
(data_quality . "Correct")
(tracklist . [... ... ...])
(master_id . 18609)
(resource_url . "http://api.discogs.com/releases/798045")
(formats . [...])
(artists . [...])
(uri . "http://www.discogs.com/Photek-Natural-Born-Killa-EP/release/798045")
(companies . [])
(notes . "...")
(country . "UK")
(title . "Natural Born Killa EP") ...)
(status . t)))
Code: Select all
(defun tree-assoc (key tree)
(when (consp tree)
(destructuring-bind (x . y) tree
(if (eql x key) tree
(or (tree-assoc key x) (tree-assoc key y))))))
Code: Select all
(cdr (tree-assoc 'title discogs))
However, the name of the artist is inside a vector, in the cons cell (artists . [...]). This vector contains another nested list, like this:
Code: Select all
[((id . 417) (resource_url . "http://api.discogs.com/artists/417") (role . "") (tracks . "") (anv . "") (name . "Photek") (join . ""))]
Thanks,
Beltxarga