Empty Product - in Computer Programming

In Computer Programming

Many programming languages, such as Python, allow the direct expression of lists of numbers, and even functions that allow an arbitrary number of parameters. If such a language has a function that returns the product of all the numbers in a list, it usually works like this:

listprod( ) --> 30 listprod( ) --> 6 listprod( ) --> 2 listprod( ) --> 1

This convention sometimes helps avoid having to code special cases like "if length of list is 1" or "if length of list is zero" as special cases.

Many programming languages do not permit the direct expression of the empty product, because they do not allow expressing lists. Multiplication is taken to be an infix operator and therefore a binary operator. Languages implementing variadic functions are the exception. For example, the fully parenthesized prefix notation of Lisp languages gives rise to a natural notation for nullary functions:

(* 2 2 2) ; evaluates to 8 (* 2 2) ; evaluates to 4 (* 2) ; evaluates to 2 (*) ; evaluates to 1

Read more about this topic:  Empty Product

Famous quotes containing the words computer and/or programming:

    The analogy between the mind and a computer fails for many reasons. The brain is constructed by principles that assure diversity and degeneracy. Unlike a computer, it has no replicative memory. It is historical and value driven. It forms categories by internal criteria and by constraints acting at many scales, not by means of a syntactically constructed program. The world with which the brain interacts is not unequivocally made up of classical categories.
    Gerald M. Edelman (b. 1928)

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)