emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@altern.org>
To: Achim Gratz <Stromeko@nexgo.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Lookup functions, take two
Date: Wed, 26 Sep 2012 00:43:27 +0200	[thread overview]
Message-ID: <873925g1v4.fsf@bzg.ath.cx> (raw)
In-Reply-To: <878vbxao4r.fsf@Rainer.invalid> (Achim Gratz's message of "Tue, 25 Sep 2012 21:39:00 +0200")

Achim Gratz <Stromeko@nexgo.de> 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	other threads:[~2012-09-25 22:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-23 15:26 [PATCH] Lookup functions, take two Jarmo Hurri
2012-09-24 14:01 ` Bastien
2012-09-24 17:33   ` Jarmo Hurri
2012-09-25  1:49     ` Bastien
2012-09-25  4:13       ` Jarmo Hurri
2012-09-25 10:04         ` Bastien
2012-09-25  9:15       ` Dominik, Carsten
2012-09-25 10:02         ` Bastien
2012-09-26 13:00           ` Jarmo Hurri
2012-09-26 13:14             ` Bastien
2012-09-25 19:39 ` Achim Gratz
2012-09-25 22:43   ` Bastien [this message]
2012-09-26 13:45     ` Jarmo Hurri
2012-09-26 14:26       ` Bastien
2012-09-26 17:47         ` Jarmo Hurri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873925g1v4.fsf@bzg.ath.cx \
    --to=bzg@altern.org \
    --cc=Stromeko@nexgo.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).