unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* #'quoting functions when they are used as identifiers
@ 2022-03-27 12:27 Jonas Bernoulli
  2022-03-27 18:58 ` Sean Whitton
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jonas Bernoulli @ 2022-03-27 12:27 UTC (permalink / raw)
  To: emacs-devel

Hi,

I was wondering whether it is wrong per se to function-quote a
function-bound symbol if it serves as an argument to a function that
does not actually call the argument as a function but for which it
would never-the-less be a bug to be passed a symbol that isn't bound
as a function.

An imperfect example would be the arguments to `derived-mode-p'.  I
don't plan to #'quote the arguments to that function but am considering
doing it for a few similar functions (from my `transient' package) for
which a prefect match exists between the name of the function and the
"symbol as an identifier".

The documentation says that ‘function’

     returns FUNCTION-OBJECT without evaluating it.  In this, it is
     similar to ‘quote’.  But unlike ‘quote’, it also serves as a note
     to the Emacs evaluator and byte-compiler that FUNCTION-OBJECT is
     intended to be used as a function. [...]

     When FUNCTION-OBJECT is a symbol and the code is byte compiled, the
     byte-compiler will warn if that function is not defined or might
     not be known at run time.

I am considering adding #'quotes because I would like to get that
feedback from the byte-compiler.  On the other hand, one might argue
that doing that is misleading to the human reader because the symbol
is not actually intended to be called as a function, it just has to be
a symbol that is fboundp, else there would be a bug (due to a typo or
renaming).

(I am not suggesting that we do this in Emacs.)

     Thanks for your thoughts!
     Jonas



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

* Re: #'quoting functions when they are used as identifiers
  2022-03-27 12:27 #'quoting functions when they are used as identifiers Jonas Bernoulli
@ 2022-03-27 18:58 ` Sean Whitton
  2022-03-28  0:50 ` Jonas Bernoulli
  2022-03-28 14:09 ` Stefan Monnier
  2 siblings, 0 replies; 6+ messages in thread
From: Sean Whitton @ 2022-03-27 18:58 UTC (permalink / raw)
  To: Jonas Bernoulli, emacs-devel

Hello,

On Sun 27 Mar 2022 at 02:27pm +02, Jonas Bernoulli wrote:

> I was wondering whether it is wrong per se to function-quote a
> function-bound symbol if it serves as an argument to a function that
> does not actually call the argument as a function but for which it
> would never-the-less be a bug to be passed a symbol that isn't bound
> as a function.

I've struggled with this.  If you assume that sharpquote has the same
meaning (ignoring implementation) as the sharpquote in Common Lisp, then
I can give an answer.  Suppose that you are choosing between (f #'foo)
and (f 'foo).  Then

  - use #'foo if f will do something with the function object which may
    be invoked using (foo ...) in the lexical environment in which the
    (f #'foo) would occur

  - otherwise, use 'foo, because f will do something with the symbol
    `foo', but not its function binding.

> I am considering adding #'quotes because I would like to get that
> feedback from the byte-compiler.  On the other hand, one might argue
> that doing that is misleading to the human reader because the symbol
> is not actually intended to be called as a function, it just has to be
> a symbol that is fboundp, else there would be a bug (due to a typo or
> renaming).

According to the CL meaning for sharpquote, this wouldn't make sense.  I
think I'd find it confusing myself, but then, I write lots of CL.  I
really don't know how close the Emacs Lisp sharpquote is meant to be to
the CL sharpquote.

The technical difference is that CL doesn't have symbol function
indirection as described by (info "(elisp) Function Indirection").

-- 
Sean Whitton



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

* Re: #'quoting functions when they are used as identifiers
  2022-03-27 12:27 #'quoting functions when they are used as identifiers Jonas Bernoulli
  2022-03-27 18:58 ` Sean Whitton
@ 2022-03-28  0:50 ` Jonas Bernoulli
  2022-03-28 14:09 ` Stefan Monnier
  2 siblings, 0 replies; 6+ messages in thread
From: Jonas Bernoulli @ 2022-03-28  0:50 UTC (permalink / raw)
  To: emacs-devel

So anyway, I have decided against doing it.



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

* Re: #'quoting functions when they are used as identifiers
  2022-03-27 12:27 #'quoting functions when they are used as identifiers Jonas Bernoulli
  2022-03-27 18:58 ` Sean Whitton
  2022-03-28  0:50 ` Jonas Bernoulli
@ 2022-03-28 14:09 ` Stefan Monnier
  2022-03-28 15:22   ` [External] : " Drew Adams
  2022-03-29 18:26   ` Jonas Bernoulli
  2 siblings, 2 replies; 6+ messages in thread
From: Stefan Monnier @ 2022-03-28 14:09 UTC (permalink / raw)
  To: Jonas Bernoulli; +Cc: emacs-devel

> I was wondering whether it is wrong per se to function-quote a
> function-bound symbol if it serves as an argument to a function that
> does not actually call the argument as a function but for which it
> would never-the-less be a bug to be passed a symbol that isn't bound
> as a function.

I think using #' only makes sense at those places where a (lambda ...)
could also be used.


        Stefan "not completely sure he always follows that rule in practice"




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

* RE: [External] : Re: #'quoting functions when they are used as identifiers
  2022-03-28 14:09 ` Stefan Monnier
@ 2022-03-28 15:22   ` Drew Adams
  2022-03-29 18:26   ` Jonas Bernoulli
  1 sibling, 0 replies; 6+ messages in thread
From: Drew Adams @ 2022-03-28 15:22 UTC (permalink / raw)
  To: Stefan Monnier, Jonas Bernoulli; +Cc: emacs-devel@gnu.org

> I think using #' only makes sense at those places where a (lambda ...)
> could also be used.
>   Stefan "not completely sure he always follows that rule in practice"

And probably only where a (lambda...) is used by
another function (e.g. as an arg, as return value,
or with funcall/apply/eval).  E.g., not here:

  ((lambda () (deprecated-but-still-around)) 42)

Another way to look at (in part): #' isn't
appropriate where the thing to be manipulated/used
is the function _symbol_ itself.  E.g.:

  (put 'forward-char 'answer 42)




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

* Re: #'quoting functions when they are used as identifiers
  2022-03-28 14:09 ` Stefan Monnier
  2022-03-28 15:22   ` [External] : " Drew Adams
@ 2022-03-29 18:26   ` Jonas Bernoulli
  1 sibling, 0 replies; 6+ messages in thread
From: Jonas Bernoulli @ 2022-03-29 18:26 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

>> I was wondering whether it is wrong per se to function-quote a
>> function-bound symbol if it serves as an argument to a function that
>> does not actually call the argument as a function but for which it
>> would never-the-less be a bug to be passed a symbol that isn't bound
>> as a function.
>
> I think using #' only makes sense at those places where a (lambda ...)
> could also be used.
>
>
>         Stefan "not completely sure he always follows that rule in practice"

Makes sense, thanks.

     Jonas "who has enough places left where #'should definitely be added"



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

end of thread, other threads:[~2022-03-29 18:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-27 12:27 #'quoting functions when they are used as identifiers Jonas Bernoulli
2022-03-27 18:58 ` Sean Whitton
2022-03-28  0:50 ` Jonas Bernoulli
2022-03-28 14:09 ` Stefan Monnier
2022-03-28 15:22   ` [External] : " Drew Adams
2022-03-29 18:26   ` Jonas Bernoulli

Code repositories for project(s) associated with this public inbox

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

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).