[Top][All Lists]

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

Re: Evaluation of macro arguments

From: Stefan Monnier
Subject: Re: Evaluation of macro arguments
Date: Thu, 14 Jan 2016 08:47:45 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

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

It's *used* (rather than checked) when *setting up* the Edebug
instrumentation, rather than while single stepping through the code.
[ I realize now that maybe "setup edebug instrumentation" is what you
  meant by "edebugging", while to me "edebugging" means something more
  like single-stepping, which is what happens after the instrumentation
  has been put in place.  ]

>> 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.

Yes, that's normal.

> If I replace 'upto with something else, I get this:
> edebug-syntax-error: Invalid read syntax: upto-or-downto-p, "failed"

That's the error I was referring to (and indeed, if the code is right
you should not be getting an error).  The error can become more
troublesome for more complex Edebug specs where Edebug can try various
alternatives in which case the error you get may be about an alternative
which shouldn't have been tried anyway.

To see the difference between "instrumentation" and "single-stepping",
you need to try C-u C-M-x on something like

  (defun my-foo () (range (- 5 4) typo (+ 4 6)))

where you'll immediately get the error during C-u C-M-x rather than latr
on when you call my-foo.

> 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?

I think we were just in violent agreement.


reply via email to

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