The Structure and Interpretation of Computer Programs
Updated: October 22, 2020
Chapter 1 #
Predicates/Expressions #
Taking the following Lisp code:
(defun abs (x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) (- x))))
which simply calculates the absolute value of a number, we see within the cond
(conditional) three “clauses”. These parenthesized pairs (clauses) are formed of “predicates” and “expressions”, respectively.
Predicate an expression whose value is interpreted as either true or false.
The interpreter of this program will check each predicate and evaluate its corresponding expression if that predicate is true. While a (> x 0)
is, itself, a predicate, there are primitive predicates used within those. In this example >
is a primitive predicate.
Functions v. Procedures or Imperative v. Declarative #
(Mathematical) Functions are different from a (Computational) Procedure in that the former is describing the property of some thing, and in the latter, describing how to do something. Take the definition of a square root:
\begin{equation} \sqrt{x}=\,y,such\,that\,y \geq 0\,and\,y^{2} = x \end{equation}
This doesn’t tell us how to do anything, it only defines square roots. This is Declarative knowledge (what something is) and, alternatively, Imperative knowledge is how to do something.