Function


 

Function[body][input]

...executes body parameterized with subExpressions taking values from input using...

Slot[...]
constructions.

 

Function[body]

...defines a potential Function which may be a Name assignment, or in any programming construct which needs the exhaustive evaluation of body.

 

 

Function is a scoped environment like a Name assignment to an ElicitationForm except for the following:

-     Function does not use  substitution names for input, but instead...

    Function uses "Slot[slotSpec]"-constructs to parameterize body, and...

-     Function[body][input] installs input and then exhausts all recognized ElicitationForms in body's subExpressions in the creation of the returned Expression.

 

 

See definition of "function".

See also NameRecognition.

 


 


SlotPosition

 

 

Function[body][input] is used to construct executable functions which use  Slots within body to substitute indexed  subExpressions extracted from input.

 

(1)                   Function[body][input]

 

...defines a Function which executes body, with values taken from subExpressions in input.  The Cardinal arguments for each  Slot[...] within body, specify which subExpressions in input are to be substituted in the evaluation of body. See Function Slots Example.

 

When an attempt within "body" to access a nonexistent SlotPosition in the Function's input is attempted, the Slot is unassigned.  This means that within the body of a Function like (1),

 

                       True[Slot[slotSpec]]

 

...evaluates "True" if slotSpec specifies a nonexistent SlotPosition

Any attempt to access a nonexistent SlotPosition returns the uninterpreted Slot-expression.

 


 


ExhaustiveEvaluation

 

 

Exhaustive evaluation means that a Function's body is interpreted by exhaustively evaluating body.
This means that the result returned by Function[body][input] will not subsequently elicit anything (in the same environment).

 

A Function's evaluation proceeds left-to-right beginning at the most deeply nested elicitation in body.  An exhaustively interpreted subExpression becomes an atom within the containing Expression.  That containing Expression is invoked (compared against elicitations in the environment) and evaluated. This process continues until Function's body has been exhaustively interpreted such that body elicits nothing in the environment.

 

 


RecursionNumber

 

It is easy to write an infinite recursion with the Function.  The following declaration defines an infiniteRecursion Function:

 

(2)                   Name[infiniteRecursion, Function[infiniteRecursion]]

 

Reckon[infiniteRecursion] evaluates Function[infiniteRecursion] invoking infiniteRecursion, which then calls itself without end. This would be the behavior of Function where it not for built-in recursion monitoring. Instead, Reckon[infiniteRecursion] will return...

 

(3)        Noop[Not[Loop[Cardinal]]]["infiniteRecursion", recursionNumber]

 

In the above NoopNamedError, the first argument is the String value of the recursive expression.  The 2nd argument is the recursionNumber which is the value assigned to Name[Loop[Cardinal]]


Name[Loop[Cardinal]] is assigned to the Cardinal number of recursions allowed to any Name invoked in a Function.
Name[Loop[Cardinal]] is the RecursionNumber.
Alternately,

 

            Name[infiniteRecursion[Loop[Cardinal]], customRecursionNumber ]

 

...allows infiniteRecursion to be called recursively customRecursionNumber times. This RecursionNumber assignment is part of infiniteRecursion's Definition. By replacing "infiniteRecursion" in the above construction, any Name can be assigned a custom RecursionNumber

 

 


Function Recursion Monitoring

 

When a Function body is Reckoned, it normally employs Recursion Monitoring.

When a Function body is Compiled, the Recursion Monitoring feature is removed

 

Recursion Monitoring has no consequence to the result returned by a Function except to cause it to return the NoopNamedError in (3) when the RecursionNumber is reached.  Thus, Recursion Monitoring is typically used as an aid in debugging. When an actual infinite loop structure in a Function generates (3), it usually reflects a conceptual programming failure. When a Compiled Function begins an infinite recursion, it will either crash its host processor, or require operating system intervention to terminate the recursion. By contrast, if a Function is Reckoned in its uncompiled state, it monitors Name recursions (returning the NoopNamedError in (3) when the RecursionNumber is reached). 

 

Compile[...] presumes that any compilable Function, is not an infinite recursion. For this reason, and for execution speed, a Compiled Function does no Recursion Monitoring. A Compiled Function will execute much quicker then its Reckoned form.  If a Function is known to potentially branch to an infinite or indeterminant recursion, it should not be Compiled. Alternately, a mechanism to monitor or control a Function's recursion can be explicitly written into a compilable Function. A portion of a Function body that does not reliably terminate in a predictable interval, is usually better Reckoned then Compiled.

 

 

 


English definition of "function"

 

function n.

1. Action; activity; doing; performance. Rare.

            Function is smothered in surmise.   Shak

2. a The natural and proper action of anything; special activity; office, duty, calling, operation, or the like.

It is a function of both poetry and religion to rebaptize using floods of wonder.                 J.Martineau.

   b The natural or characteristic action of any power or faculty; esp., one of the characteristic processes or elementary activities of consciousness; a mode of conscious action.

All mental activities, such as seeing, hearing, perceiving, conceiving, imagining, recalling, etc., are termed functions.                   Murchison.

c. The course of action which peculiarly pertains to any public officer in church or state; the activity appropriate to any business or profession; official duty.

3. Profession; occupation; office; as, the clerical function; also, obs., body or class of persons of one trade or profession.

4. A public or social ceremony or gathering; a festivity or entertainment, esp. one that is somewhat formal.

           At this function, which is our chief social event.           W.D. Howells,

5. Any quality, trait, or fact so related to another that it is dependent upon and varies with that other.

6. Eccl. An impressive and elaborate religious ceremony.

7. Gram. a Syntactic relation; as "round" has a qualifying function in "round eyes".

            b A feature of meaning distinguished as characteristic of a type of word; as, number is a function of noun senses; tense, or verb senses.

8. Math. A magnitude so related to another magnitude that to values of the latter there correspond values of the former.  Either magnitude is a function of the other, but that one whose values are observed or arbitrarily assigned is called the argument of the independent variable.  A magnitude may be a function of a any number of arguments.  Thus the surface and volume of a sphere are functions of its radius; the velocity of sound is a function of the elasticity, etc., of the air.

9. Org. Chem. Characteristic behavior of a compound due to the presence of a particular atom, group of atoms, or mode of union of atoms; also, the atom, group, orarrangement causing such properties;  as, the amino function.

10. Physical. The normal and special action of any organ or part of a living animal or plant.

11. Symbolic Logic. An expression involving a variable term or terms, whose meaning or truth is determined when concrete values of the variable, or variables, are specified.

Syn. Province, service; working.

                                                           [From Websters1949Unabridged.]

 

 


Function Example

If,

 

            Name[func, Function[{Slot[1], Slot[2]}]]

 

...is reckoned, (and thereby becomes part of the current environment), subsequently invoking...

 

                        Reckon[func["a", "b"]]

 

...returns...

                       {"a", "b"}.

 

 


Grok32`

(c) 2004-2008 by
John Van Wie Bergamini.

Hosted by www.Geocities.ws

1