There was a link to a book on this group some time ago, giving some
practical eamples of how to use lisp. One example was on how to build up
a database of your CD collection, or something.
In it, they gave a method for finding the value in a list whose elements
were stored in key - value order. The problem is, I can't remember the
name of the book, or the function. Any pointers?
So, for example, I've got a list lst that looks like this:
(TIME (5 51 14 23 4 2005 5 T 0) REMOTE "100.10.10.10" WEBSITENAME "dfgv"
DESCRIPTION "describes the website" URL NIL)
Suppose I want to be able to extract the description. I want to do
something like
(wtf-is-it-called lst 'DESCRIPTION)
and have it return the value
"describes the website"
What function should I be using instead of wtf-is-it-called?
Sorry for such a n00b question.
In article <·························@news.sunsite.dk>,
Mark Carter <···········@yahoo.co.uk> wrote:
> There was a link to a book on this group some time ago, giving some
> practical eamples of how to use lisp. One example was on how to build up
> a database of your CD collection, or something.
Possibly Seibel's Practical Common Lisp
>
> In it, they gave a method for finding the value in a list whose elements
> were stored in key - value order. The problem is, I can't remember the
> name of the book, or the function. Any pointers?
>
> So, for example, I've got a list lst that looks like this:
> (TIME (5 51 14 23 4 2005 5 T 0) REMOTE "100.10.10.10" WEBSITENAME "dfgv"
> DESCRIPTION "describes the website" URL NIL)
>
> Suppose I want to be able to extract the description. I want to do
> something like
> (wtf-is-it-called lst 'DESCRIPTION)
> and have it return the value
> "describes the website"
>
> What function should I be using instead of wtf-is-it-called?
getf
Chris Riesbeck wrote:
> Mark Carter <···········@yahoo.co.uk> wrote:
>>What function should I be using instead of wtf-is-it-called?
> getf
Many thanks. That hit the spot!
No doubt it's obvious that I'm new to Lisp. I've decided to write a
small webapp in CLISP on Debian. I decided to do without databases, so
what happens is that a user can log new records. Another process comes
along and does some aggregation on them. The beauty of Lisp is that it
it's all done as sexprs, so I don't have any parsing problems. It's all
just Lisp.
From: Sam Steingold
Subject: Re: Extracting key-values from a list
Date:
Message-ID: <u8y35cnas.fsf@gnu.org>
> * Mark Carter <···········@lnubb.pb.hx> [2005-04-26 20:30:50 +0100]:
>
> No doubt it's obvious that I'm new to Lisp. I've decided to write a
> small webapp in CLISP on Debian. I decided to do without databases, so
> what happens is that a user can log new records. Another process comes
> along and does some aggregation on them. The beauty of Lisp is that it
> it's all done as sexprs, so I don't have any parsing problems. It's
> all just Lisp.
note that you can use alists (association lists)
<http://www.lisp.org/HyperSpec/Body/fun_assoccm_a_assoc-if-not.html>
or hash tables <http://www.lisp.org/HyperSpec/Body/acc_gethash.html>
instead of plists (property lists)
<http://www.lisp.org/HyperSpec/Body/acc_getf.html>
(both hash tables and association lists are printed as SEXPs in CLISP).
Good luck!
--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://pmw.org.il/> <http://www.openvotingconsortium.org/>
<http://ffii.org/> <http://www.honestreporting.com>
Why do we want intelligent terminals when there are so many stupid users?
Sam Steingold wrote:
>>* Mark Carter <···········@lnubb.pb.hx> [2005-04-26 20:30:50 +0100]:
>>
>>No doubt it's obvious that I'm new to Lisp. I've decided to write a
>>small webapp in CLISP on Debian. I decided to do without databases, so
>>what happens is that a user can log new records. Another process comes
>>along and does some aggregation on them. The beauty of Lisp is that it
>>it's all done as sexprs, so I don't have any parsing problems. It's
>>all just Lisp.
>
>
> note that you can use alists (association lists)
> <http://www.lisp.org/HyperSpec/Body/fun_assoccm_a_assoc-if-not.html>
> or hash tables <http://www.lisp.org/HyperSpec/Body/acc_gethash.html>
> instead of plists (property lists)
> <http://www.lisp.org/HyperSpec/Body/acc_getf.html>
>
> (both hash tables and association lists are printed as SEXPs in CLISP).
>
> Good luck!
Many thanks.
I just had a look at Paul Graham's Lisp in Web-Based Applications:
http://lib.store.yahoo.com/lib/paulgraham/bbnexcerpts.txt
Like Graham, I am taking an incremental approach to building a web app.
Unlike Graham, I'm not currently using macros, or expect to become a
millionaire from it :( .
Actually, I find that I need to take an incremental approach anyway,
because I am quite unfamiliar with Lisp. So everything is a bit more
ponderous for me. I note, however, that by using my approach of logged
lists, rather than say MySql, I can be much more experimental, and
expand and change my design as I become more familiar with the
problem-space.
OTOH, maybe one man's bottom-up design methodology is another man's lack
of foresight. ;)
On Tue, 26 Apr 2005 17:47:27 +0100, Mark Carter
<···········@yahoo.co.uk> wrote:
>What function should I be using instead of wtf-is-it-called?
That list is a plist. The standard Common Lisp function to get an
item from it is "getf". E.g. (getf list 'description)
Mark Carter <···········@yahoo.co.uk> writes:
> There was a link to a book on this group some time ago, giving some
> practical eamples of how to use lisp. One example was on how to build
> up a database of your CD collection, or something.
Practical Common Lisp
http://www.gigamonkeys.com/book
Paolo
--
Why Lisp? http://lisp.tech.coop/RtL%20Highlight%20Film
Recommended Common Lisp libraries/tools (see also http://clrfi.alu.org):
- ASDF/ASDF-INSTALL: system building/installation
- CL-PPCRE: regular expressions
- UFFI: Foreign Function Interface