unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: help-gnu-emacs@gnu.org
Subject: Re: problem with macro definitions
Date: Tue, 09 May 2017 16:16:22 +0200	[thread overview]
Message-ID: <87tw4ut8sp.fsf@drachen> (raw)
In-Reply-To: <20170509081435.GA3514@workstation> (hector's message of "Tue, 9 May 2017 10:14:35 +0200")

hector <hectorlahoz@gmail.com> writes:

> I did it. This is what I meant:
>
> (defmacro idx (list needle)
>   (let (found
> 	 (haystack (eval list))
> 	 (idx 0))
>     (while (not found)
>       (when (eq (car haystack) needle)
> 	  (setq found idx))
>       (setq idx (1+ idx))
>       (setq haystack (cdr haystack)))
>     found))
>
> The macro expansion is just a number.

Yes, that's true now.

> I'm not quite sure what the "(let ((haystack (eval list))))" does but
> it works.

A macro doesn't evaluate its arguments.  Normally, arguments are
evaluated when the expanded code (with argument expressions "pasted in")
is run.  You want to do the whole calculation at compile time, and you
want to allow LIST to be an expression (known at compile time), so you
need to evaluate it explicitly to get a list value.

The same applies to the NEEDLE argument btw.


Michael.



      reply	other threads:[~2017-05-09 14:16 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
2017-05-09  8:14     ` hector
2017-05-09 14:16       ` Michael Heerdegen [this message]

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=87tw4ut8sp.fsf@drachen \
    --to=michael_heerdegen@web.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).