emacs-orgmode
[Top][All Lists]
Advanced

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

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


From: Bastien
Subject: Re: [O] [PATCH] Lookup functions, take two
Date: Wed, 26 Sep 2012 00:43:27 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.2.50 (gnu/linux)

Achim Gratz <address@hidden> 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



reply via email to

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