Cadence SKILL - Functions

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:

    In today’s 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)

    Let us stop being afraid. Of our own thoughts, our own minds. Of madness, our own or others’. Stop being afraid of the mind itself, its astonishing functions and fandangos, its complications and simplifications, the wonderful operation of its machinery—more wonderful because it is not machinery at all or predictable.
    Kate Millett (b. 1934)

    One of the most highly valued functions of used parents these days is to be the villains of their children’s lives, the people the child blames for any shortcomings or disappointments. But if your identity comes from your parents’ failings, then you remain forever a member of the child generation, stuck and unable to move on to an adulthood in which you identify yourself in terms of what you do, not what has been done to you.
    Frank Pittman (20th century)