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

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

Learners doubt in LISP


From: Ganesh Swami
Subject: Learners doubt in LISP
Date: Thu, 8 Jan 2004 02:27:29 -0800

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

    RM> I have just started learning lisp.  I use emacs (which was my
    RM> motivation to learn LISP) to compile things.

    RM> There is a function in emacs called completing-read which when
    RM> passed some strings allows the user to select one string out
    RM> of the many passed. I want to allow the user select a string
    RM> and then use the data associated with the string.

    RM> eg.

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


| C-h f assoc |----------
| 
| assoc is a built-in function.
| (assoc KEY LIST)
| 
| Return non-nil if KEY is `equal' to the car of an element of LIST.
| The value is actually the first element of LIST whose car equals KEY.


Real lisping:

  (defun y-completing-read (x)
    (cadr 
     (assoc 
      (completing-read "Input: " x nil t nil) 
      x)))


Better readability:

  (defun my-completing-read (x)
    (let ((ret (completing-read "Input: " x nil t nil)))
      (cadr (assoc ret x))
      ))
    

(my-completing-read '(("hai" 10) ("bye" 20)))


cheers,
Ganesh


    RM> reads allowing completions hai and bye.

    RM> the nil t nil are insignificant (t - only allow things on the
    RM> list).

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


-- 
Ganesh Swami

If you want to get laid, go to school;
If you want to get educated, go to the library.
       -- Frank Zappa.




reply via email to

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