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: problem with macro definitions
Date: Fri, 28 Apr 2017 00:44:07 +0200	[thread overview]
Message-ID: <20170427224407.GA5655@workstation> (raw)

Hi.

I'm trying to write a macro. Honestly I find this is one of the most
difficult matters about learning ELISP.

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 I thought it was a good candidate for a macro:

(defmacro idx (list telt)
  `(let (found
	 (idx 0))
     (dolist (elt ,list found)
       (when (eq elt ,telt)
	 (setq found idx))
       (setq idx (1+ idx)))))

Then I wrote another one:

(defconst start-states '(initial red blue yellow))
(defconst shift-val 10)

(defmacro state-eof (st)
  (let ((val (+ shift-val (idx start-states st))))
    val))

Probably there is a better way to accomplish this. Anyway I'd like to know
why it doesn't work.

This yields 2 as expected:
(idx start-states 'blue)

so I expected this to return 12:
(state-eof 'blue)

but instead I get:

wrong-type-argument number-or-marker-p nil

What am I doing wrong?



             reply	other threads:[~2017-04-27 22:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27 22:44 hector [this message]
2017-04-29  9:39 ` problem with macro definitions 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

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=20170427224407.GA5655@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.