Hacker News new | ask | show | jobs
by emidln 3593 days ago
> adopt the idiotic "-p convention" which doesn't even really exist in Lisp any more.

Do you have a better way of signaling to the reader that a function is a predicate? I don't write a ton of Common Lisp, but I do still see quite of a bit of foop when I read Common Lisp. Possible that most of the code I'm reading was written when this was still a thing though...

I think the only reason this doesn't exist in Clojure (which is the lisp I used the most) is that ? is a valid identifier. Similarly Scheme includes ? as a valid identifier (at least R5RS as implemented by Chicken).

4 comments

See first 25 entries or so in the permuted CL symbol index:

http://www.lispworks.com/documentation/lw51/CLHS/Front/X_Per...

Scheme does use ?, and you can in CL if you really want. But CL reserves ? as a programmable reader macro [1]. It is often used, for example, to designate a stand-in domain variable designation in, say an embedded Prolog.

Another reason that CL avoids the "?" convention is that it's "unpronounceable" [2]. CL is the only language spec I've seen that discusses pronunciation; they actually gave thought to how programmers might converse about their code unambiguously [3]. Another manifestation of this is CL's sort-of case-insensitivity [4].

--

[1] The other reserved characters are !, [ ], and { }

[2] Although at least one wag suggested pronouncing it as "eh?", like a good Canadian.

[3] CLtL2 provides quite a bit of this. My fav is a brief excursion into how some hackers pronounce "macrolet" to rhyme with Chevrolet. :)

[4] This is not actually the case, but appears to be true to new Lispers, until they understand that by default, the reader converts everything to upcase.

Did you miss the Hoon language and their pronunciation table that works for other languages too? http://urbit.org/docs/hoon/syntax/ They suggest pronouncing '?' as 'wut'.
You can name your symbol as you want in Lisp, "(make-symbol s)" works for all string "s". With the reader, if you need to define symbols with spaces or otherwise not treated as symbols, or if you want to ensure the names are not upcased (it depends on the readtable), you enclose the name in bars: |anything, whatever| is a single symbol, as well as || (the empty symbol).

The convention for predicates is to use "-p" (there is a hyphen if the rest of the symbol has hyphens, otherwise no hyphen). I think I saw a few libraries that define "thing?" predicates, but that is quite rare. People generally tend to not break conventions in practice, even though "?" can be regarded as a logical prefix for predicates.

You may be right, maybe I've just only looked at Scheme lately and thought "?" had migrated to Common Lisp.

https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node188.html seems to indicate that you could use ? in a common lisp function name, though.

You could, but I've never seen it. Convention seems to be to suffix 'p' if the predicate name is a single word, and '-p' otherwise.
In languages without '?', it's common to prefix the predicate function's name with "is", for example is_empty or isEmpty.