From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jarmo Hurri Subject: Re: [PATCH] Lookup functions, take two Date: Wed, 26 Sep 2012 16:45:40 +0300 Message-ID: <87txukyk1n.fsf@syk.fi> References: <87y5k0g3qc.fsf@syk.fi> <878vbxao4r.fsf@Rainer.invalid> <873925g1v4.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGrwC-0008RW-EN for emacs-orgmode@gnu.org; Wed, 26 Sep 2012 09:46:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGrw2-0006y7-9F for emacs-orgmode@gnu.org; Wed, 26 Sep 2012 09:46:04 -0400 Received: from plane.gmane.org ([80.91.229.3]:33685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGrw2-0006wb-1W for emacs-orgmode@gnu.org; Wed, 26 Sep 2012 09:45:54 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TGrw4-0006uV-6y for emacs-orgmode@gnu.org; Wed, 26 Sep 2012 15:45:56 +0200 Received: from host-137-163-18-130.edu.hel.fi ([137.163.18.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 26 Sep 2012 15:45:56 +0200 Received: from jarmo.hurri by host-137-163-18-130.edu.hel.fi with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 26 Sep 2012 15:45:56 +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: emacs-orgmode@gnu.org Bastien writes: > I suggest using this code: > > ... > > 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? I have nothing against the idea. However, I get only errors when I try to apply your functions in my examples. I can track down the source of the problems later (not today, though). But how about combining your idea about getting rid of CL's position with the following idea of building the docstring on the fly in the macro? That is, you do not need to define multiple functions by hand, but the docstrings can still be unique. #+BEGIN_SRC emacs-lisp (defmacro org-lookup-function (name-str from-end-p) `(defun ,(intern (format "org-lookup-%s" name-str)) (val search-list return-list &optional predicate) ,(format "Searches for the %s element el in list search-list for which (predicate val el) is t; returns a value from the corresponding position in list return-list. The default predicate is equal." (if from-end-p "last" "first")) (let ((p (if (eq predicate nil) 'equal predicate))) (nth (position val search-list :test p :from-end ,from-end-p) return-list)))) (org-lookup-function "first" nil) (org-lookup-function "last" t) #+END_SRC -- Jarmo