[Top][All Lists]

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

Re: unexpected byte-compiler behaviour

From: John Mastro
Subject: Re: unexpected byte-compiler behaviour
Date: Thu, 9 Mar 2017 13:55:12 -0800

hector <address@hidden> wrote:
> One of the problems here is that I'm thinking in C. That's where I come
> from and sometimes it's hard to get accustomed to a new language.
> You don't need to define a function before it is called. That's why
> the "function is not defined" message is delayed until the end of parsing.

Functions do need to be defined before they're called, just not before
the call is compiled. However, macros (like defclass) are expanded at
compile time, so they need to be defined before then.

> I think perhaps I should use "(require 'eieio):
> (defclass lyqi-abbrev ()
>   ((abbrev :initarg :abbrev)
>    (collection :initarg :collection)
>    (start-position :initarg :start-position)))
> But then, is "defclass" defined even if I don't require eieio?

Yes - EIEIO isn't preloaded, and defclass isn't autoloaded, so you
should (require 'eieio).

You can test this by starting a fresh Emacs with "emacs -Q", then
evaluate (fboundp 'defclass), which will return nil. Then evaluate
(require 'eieio), followed by (fboundp 'defclass) again, which will now
return t.

As an aside: Often if you're only using a macro like defclass, it would
be enough to use (eval-when-compile (require 'eieio)), because the
definition is only needed at compile-time. However, from a quick look I
think the expansion of defclass will need EIEIO at runtime (e.g. the
call to eieio-defclass-internal), so EIEIO is needed at both
compile-time and run-time and thus a full (require 'eieio) is called


reply via email to

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