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

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

what's the order of evaluation of forms in the top level body?


From: Marco Maggi
Subject: what's the order of evaluation of forms in the top level body?
Date: Wed, 19 Feb 2020 21:36:26 +0100

Ciao,

  I would like to keep my "bootstrap macros" local to a file; so, rather
that using DEFMACRO to build CL-DEFSTRUCT  and similar forms, I tried to
use CL-MACROLET.  The code looks like this:

   (require 'cl-lib)

   (defun debug-print (&rest args)
     (pp args 'external-debugging-output))

   (cl-macrolet ((defit (NAME) `(cl-defstruct ,NAME val)))
     (defit one)
     (defit two))

   (cl-defgeneric doit (arg))

   (defmacro defmeth (TYPE)
     `(progn
        (cl-defmethod doit ((arg ,TYPE))
          arg)))

   (defmeth one)
   (defmeth two)

   (debug-print (doit (make-one :val 1)))
   (debug-print (doit (make-two :val 2)))

this works fine, no error.  But I  have a case, with more code involved,
when  a  macro use  like  "(defmeth  one)"  above  fails with  an  error
equivalent  to "undefined  argument  type:  one".  So  far  I failed  to
reproduce this error with smaller code.

  But I see that if I turn the CL-MACROLET into a DEFMACRO, as in:

   (defmacro defit (NAME)
     `(cl-defstruct ,NAME val))

   (defit one)
   (defit two)

no error is raised.

  So I wonder: what's the order of  evaluation of forms in the top level
body of an Emacs Lisp source file?   Are there special cases?  I was not
able to find relevant documentation in the elisp manual.

TIA
-- 
Marco Maggi



reply via email to

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