Product Documentation
OCEAN Reference
Product Version IC23.1, September 2023

4


Working with SKILL

This chapter provides information on using SKILL functions. It includes information on the types of SKILL functions, the types of data accepted as arguments, how data types are used, and how to declare and define functions. In this chapter, you can find information about

SKILL Functions

There are two basic types of SKILL functions:

Data Types

SKILL supports several data types, including integer and floating-point numbers, character strings, arrays, and a highly flexible linked list structure for representing aggregates of data. The simplest SKILL expression is a single piece of data, such as an integer, a floating-point number, or a string. SKILL data is case sensitive. You can enter data in many familiar ways, including the following:

Sample SKILL Data Items
Data Type Syntax Example

integer

5

floating point number

5.3

text string

"Mary had a little lamb"

For symbolic computation, SKILL has data types for dealing with symbols and functions.

For input/output, SKILL has a data type for representing I/O ports. The table below lists the data types supported by SKILL with their internal names and prefixes.

Data Types Supported by SKILL

Data Type Internal Name Prefix
array array a

boolean

b

floating-point number

flonum

f

any data type

general

g

linked list

list

l

floating-point number or integer

n

user-defined type

o

I/O port

port

p

symbol

symbol

s

symbol or character string

S

character string (text)

string

t

window type

w

integer number

fixnum

x

Numbers

SKILL supports the following numeric data types:

Both integers and floating-point numbers may use scaling factors to scale their values. For information on scaling factors, see “Scaling Factors”.

Atoms

An atom is any data object that is not a grouping or collection of other data objects. Built into SKILL are several special atoms that are fundamental to the language.

nil

The nil atom represents both a false logical condition and an empty list.

t

The symbol t represents a true logical condition.

Both nil and t always evaluate to themselves and must never be used as the name of a variable.

unbound

To make sure you do not use the value of an uninitialized variable, SKILL sets the value of all symbols and array elements initially to unbound so that such an error can be detected.

Constants and Variables

Supported constants and variables are discussed in “Arithmetic and Logical Expressions”

Strings

Strings are sequences of characters; for example, "abc" or "123". A string is marked off by quotation marks, just as in the C language; the empty string is represented as "". The SKILL parser limits the length of input strings to a maximum of 8,191 characters. There is, however, no limit to the length of strings created during program execution. Strings of more than 8,191 characters can be created by applications and used in SKILL if they are not given as arguments to SKILL string manipulation functions.

When typing strings, you specify

Arrays

An array represents aggregate data objects in SKILL. Unlike simple data types, you must explicitly create arrays before using them so the necessary storage can be allocated. SKILL arrays allow efficient random indexing into a data structure using familiar syntax.

Allocating an Array of a Given Size

Use the declare function to allocate an array of a given size.

declare( week[7] )           => array[7]:9780700 
week => array[7]:9780700
type( week ) => array
days = ’(monday tuesday wednesday
thursday friday saturday sunday)
for( day 0 length(week)-1
week[day] = nth(day days))

Concatenating Strings (Lists)

Concatenating a List of Strings with Separation Characters (buildString)

buildString makes a single string from the list of strings. You specify the separation character in the third argument. A null string is permitted. If this argument is omitted, buildString provides a separating space as the default.

buildString( ’("test" "il") ".")       => "test.il"
buildString( ’("usr" "mnt") "/") => "usr/mnt"
buildString( ’("a" "b" "c")) => "a b c"
buildString( ’("a" "b" "c") "")   => "abc"

Concatenating Two or More Input Strings (strcat)

strcat creates a new string by concatenating two or more input strings. The input strings are left unchanged.

strcat( "l" "ab" "ef" )     => "labef" 

You are responsible for any separating space.

strcat( "a" "b" "c" "d" )     => "abcd" 
strcat( "a " "b " "c " "d " ) => "a b c d "

Appending a Maximum Number of Characters from Two Input Strings (strncat)

strncat is similar to strcat except that the third argument indicates the maximum number of characters from string2 to append to string1 to create a new string. string1 and string2 are left unchanged.

strncat( "abcd" "efghi" 2)                => "abcdef"
strncat( "abcd" "efghijk" 5)   => "abcdefghi"

Comparing Strings

Comparing Two Strings or Symbol Names Alphabetically (alphalessp)

alphalessp compares two objects, which must be either a string or a symbol, and returns t if arg1 is alphabetically less than arg2. alphalessp can be used with the sort function to sort a list of strings alphabetically. For example:

stringList = ’( "xyz" "abc" "ghi" )
sort( stringList ’alphalessp ) => ("abc" "ghi" "xyz")

The next example returns a sorted list of all the files in the login directory:

sort( getDirFiles( "~" ) ’alphalessp )

Comparing Two Strings Alphabetically (strcmp)

strcmp compares two strings. (To test if two strings are equal or not, you can use the equal command.) The return values for strcmp are explained in the following table.

Return Value Meaning
1 string1 is alphabetically greater than string2.

0

string1 is alphabetically equal to string2.

-1 string1 is alphabetically less than string2.
strcmp( "abc" "abb" )=> 1
strcmp( "abc" "abc")=> 0
strcmp( "abc" "abd")=> -1

Comparing Two String or Symbol Names Alphanumerically or Numerically (alphaNumCmp)

alphaNumCmp compares two string or symbol names. If the third optional argument is not nil and the first two arguments are strings holding purely numeric values, a numeric comparison is performed on the numeric representation of the strings. The return values are explained in the following table.

Return Value Meaning
1 arg1 is alphanumerically greater than arg2.

0

arg1 is alphanumerically identical to arg2.

-1 arg2 is alphanumerically greater than arg1.

Declaring a SKILL Function

To refer to a group of statements by name, use the procedure declaration to associate a name with the group. The group of statements and the name make up a SKILL function.

To run the group of statements, mention the function name followed immediately by ().

The clearplot command below erases the Waveform window and then plots a net.

procedure( clearplot( netname ) 
clearAll( )
plot( v (netName))
    )

Defining Function Parameters

To make your function more versatile, you can identify certain variables in the function body as formal parameters.

When you start your function, you supply a parameter value for each formal parameter.

Defining Local Variables (let)

Local variables can be used to establish temporary values in a function. This is done using the let statement. When local variables are defined, they are known only within the let statement and are not available outside the let statement.

When the function is defined, the let statement includes the local variables you want to define followed by one or more SKILL expressions. The variables are initialized to nil. When the function runs, it returns the last expression computed within its body. For example:

procedure( test ( x )
let(( a b )
a=1
b=2
x * a+b
)
)

SKILL Function Return Values

All SKILL functions compute a data value known as the return value of the function. Throughout this document, the right arrow (=>) denotes the return value of a function call. You can

Any type of data can be a return value.

Syntax Functions for Defining Functions

SKILL supports the following syntax functions for defining functions. You should use the procedure function in most cases.

procedure

The procedure function is the most general and is easiest to use and understand.

The procedure function provides the standard method of defining functions. Its return value is the symbol with the name of the function. For example:

procedure( trAdd( x y ) 
"Display a message and return the sum of x and y"
printf( "Adding %d and %d ... %d \n" x y x+y )
x+y
) => trAdd
trAdd( 6 7 ) => 13

Terms and Definitions

function, procedure

In SKILL, the terms procedure and function are used interchangeably to refer to a parameterized body of code that can be executed with parameters in the function call bound to the parameters in the function definition. SKILL can represent a function as both a hierarchical list and as a function object.

argument, parameter

The terms argument and parameter are used interchangeably. The arguments in a function call correspond to the formal arguments in the declaration of the function.

expression

A use of a SKILL function, often by means of an operator supplying required parameters.

function body

The collection of SKILL expressions that define the function’s algorithm.


Return to top
 ⠀
X