[Top][All Lists]

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

Re: Evaluation of macro arguments

From: Marcin Borkowski
Subject: Re: Evaluation of macro arguments
Date: Wed, 13 Jan 2016 23:16:47 +0100
User-agent: mu4e 0.9.13; emacs

On 2016-01-05, at 13:55, Stefan Monnier <> wrote:

>> Do I get it correctly that if I want to write an Edebug spec for this
>> macro, I should mark the second argument as _not evaluated_, because its
>> value is actually quoted?
> That's right.
>> (Also, do I get it right that the spec for the second argument should be
>> e.g. `symbolp', or - if I want to have more error-checking while
>> edebugging - I should _define_ a predicate like this
>> (defun upto-or-downto-p (symbol)
>>   (memq symbol '(upto downto)))
>> since the predicate in the edebug spec cannot be a lambda expression?
> Something like it, yes (tho it's not really "checked while edebugging".


I finally sat down to this.

I still don't get it.  If it's not checked while edebugging, what's the
point of the precise declaration?

> Instead, such a precise Edebug spec would cause an error (and not
> a very pretty one) when you ask Edebug to annotate the code).
> I'd use a spec like (declare (debug (form symbolp form))).

I tried it and did not get any error message.  Why?  More precisely,
here's what I have done:

--8<---------------cut here---------------start------------->8---
(defun upto-or-downto-p (symbol)
  (memq symbol '(upto downto)))

(defmacro range (from dir to)
  "Return a list of numbers starting with FROM and going up to
TO-1 if DIR is the symbol 'upto or down to TO+1 if DIR is the
symbol 'downto.  Warning: this version is broken!"
  (declare (debug (form upto-or-downto-p form)))
  `(let ((delta (cond ((eq ',dir 'upto) 1)
                      ((eq ',dir 'downto) -1)))
         (i ,from)
         (list nil))
     (while (not (= i ,to))
       (push i list)
       (setq i (+ i delta)))
     (nreverse list)))

(range (- 5 4) upto (+ 4 6))
--8<---------------cut here---------------end--------------->8---

Then I pressed C-u C-M-x on the last form, and everything went
smoothly.  If I replace 'upto with something else, I get this:

edebug-syntax-error: Invalid read syntax: upto-or-downto-p, "failed"

So basically it seems that I was (more or less) right.  OTOH, I can't
be right about anything Emacs-related and you be wrong on it, so what's
going on?

>         Stefan


Marcin Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

reply via email to

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