help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with macro definitions


From: hector
Subject: problem with macro definitions
Date: Fri, 28 Apr 2017 00:44:07 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]