Bastien <b...@altern.org> 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