[Top][All Lists]

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

Re: [O] [PATCH] Lookup functions, take two

From: Jarmo Hurri
Subject: Re: [O] [PATCH] Lookup functions, take two
Date: Wed, 26 Sep 2012 16:45:40 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Bastien <address@hidden> 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) 
(org-lookup-function "first" nil)
(org-lookup-function "last" t)



reply via email to

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