From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Ganesh Swami Newsgroups: gmane.emacs.help Subject: Learners doubt in LISP Date: Thu, 8 Jan 2004 02:27:29 -0800 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <16381.12433.72353.855468@desktop.localhost> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1073557647 19166 80.91.224.253 (8 Jan 2004 10:27:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 8 Jan 2004 10:27:27 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 08 11:27:19 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AeXNn-0001GJ-00 for ; Thu, 08 Jan 2004 11:27:19 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AeYJM-0006jL-6E for geh-help-gnu-emacs@m.gmane.org; Thu, 08 Jan 2004 06:26:48 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AeYI2-0006dh-BB for help-gnu-emacs@gnu.org; Thu, 08 Jan 2004 06:25:26 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AeYHS-0006GL-5c for help-gnu-emacs@gnu.org; Thu, 08 Jan 2004 06:25:21 -0500 Original-Received: from [24.207.1.134] (helo=yoda.dccnet.com) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AeY7W-00034b-5i for help-gnu-emacs@gnu.org; Thu, 08 Jan 2004 06:14:34 -0500 Original-Received: from desktop.localhost.iamganesh.com (unverified [24.207.66.212]) by dccnet.com (Rockliffe SMTPRA 5.3.6) with ESMTP id ; Thu, 8 Jan 2004 02:13:03 -0800 Original-To: Rajsekar Manokaran Original-Newsgroups: gnu.emacs.help In-Reply-To: X-Mailer: VM 7.18 under Emacs 21.3.50.2 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:15808 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15808 >>>>> "RM" == Rajsekar Manokaran 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.