TomSW <tom.weissmann@gmail.com> wrote:
+---------------
| I've recently started programming Lisp at work, and often find myself
| having to unpack a data structure (eg, a plist containing plists
| containing lists) and then filter and process it as a list.
|
| It strikes me this is a kind of data query, and I was wondering if
| there was a neat way to do it, a kind of SQL for objects. ...
+---------------
Have you bought/read Peter Seibel's "Practical Common Lisp" yet?
It sounds like the simple in-memory database shown in Chapter 3
might be just what you're looking for. It starts from scratch and
works up to being able to write SQL-ish queries such as this one:
CL-USER> (select (where :title "Give Us a Break" :ripped t))
((:TITLE "Give Us a Break" :ARTIST "Limpopo" :RATING 10 :RIPPED T))
Chapter 27 takes this further, introducing multiple tables, schema
definitions, and a richer SELECT operator [that also returns tables
as its results, which can be fed to other SELECTs, etc.], e.g.:
;; Select a sorted list of artists with songs in the genre "Rock"
(select
:columns :artist
:from *mp3s*
:where (matching *mp3s* :genre "Rock")
:distinct t
:order-by :artist)
-Rob
p.s. Oh, o.k., you can also read Chapters 3 & 27 here:
http://gigamonkeys.com/book/practical-a-simple-database.html
http://gigamonkeys.com/book/practical-an-mp3-database.html
But buy the hardcopy book anyway. It's worth it.
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607