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

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

Re: Learners doubt in LISP


From: Joakim Hove
Subject: Re: Learners doubt in LISP
Date: Thu, 08 Jan 2004 10:22:08 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Rajsekar Manokaran <rajsekar_manokaran@yahoo.co.uk> writes:


> (completing-read "Input: " '(("hai" 10) ("bye" 20)) nil t nil)

[...]

> Now this thing seems to return "bye" or "hai"
> How do I access the 10 or 20 that comes together with it?

    (let* ((alist '(("hai" 10) ("bye" 20)))
           (key     (completing-read "Input: alist nil t nil))
           (value   (nth 1 (assoc-string key alist))))

        ;; Key and value defined in this scope.
 
    )


The function (assoc-string) returns the whole pair, and (nth 1 )
selects the last one. (Maybe a function to perform this combination
already exists?)


HTH - Joakim



-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/


reply via email to

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