unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Cc: hector <hectorlahoz@gmail.com>
Subject: Re: unexpected byte-compiler behaviour
Date: Thu, 9 Mar 2017 13:55:12 -0800	[thread overview]
Message-ID: <CAOj2CQS0oZYacL+GPeT8x1_nEvfVgSEJ6AOfzMr=QRhzfPVg0Q@mail.gmail.com> (raw)
In-Reply-To: <20170309192503.GB2999@workstation>

hector <hectorlahoz@gmail.com> 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
for.

        John



  reply	other threads:[~2017-03-09 21:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-09 17:46 unexpected byte-compiler behaviour hector
2017-03-09 18:18 ` John Mastro
2017-03-09 18:20   ` John Mastro
2017-03-09 19:17     ` hector
2017-03-09 19:25   ` hector
2017-03-09 21:55     ` John Mastro [this message]
2017-03-09 22:49       ` hector
2017-03-09 23:28         ` John Mastro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOj2CQS0oZYacL+GPeT8x1_nEvfVgSEJ6AOfzMr=QRhzfPVg0Q@mail.gmail.com' \
    --to=john.b.mastro@gmail.com \
    --cc=hectorlahoz@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).