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:
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)
“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)
“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 (16701733)