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 archetype of all humans, their ideal image, is the computer, once it has liberated itself from its creator, man. The computer is the essence of the human being. In the computer, man reaches his completion.
    Friedrich Dürrenmatt (1921–1990)

    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)