[Top][All Lists]

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

Re: Naming predicates

From: Stefan Monnier
Subject: Re: Naming predicates
Date: Fri, 28 Sep 2018 15:26:24 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>>    If the purpose of a function is to tell you whether a certain
>>    condition is true or false, give the function a name that ends in
>>    'p' (which stands for "predicate").  If the name is one word, add
>>    just 'p'; if the name is multiple words, add '-p'.  Examples are
>>    'framep' and 'frame-live-p'.

*Users* should never define a single-word function, since they should
use a namespace prefix.  Hence "I'd say you can simply always use "-p"
when it's something you define".

> Thanks for the pointer; I'd forgotten that. But there are several
> counterexamples:

You don't have to follow them when you define your own function.

> indivisible-p interactive-p ring-p registerv-p
> bool-vector-subsetp coding-system-lessp default-boundp file-attributes-lessp
> hack-one-local-variable-eval-safep ...

Yes, there are conflicting desires: when you define something that's
very much like "foop" but in the context of "strigles", the multi-word
rule suggest you name it "strigle-foo-p", but there's also an argument
to be made for "strigles-foop".

As the author of that function you get to follow whichever of the two
you like.  Personally, I think always using "-p" is a simpler rule and
is never wrong (that's the rule followed by `cl-defstruct`,
incidentally).  Even using "-p" on single-word thingies is
perfectly acceptable.

> The Common Lisp influence seems to be causing a lot of Elisp code to violate
> the guideline, which may help to explain why I can never remember it.

While the inconsistency is annoying when trying to reference an existing
function, the situation is much simpler when you're defining a new


reply via email to

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