From: Jonathon McKitrick
Subject: Best way to convert query to property list
Date: 
Message-ID: <1152034407.889062.226130@m73g2000cwd.googlegroups.com>
I know this has to be simple, but the approaches I'm trying just aren't
working for some reason.

I'm querying a db and getting a list of 2-item lists of properties:

( ("property1" "val1") ("property2" "val2") ...)

What I want is either a hash, plist, or alist, whatever makes the most
sense for a throwaway result that will let me get the value for any
property but not save the whole structure when I'm done with it.  It
seems a hash would be overkill, but I could be wrong.

I thought this would create the plist I wanted, but I was wrong:

(loop for prop in props collect (mapcar #'append prop))

It just gives me the exact same list as went into it.

From: Carl Taylor
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <cPxqg.314000$Fs1.211625@bgtnsc05-news.ops.worldnet.att.net>
"Jonathon McKitrick" <···········@bigfoot.com> wrote in message 
·····························@m73g2000cwd.googlegroups.com...
>
> I know this has to be simple, but the approaches I'm trying just aren't
> working for some reason.
>
> I'm querying a db and getting a list of 2-item lists of properties:
>
> ( ("property1" "val1") ("property2" "val2") ...)
>
> What I want is either a hash, plist, or alist, whatever makes the most
> sense for a throwaway result that will let me get the value for any
> property but not save the whole structure when I'm done with it.  It
> seems a hash would be overkill, but I could be wrong.
>
> I thought this would create the plist I wanted, but I was wrong:
>
> (loop for prop in props collect (mapcar #'append prop))
>
> It just gives me the exact same list as went into it.


CL-USER 4 >
(apply #'nconc '( ("property1" "val1") ("property2" "val2")))
("property1" "val1" "property2" "val2")

Carl Taylor
From: Pascal Bourguignon
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <87wtats1gx.fsf@thalassa.informatimago.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> I know this has to be simple, but the approaches I'm trying just aren't
> working for some reason.
>
> I'm querying a db and getting a list of 2-item lists of properties:
>
> ( ("property1" "val1") ("property2" "val2") ...)
>
> What I want is either a hash, plist, or alist, whatever makes the most
> sense for a throwaway result that will let me get the value for any
> property but not save the whole structure when I'm done with it.  It
> seems a hash would be overkill, but I could be wrong.
>
> I thought this would create the plist I wanted, but I was wrong:
>
> (loop for prop in props collect (mapcar #'append prop))
>
> It just gives me the exact same list as went into it.

You already have an a-list.

(second (assoc "property1" '(("property1" "val1") ("property2" "val2") )
               :test (function string=)))
--> "val1"


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.
From: Jonathon McKitrick
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <1152039434.299249.25960@m73g2000cwd.googlegroups.com>
Pascal Bourguignon wrote:
> You already have an a-list.
>
> (second (assoc "property1" '(("property1" "val1") ("property2" "val2") )
>                :test (function string=)))
> --> "val1"

I knew in was simple, but not that simple!!

I thought cons cells had to be specifically created as such?
From: Ari Johnson
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <m21wt1i3hv.fsf@hermes.theari.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> Pascal Bourguignon wrote:
>> You already have an a-list.
>>
>> (second (assoc "property1" '(("property1" "val1") ("property2" "val2") )
>>                :test (function string=)))
>> --> "val1"
>
> I knew in was simple, but not that simple!!
>
> I thought cons cells had to be specifically created as such?

Just to expound on what Pascal has already said:

(cons (cons "property1" (cons "val1" '()))
  (cons (cons "property2" (cons "val2" '()))
    '()))
 ==>
(("property1" "val1") ("property2" "val2"))

The cons cells were created as such by whatever gave you that list of
lists to begin with, so you were correct.
From: Pascal Bourguignon
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <87odw5rxz8.fsf@thalassa.informatimago.com>
"Jonathon McKitrick" <···········@bigfoot.com> writes:

> Pascal Bourguignon wrote:
>> You already have an a-list.
>>
>> (second (assoc "property1" '(("property1" "val1") ("property2" "val2") )
>>                :test (function string=)))
>> --> "val1"
>
> I knew in was simple, but not that simple!!
>
> I thought cons cells had to be specifically created as such?

Lists are made of cons cells.

("property1" "val1") == ("property1" . ( "val1" . () ))

Usually, you get the value of an assoc with CDR:

     (cdr (assoc key a-list))

that is, if you had a-list == ((prop1 . val1) (prop2 . val2) ...)


But since your couples are stored in lists (eg 2 cons cells instead of
one cons cell), we must use CADR (= SECOND) instead of CDR, that's all.

If we still used CDR, we'd simply get the list ("val1") instead of "val1".

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
From: Jonathon McKitrick
Subject: Re: Best way to convert query to property list
Date: 
Message-ID: <1152039595.121359.26280@a14g2000cwb.googlegroups.com>
Pascal Bourguignon wrote:
> You already have an a-list.
>
> (second (assoc "property1" '(("property1" "val1") ("property2" "val2") )
>                :test (function string=)))
> --> "val1"

I knew in was simple, but not that simple!!

I thought cons cells had to be specifically created as such?