From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: [PATCH] Lookup functions, take two Date: Wed, 26 Sep 2012 00:43:27 +0200 Message-ID: <873925g1v4.fsf@bzg.ath.cx> References: <87y5k0g3qc.fsf@syk.fi> <878vbxao4r.fsf@Rainer.invalid> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGdqg-0001H8-QU for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 18:43:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGdqf-0002cI-HU for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 18:43:26 -0400 Received: from mail-we0-f169.google.com ([74.125.82.169]:44203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGdqf-0002cB-8G for emacs-orgmode@gnu.org; Tue, 25 Sep 2012 18:43:25 -0400 Received: by weyu3 with SMTP id u3so3083585wey.0 for ; Tue, 25 Sep 2012 15:43:24 -0700 (PDT) In-Reply-To: <878vbxao4r.fsf@Rainer.invalid> (Achim Gratz's message of "Tue, 25 Sep 2012 21:39:00 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Achim Gratz Cc: emacs-orgmode@gnu.org Achim Gratz writes: > You could ask on the Emacs devel list if that'd be OK. I suggest using this code: (defun org-lookup (val s-list r-list lastp &optional predicate) "Look for VAL in S-LIST and return the corresponding element in R-LIST. If LASTP, ignore all matching VAL in SEARCH-LIST except the last one. If PREDICATE is not nil, use this instead of `equal' to match VAL." (let ((p (or predicate 'equal)) (c 0) r) (nth (dolist (i search-list r) (setq c (1+ c)) (if (and (funcall p val i) (or lastp (not r))) (setq r (1- c)))) return-list))) (defun org-lookup-first (val s-list r-list &optional predicate) "Look for VAL in S-LIST and return the corresponding element in R-LIST. If PREDICATE is not nil, use this instead of `equal' to match VAL." (org-lookup val s-list r-list nil predicate)) (defun org-lookup-last (val s-list r-list &optional predicate) "Look for VAL in S-LIST and return the corresponding element in R-LIST. If PREDICATE is not nil, use this instead of `equal' to match VAL." (org-lookup val s-list r-list t predicate)) ;; (org-lookup-first 2 '(1 2 3 2) '(A B C D E)) => B ;; (org-lookup-last 2 '(1 2 3 2) '(A B C D E)) => D No `cl-position' anymore. Less dense and elegant, of course, but more explicit. Users will be able to check the docstring of org-lookup-first/last, which I think is good for functions that we advertize in the manual. Jarmo, would you be okay if I commit this? Then you can commit a <20 lines patch for the documentation :) Or you commit the code (19 lines!) and I commit the doc patch, as you want! Thanks, -- Bastien