all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: hector <hectorlahoz@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: problem with macro definitions
Date: Sat, 29 Apr 2017 18:06:32 +0200	[thread overview]
Message-ID: <20170429160632.GA3291@workstation> (raw)
In-Reply-To: <878tmjr1ry.fsf@drachen>

Thank you for your reply.

On Sat, Apr 29, 2017 at 11:39:13AM +0200, Michael Heerdegen wrote:
> hector <hectorlahoz@gmail.com> writes:
> 
> > I was looking for the complementary of nth, that is, a function that
> > returns the index of an element. Since it can be done at compilation
> > time
> 
> Not if you want to use it on values that are known only at run-time.

I know. In this case when the list is constant it seemed to be right.

> > I thought it was a good candidate for a macro:
> 
> No, not really:
> 
> > (defmacro idx (list telt)
> >   `(let (found
> > 	 (idx 0))
> >      (dolist (elt ,list found)
> >        (when (eq elt ,telt)
> > 	 (setq found idx))
> >        (setq idx (1+ idx)))))
> 
> You loose nothing when you rewrite this as a function.  In this
> implementation, the index is calculated at run-time.

Let me rephrase your statement:

"You gain nothing when you write this as a macro.  In this
implementation, the index is calculated at run-time"

I'm aware of that now. This is not what I meant.
I'll try to rewrite it.

> Note that macros don't evaluate their arguments.  The argument 'blue you
> pass, a read syntax for (quote blue), is a list of two elements.  This
> doesn't appear as an element of `start-states' which consists of four
> symbols.

This is the key to my confusion.



  parent reply	other threads:[~2017-04-29 16:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 22:44 problem with macro definitions hector
2017-04-29  9:39 ` Michael Heerdegen
2017-04-29  9:52   ` Michael Heerdegen
2017-04-29 16:06   ` hector [this message]
2017-05-09  8:14     ` hector
2017-05-09 14:16       ` Michael Heerdegen

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

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

  git send-email \
    --in-reply-to=20170429160632.GA3291@workstation \
    --to=hectorlahoz@gmail.com \
    --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.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.