[Top][All Lists]

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

Re: Codifying some aspects of Elisp code style and improving pretty prin

From: Stefan Monnier
Subject: Re: Codifying some aspects of Elisp code style and improving pretty printer
Date: Fri, 01 Oct 2021 13:08:28 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> All the examples there use 'quote', and the discussion of 'quote' vs
> 'function' is in (info "(elisp) Anonymous Functions"). People who've
> just gone 'i mapc' in the elisp manual have no reason to read that
> second node. Patch below

See comment below.

> If dislike it, because I view lambda as self-quoting, but as you say
> thatʼs a personal preference (although "(elisp) Anonymous Functions"
> kind of tells you not to quote lambda's).

Quoting a lambda for me means to put a `quote` in front of it not
a `function`.  #' is a "translucent quote" which says this isn't some
chunk of data (something the compiler basically can't touch nor
"understand") but is a chunk of code (something which the compiler can
definitely manipulate, analyze, etc...).

>     >> 3. The byte compiler doesnʼt warn about it.
>     Stefan> Mine does ;-)
>     Stefan> But I wouldn't want to enable such a warning by default (or at 
> least it
>     Stefan> should be mess a bit less eager than it is, because of the 
> occasional false
>     Stefan> positives).
> Iʼve not seen any false positives from mine, but I suspect itʼs less
> sophisticated than yours :-)

Mine's very simple, but I think most of its false positives come from
`define-key`. In any case I think the trade off between annoying coders
with more warnings and the improvement in code quality we hope to get by
fixing the code to eliminate the warnings is not in favor of adding
this warning.  At least not at this point.

> diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
> index c856557c3c..4416b39f09 100644
> --- a/doc/lispref/functions.texi
> +++ b/doc/lispref/functions.texi
> @@ -890,6 +890,33 @@ Mapping Functions
>  over a char-table in a way that deals properly with its sparse nature,
>  use the function @code{map-char-table} (@pxref{Char-Tables}).
> +  All the mapping functions described here take a function as their
> +first argument, which can be specified in different ways:
> +
> +@itemize
> +@item An anonymous lambda
> +
> +@example
> +(mapcar (lambda (x) (x)) ....)
> +@end example
> +
> +@item A function-quoted symbol
> +
> +@example
> +(mapcar #'identity ....)
> +@end example
> +
> +@item An quoted symbol
> +
> +@example
> +(mapcar 'car ....)
> +@end example
> +@end itemize

I don't see the point of documenting (mapcar 'foo ..) at this place.
Also functions can be specified in many other ways (they can come from
variable or be computed on the spot by calling a function-generating
function, such as `apply-partially`).

So I think it's better to link to some other place in the manual where
we talk specifically about anonymous functions.

More importantly, we should try and systematically use #'foo in all the
examples instead.

Also I wouldn't call it "a (function-)quoted symbol" but I'd say that we
pass to mapcar a "function name" or maybe a "named function".  We can
elsewhere mention that 'foo also works to pass a (global)
named function.


reply via email to

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