Predicate in Programing Languages and Naming

By Xah Lee. Date: . Last updated: .

Meaning of “Predicate” in Logic and Computer Science

in math and programing, there's the term “predicate”. In first order logic, “predicate” is a unary relation. For example, p(x) means p(x) is true. In pseudo-code, you are asserting eval(f(x)) == True.

But in programing language, “predicate” just means a function that return true or false.

this is important and often confusing. Here's a concrete example. Suppose you want to say that 3 is a integer:

In the above example, “isInteger” is the predicate, but their meaning is critically different.

Naming Convention of Predicate in Computer Languages

Emacs Lisp and Common Lisp

in emacs lisp and Common Lisp, by convention, predicate function names end with “p”. For example, in emacs lisp you have:

in emacs lisp, not all functions ending in p is a predicate. For example: {pop, defgroup, make-sparse-keymap, forward-sexp}

Scheme Lisp and Clojure Lisp

in Scheme Lisp and Clojure Lisp, the convention is to name predicate ending with a question mark “?”.

this is better. Because the question mark is more intuitive. The “p” is incomprehensible, and the term “predicate” came from history of logic.

Wolfram Language

in Mathematica, they end with “Q”, standing for Question.

Mathematica identifiers allow letters only, and builtin names always start with a capital letter. So, all builtin names have this CamelCaseStyle.

So, they cannot use question mark ?. And because p for predicate is not intuitive, thus Q, for Question.

examples of Mathematica predicate:

[see Wolfram Language Tutorial]


in Ruby, it picked up from Scheme Lisp, and ends with “?”. For example, here's predicate methods for integer:

[see Ruby Tutorial by Example]

Programing Language Naming of Things