unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* problem with macro definitions
@ 2017-04-27 22:44 hector
  2017-04-29  9:39 ` Michael Heerdegen
  0 siblings, 1 reply; 6+ messages in thread
From: hector @ 2017-04-27 22:44 UTC (permalink / raw)
  To: help-gnu-emacs

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?



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-05-09 14:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).