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:

    The English masses are lovable: they are kind, decent, tolerant, practical and not stupid. The tragedy is that there are too many of them, and that they are aimless, having outgrown the servile functions for which they were encouraged to multiply. One day these huge crowds will have to seize power because there will be nothing else for them to do, and yet they neither demand power nor are ready to make use of it; they will learn only to be bored in a new way.
    Cyril Connolly (1903–1974)

    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)

    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 unconscious—to get rid of boundaries, not to create them.
    Edward T. Hall (b. 1914)