all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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

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.