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:
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:
Read more about this topic: Cadence SKILL
Famous quotes containing the word examples:
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)