Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a predicate?

Being a hobbyist coder, I'm lacking some fundamental knowledge. For the last couple days I've been reading some stuff and the word "predicate" keeps reappearing. I'd very much appreciate an explanation on the subject.

like image 704
Maciek Avatar asked Aug 27 '09 22:08

Maciek


People also ask

What is an example of a predicate?

: the part of a sentence or clause that tells what is said about the subject "Rang" in "the doorbell rang" is the predicate. : completing the meaning of a linking verb "Sweet" in "the sugar is sweet" is a predicate adjective.

How do you find predicate?

A simple predicate is simply the main verb. Each sentence must have a main verb, and the easiest way to find it is to look for a word that shows action. If there is no action verb in the sentence, then the simple predicate will be a "state of being" verb.

What is a subject and a predicate?

Every complete sentence contains two parts: a subject and a predicate. The subject is what (or whom) the sentence is about. The predicate tells something about the subject. The predicate of the sentence contains the verb.


2 Answers

The definition of a predicate, which can be found online in various sources such as here, is:

A logical expression which evaluates to TRUE or FALSE, normally to direct the execution path in code.

Referencing: Software Testing. By Mathew Hayden

like image 56
aehlke Avatar answered Oct 02 '22 18:10

aehlke


In programming, a predicate is a function which returns either true or false for some input.

Most commonly (I guess) used in the context of higher-order function. E.g. filter is a function in many languages which takes a predicate and a list as arguments, and returns the items in the list for which the predicate is true.

Example in javascript:

function lessThanTen(x) { return x < 10; } [1,7,15,22].filter(lessThanTen) --> [1,7] 

The function lessThanTen is the predicate here, which is applied to each item in the list.

like image 20
JacquesB Avatar answered Oct 02 '22 17:10

JacquesB