emacs-devel
[Top][All Lists]
Advanced

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

Re: How to silence "Unknown slot" compiler warnings?


From: Stefan Monnier
Subject: Re: How to silence "Unknown slot" compiler warnings?
Date: Sat, 20 Feb 2016 21:05:23 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> I am always using :initarg with keywords because I want to emphasise
> slot names in main code:

>   (defclass pm-polymode (pm-root) 
>   ((hostmode
>     :initarg :hostmode

:hostmode is not a slot name, it's an initarg name.  EIEIO is mostly an
implementation of CLOS, but for some reason it decided to allow you to
say (slot-value x :hostmode) instead of (slot-value x 'hostmode).

The two are equivalent, except that:
- (slot-value x :hostmode) is not accepted by CLOS.
- (slot-value x :hostmode) is slower.

> I can't say why! I'm also a little uncomfortable about the "naked"
> versions, and for the same reason -- my brain keeps seeing them as
> variables.

The "naked" version only shows up with (oref x hostmode) which is an
EIEIO-only macro which is equivalent to (slot-value x 'hostmode).
As you can see, the (slot-value x 'hostmode) version doesn't suffer from
this problem (and additionally it's part of CLOS), so I encourage you to
use that instead.
EIEIO can't take advantage of the compile-time-knowledge of `hostmode'
to speed up the slot access anyway, so you might as well use `slot-value'.

Both `oref' and `slot-value' are "namespace unclean" (they don't have
any kind of "package prefix"), but `oref' is a much more likely
candidate to obsolescence because `slot-value' at least has the argument
that it's a standard CLOS name.


        Stefan




reply via email to

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