Cadence SKILL - Examples

Examples

Here are some examples of SKILL.

First, a basic “Hello world”:

println("Hello, world!")

SKILL supports tail call optimization, if it is explicitly enabled. Here is a tail recursive version of factorial which requires no stack space for the recursion if optimizeTailCall is enabled.

(sstatus optimizeTailCall t) (defun factorial (n) (flet ((repeat (n factorial) (if (plusp n) (repeat (sub1 n) n * factorial)) factorial))) (repeat n 1)))

The following definition is a more idiomatic iterative definition.

(defun factorial (n) (let ((answer 1)) (for i 2 n answer = answer * i) answer)))

This example shows how variables are assigned and scoped, using = and let, respectively:

procedure( swap let( ((a 1) (b 2)) c = a a = b b = c printf("%d %d %d\n" a b c) ) )

The variables a and b are scoped within the let function, but variable c is not. As a result, c becomes a global variable that can be accessed without the scope of the swap function. Here is what happens when swap is executed and a, b and c are then printed:

> swap 2 1 1 t > a *Error* toplevel: undefined variable - a > b *Error* toplevel: undefined variable - b > c 1

Read more about this topic:  Cadence SKILL

Famous quotes containing the word examples:

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)

    Histories are more full of examples of the fidelity of dogs than of friends.
    Alexander Pope (1688–1744)

    There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring ‘em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.
    Bernard Mandeville (1670–1733)