Functions
The SKILL language supports both dynamic (sometimes referred to as special) and lexical variables. However, a single function is limited to interpret its variables homogeneously. There are several ways of syntactically indicating whether a function be interpreted lexically or dynamically. One of which are to use (inSkill ..) and (inScheme ...) forms indicating dynamic and lexical scoping respectively.
(inSkill (lambda (A B) (A B)))In the inSkill example A and B are dynamic variables in the parameter list of the lambda (the lambda list), and (A B) within the body of the function is interpreted as a call to the globally defined function A passing the value of the local dynamic variable B.
(inScheme (lambda (A B) (A B)))In the inScheme example A and B are lexical variables in both the lambda list, and also (A B) within the body of the function which is interpreted as a call to the function A which has been passed and a parameter the value of the local lexical variable B.
inSkill and inScheme forms may be mixed within a single function with some degree of flexibility.
(inScheme (lambda (A B) (A (inSkill B) B)))In this example a lexical 2-ary function is created which calls A, a function passed as its first argument, passing two parameters: the value of the dynamic variable B and also the value of the local lexical variable B.
SKILL supports several kinds of functions. In addition to the functions and special forms built into the language, users can create functions in their own applications of several varieties.
Anonymous functions including lexical closures.
(lambda (A) (lambda (B) (plus A B)))Lambda functions which evaluate their arguments using normal left-to-right evaluation rules.
(defun (A B) (list A A B B))Nlambda functions which do not evaluate their arguments, but pass their operands unevaluated at run time.
(nprocedure (A) (when (listp A) (eval A)))Macros which are evaluated by expanding at load/compile time. The sexpressions a macro returns (evaluates to) become input for the compiler, and is thus evaluated at run time.
(defmacro nif (num if_plus if_zero if_minus) (let ((var (gensym))) `(let ((,var ,num)) (cond ((plusp ,var) ,if_plus) ((zerop ,var) ,if_zero) (t ,if_minus)))))SKILL supports CLOS-like generic functions which are allowed to have an optional default implementation.
(defgeneric generic_add (a b c))SKILL supports CLOS-like methods which specialize on all their required arguments. (Older versions of SKILL only support specialization of the first argument.)
(defmethod generic_add ((a fixnum) (b number) (c list)) (apply plus a b c))Local functions of two sorts are supported with flet and labels. If local functions are defined with flet such as inner1 and inner2 below, neither one can see the other's definition.
(defun outer (flet ((inner1 (printf "hello")) (inner2 (printf "world"))) (inner1) (printf " ") (inner2) (newline)))If local functions are defined with labels such as inner1 and inner2 below, all of them see the other's definition. Local function are only supported in lexical mode.
(defun outer (labels ((inner1 (printf "hello")) (inner2 (inner1) (printf " world\n"))) (inner2)))Read more about this topic: Cadence SKILL
Famous quotes containing the word functions:
“When Western people train the mind, the focus is generally on the left hemisphere of the cortex, which is the portion of the brain that is concerned with words and numbers. We enhance the logical, bounded, linear functions of the mind. In the East, exercises of this sort are for the purpose of getting in tune with the unconsciousto get rid of boundaries, not to create them.”
—Edward T. Hall (b. 1914)
“In todays world parents find themselves at the mercy of a society which imposes pressures and priorities that allow neither time nor place for meaningful activities and relations between children and adults, which downgrade the role of parents and the functions of parenthood, and which prevent the parent from doing things he wants to do as a guide, friend, and companion to his children.”
—Urie Bronfenbrenner (b. 1917)
“If photography is allowed to stand in for art in some of its functions it will soon supplant or corrupt it completely thanks to the natural support it will find in the stupidity of the multitude. It must return to its real task, which is to be the servant of the sciences and the arts, but the very humble servant, like printing and shorthand which have neither created nor supplanted literature.”
—Charles Baudelaire (18211867)