help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to remove verbosity from the data passing mechanism using alist


From: PJ Weisberg
Subject: Re: How to remove verbosity from the data passing mechanism using alist or plist ?
Date: Mon, 6 Dec 2010 23:59:31 -0800

On Mon, Dec 6, 2010 at 10:18 PM, Fren Zeee <frenzeee@gmail.com> wrote:

>>   [Q] Is there a way to avoid lengthy calling statement like
>>         (car (assoc-default :GOLD-value    GOLD )
>>       inside let,
>>
>>       since the first argument of let is an alist of the form
>>            ((sym1 val1) (sym2 val2))
>>
>
> OK lets take the suggestion below and show me how it works with my case ?
>
>> You need the ‘car’ because you do ‘(list k v)’.
>> If you use ‘(cons k v)’, then you do not need the ‘car’.
>
> What I have is
>
> (list (list k1 v1) (list k2 v2))
>
> Now, kindly show me where I put the car to get both of these uniformly
> communicated outside of the function to another function ? Later in
> some cases I may have (k3 v3) pair !!!

Don't put the car anywhere.  Change that to (list (cons k1 v1) (cons
k2 v2)) and then use use (assoc-default k1 myList), (assoc-default k2
myList), etc.

With that sexp you gave earlier,

(assoc-default 'y '((w . 0) (x . 1) (y . 2) (z . 3)))

Now it returns 2 instead of (2), so if you wanted the number you don't
need car to get it.

I think you were asking the difference between cons and list, and I
was going to write some kind of explanation, but apparently the part
of my brain that's capable of explaining things clearly has already
gone to sleep, so before I turn in I'll just say that lisp uses linked
lists with one "cons cell" for each item in the list, and those things
that look like lists but have dots in them are a result of someone
abusing "cons" to make a cons cell whose 'next' pointer points to
something other than the next cons cell in a list.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]