Why does the predicate naming convention differ between different functions?
Asked Answered
F

1

9

I am a Common Lisp newbie who's beginning to learn the language. My question is: I've seen several functions use the predicate syntax in different ways. For example (just looked this up), there is streamp and pathnamep, but there is also input-stream-p and output-stream-p. Why aren't all functions standardized to use *p or *-p? Is this maybe just a historical artifact?

Feodore answered 26/3, 2013 at 15:27 Comment(3)
Mostly historical -- Common Lisp largely ended up as a simple union of everything from every major Lisp implementation at the time, almost all thrown in together with more interest in ensuring that existing code would continue to work than in creating a language that really fit together well.Lorettalorette
This isn't actually 'syntax' - it is 'naming convention'Funnyman
@Funnyman Good point, fixed.Feodore
G
12

The rule is that one-word predicate names end in just P, while multi-word predicate names end in -P. The reason for the former is mostly historical; the reason for the latter is that a name like input-streamp would wrongly suggest that the question being asked is “is this input a stream?” or something like that.

Gownsman answered 26/3, 2013 at 16:18 Comment(3)
I tend to say predicatep and complex-predicate-p (or, alternatively simplep and complex-predicate-p) as a rule.Murrell
Note also that in some cases, you do not add an hyphen for multi-word predicate (e.g. string-lessp). See Common Lisp the Language, 2nd Edition.Viridity
And also there is atom :) .Common Lisp the Language, 2nd EditionMarolda

© 2022 - 2024 — McMap. All rights reserved.