all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* compiler warnings for "unused" method specializers
@ 2016-10-13 23:38 Eric Abrahamsen
  2016-10-13 23:39 ` Lars Ingebrigtsen
  2016-10-14  0:43 ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2016-10-13 23:38 UTC (permalink / raw)
  To: emacs-devel

I'm having to go through a whole bunch of code and add leading
underscores to method parameters used as specializers, to quiet the
compiler. I guess this makes sense, in a way -- the parameters aren't
actually used in the function body -- but doesn't make sense in another
way: the parameters are essential to determining how and when this
method is run. So I need to do:

(cl-defmethod foo ((thing my-object) (_style (eql disco)))
  (message "%s points at the ceiling" thing))

There might be better solutions for this stupid example, but I have many
cases where it's pretty much necessary to specialize on a parameter that
isn't actually used.

My other instinct was to just put "_" for all unused parameters, but if
there's more than one of those, the compiler complains about repeated
variables.

Could the compiler special-case this situation somehow (either not
complaining about unused variables, or not complaining about repeated
variables)? Or am I just being overly persnickety about this?

Eric




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-13 23:38 compiler warnings for "unused" method specializers Eric Abrahamsen
@ 2016-10-13 23:39 ` Lars Ingebrigtsen
  2016-10-14  0:43 ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2016-10-13 23:39 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-devel

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> (cl-defmethod foo ((thing my-object) (_style (eql disco)))
>   (message "%s points at the ceiling" thing))
>
> There might be better solutions for this stupid example, but I have many
> cases where it's pretty much necessary to specialize on a parameter that
> isn't actually used.

For what it's worth, Lispworks does not complain about unused eql
parameters in defmethods.  It would make sense if Emacs didn't, either.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-13 23:38 compiler warnings for "unused" method specializers Eric Abrahamsen
  2016-10-13 23:39 ` Lars Ingebrigtsen
@ 2016-10-14  0:43 ` Stefan Monnier
  2016-10-14  6:23   ` Eric Abrahamsen
  1 sibling, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2016-10-14  0:43 UTC (permalink / raw)
  To: emacs-devel

> My other instinct was to just put "_" for all unused parameters, but if
> there's more than one of those, the compiler complains about repeated
> variables.

It'd be nice to change the byte-compiler so it doesn't complain about
repeated variables for _.

> For what it's worth, Lispworks does not complain about unused eql
> parameters in defmethods.  It would make sense if Emacs didn't, either.

Indeed for eql specializers, it could make sense to silence the
byte-compiler warnings, but at the same time, I'm not sure it's worth
the trouble to handle this case specially.


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-14  0:43 ` Stefan Monnier
@ 2016-10-14  6:23   ` Eric Abrahamsen
  2016-10-14 12:59     ` Stefan Monnier
  2016-10-14 13:01     ` Elias Mårtenson
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2016-10-14  6:23 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> My other instinct was to just put "_" for all unused parameters, but if
>> there's more than one of those, the compiler complains about repeated
>> variables.
>
> It'd be nice to change the byte-compiler so it doesn't complain about
> repeated variables for _.
>
>> For what it's worth, Lispworks does not complain about unused eql
>> parameters in defmethods.  It would make sense if Emacs didn't, either.
>
> Indeed for eql specializers, it could make sense to silence the
> byte-compiler warnings, but at the same time, I'm not sure it's worth
> the trouble to handle this case specially.

So maybe it's not worth adding extra compiler code to handle method
specializers, but it would be worth allowing multiple _s? I do like the
use of _ to say "this variable intentionally and permanently ignored".




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-14  6:23   ` Eric Abrahamsen
@ 2016-10-14 12:59     ` Stefan Monnier
  2016-10-14 13:01     ` Elias Mårtenson
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2016-10-14 12:59 UTC (permalink / raw)
  To: emacs-devel

> So maybe it's not worth adding extra compiler code to handle method
> specializers, but it would be worth allowing multiple _s?

That's my opinion, yes,


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-14  6:23   ` Eric Abrahamsen
  2016-10-14 12:59     ` Stefan Monnier
@ 2016-10-14 13:01     ` Elias Mårtenson
  2016-10-14 13:07       ` Stefan Monnier
  1 sibling, 1 reply; 8+ messages in thread
From: Elias Mårtenson @ 2016-10-14 13:01 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

On 14 Oct 2016 2:25 pm, "Eric Abrahamsen" <eric@ericabrahamsen.net> wrote:
>
> So maybe it's not worth adding extra compiler code to handle method
> specializers, but it would be worth allowing multiple _s? I do like the
> use of _ to say "this variable intentionally and permanently ignored".

How about supporting CL-style ignore declarations?

(defun foo (x) (declare (ignore x)) 1)

[-- Attachment #2: Type: text/html, Size: 539 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-14 13:01     ` Elias Mårtenson
@ 2016-10-14 13:07       ` Stefan Monnier
  2016-10-14 19:08         ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2016-10-14 13:07 UTC (permalink / raw)
  To: emacs-devel

>> So maybe it's not worth adding extra compiler code to handle method
>> specializers, but it would be worth allowing multiple _s? I do like the
>> use of _ to say "this variable intentionally and permanently ignored".
> How about supporting CL-style ignore declarations?
> (defun foo (x) (declare (ignore x)) 1)

You can already do

    (defun foo (x) (ignore x) 1)


-- Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: compiler warnings for "unused" method specializers
  2016-10-14 13:07       ` Stefan Monnier
@ 2016-10-14 19:08         ` Eric Abrahamsen
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Abrahamsen @ 2016-10-14 19:08 UTC (permalink / raw)
  To: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> So maybe it's not worth adding extra compiler code to handle method
>>> specializers, but it would be worth allowing multiple _s? I do like the
>>> use of _ to say "this variable intentionally and permanently ignored".
>> How about supporting CL-style ignore declarations?
>> (defun foo (x) (declare (ignore x)) 1)
>
> You can already do
>
>     (defun foo (x) (ignore x) 1)

If I was willing to do all that typing, I wouldn't have complained about
having to prefix all my variable names with an underscore in the first
place. :)




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-10-14 19:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-13 23:38 compiler warnings for "unused" method specializers Eric Abrahamsen
2016-10-13 23:39 ` Lars Ingebrigtsen
2016-10-14  0:43 ` Stefan Monnier
2016-10-14  6:23   ` Eric Abrahamsen
2016-10-14 12:59     ` Stefan Monnier
2016-10-14 13:01     ` Elias Mårtenson
2016-10-14 13:07       ` Stefan Monnier
2016-10-14 19:08         ` Eric Abrahamsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.