unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt.de>
To: help-gnu-emacs@gnu.org
Subject: Re: emacs lisp - unable to write a function maker
Date: Fri, 23 Sep 2011 15:31:21 +0000	[thread overview]
Message-ID: <m3d3ers2ba.fsf@passepartout.tim-landscheidt.de> (raw)
In-Reply-To: 47D4EF93ED6C47B8AD53845AECED59D4@us.oracle.com

"Drew Adams" <drew.adams@oracle.com> wrote:

> [...]
> Well, not quite - the OP quoted the function symbol, indicating that s?he would
> pass something that needs to be eval'd. If that's rally part of the requirement,
> then:

> (defmacro makeAbrevFun (name val)
>  `(defun ,(eval name) () (insert ,val)))

> (makeAbrevFun 'aa "aaaaaaaaaaaaaa")

> In both cases: (symbol-function 'aa) gives:
> (lambda () (insert "aaaaaaaaaaaaaa"))

On a related note - how do I proceed if I do not want to
create a macro that creates a function, but create multiple
functions directly? For example, after some trial and error
my ~/.emacs ended up with (paraphrased):

| (dolist (i '(("once"   . 1)
|              ("twice"  . 2)
|              ("thrice" . 3)))
|   (fset (intern (concat "tl-say-" (downcase (car i))))
|         `(lambda (s)
|            ,(concat "Say S only " (car i) ".")
|            (interactive "sWhat to message: ")
|            (dotimes (j ,(cdr i))
|              (message "I say it only %s: %s." ,(car i) s)))))

I didn't manage to use defun as I got stuck in quoting and
non-quoting "magic".

Tim




  reply	other threads:[~2011-09-23 15:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-16  8:46 emacs lisp - unable to write a function maker C K Kashyap
2011-09-16  8:58 ` Thien-Thi Nguyen
2011-09-16  9:26   ` C K Kashyap
2011-09-16  9:40     ` Thien-Thi Nguyen
2011-09-16  9:57     ` Eric Abrahamsen
2011-09-16 10:17       ` C K Kashyap
2011-09-16 11:19         ` Eric Abrahamsen
2011-09-16 14:06       ` Drew Adams
2011-09-23 15:31         ` Tim Landscheidt [this message]
2011-09-23 16:43           ` Drew Adams

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=m3d3ers2ba.fsf@passepartout.tim-landscheidt.de \
    --to=tim@tim-landscheidt.de \
    --cc=help-gnu-emacs@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.
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).