emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jarmo Hurri <jarmo.hurri@syk.fi>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Lookup functions, take two
Date: Wed, 26 Sep 2012 16:45:40 +0300	[thread overview]
Message-ID: <87txukyk1n.fsf@syk.fi> (raw)
In-Reply-To: 873925g1v4.fsf@bzg.ath.cx

Bastien <bzg@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

  reply	other threads:[~2012-09-26 13:46 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
2012-09-26 13:45     ` Jarmo Hurri [this message]
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=87txukyk1n.fsf@syk.fi \
    --to=jarmo.hurri@syk.fi \
    --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).