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
- Data Types
- Arrays
- Concatenating Strings (Lists)
- Declaring a SKILL Function
- SKILL Function Return Values
- Syntax Functions for Defining Functions
SKILL Functions
There are two basic types of SKILL functions:
- Functions carry out statements and return data that can be redirected to other commands or functions.
-
Commands are functions that carry out statements defined by the command and return
tornil. Some commands return the last argument entered, but the output cannot be redirected.
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:
| Data Type | Syntax Example |
|---|---|
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 Type | Internal Name | Prefix |
|---|---|---|
|
|
|
|
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
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.
|
The |
|
Both nil and t always evaluate to themselves and must never be used as the name of a variable.
|
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 |
Constants and Variables
Supported constants and variables are discussed in
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
-
Printable characters (except a quotation mark) as part of a string without preceding them with the backslash (
\) escape character -
Unprintable characters and the quotation mark itself by preceding them with the backslash (
\) escape character, as in the C language
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.
- Arrays are not typed. Elements of the same array can be different data types.
- SKILL provides run-time array bounds checking. The array bounds are checked with each array access during runtime. An error occurs if the index is outside the array bounds.
- Arrays are one dimensional. You can implement higher dimensional arrays using single dimensional arrays. You can create an array of arrays.
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))
-
The
declarefunction returns the reference to the array storage and stores it as the value ofweek. -
The
typefunction returns the symbol array.
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.
|
|
|
|---|---|
|
|
|
|
|
|
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.
|
|
|
|---|---|
|
|
|
|
|
|
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
)
)
-
The function name is
test. -
The local variables are
aandb. -
The local variables are initialized to
nil. -
The return value is the value of
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
Return to top