=====================
== avisiblenetwork ==
=====================
seeing the invisible

Compound Procedures

Compound procedures provide another means of abstraction similar to naming elements. It is an extension of primitive procedures, i.e., it is the combination of primitive procedures. It includes all three aspects of a programming language: primitive elements, a combination of those primitive elements, and the packaging of those elements as a unit to be abstracted. This allows for greater flexibility and functionality in a program.

As it is an extension of primitive procedures, I will only present how to build a compound procedure in Common Lisp.

Start with defining the name of the procedure, the parameters that are going to be used, and then the application of those parameters as arguments in the program.

In Common Lisp:

(defun product (x y) (* x y))
(defun sum-of-product (x y) (+ (product x y) (product x y)))
(defun f (x y) (sum-of-product (+ x 1) (* y 2)))

If you input 3 and 4 as the arguments to the function, you will end with 64.

(f 3 4) is what the function will look like. But under the hood, a lot is going on:

(+ (* (+ 3 1) (* 4 2)) (* (+ 3 1) (* 4 2)))

Here is what it looks like in full:

[1]> (defun product (x y) (* x y))
PRODUCT
[2]> (defun sum-of-product (x y)(+ (product x y) (product x y)))
SUM-OF-PRODUCT
[3]> (defun f (x y) (sum-of-product (+ x 1) (* y 2)))
F
[4]> (f 3 4)
64

This is the power of combining primitive elements and abstracting them.