logo资料库

Cadence SKILL Language User Guide.pdf

第1页 / 共386页
第2页 / 共386页
第3页 / 共386页
第4页 / 共386页
第5页 / 共386页
第6页 / 共386页
第7页 / 共386页
第8页 / 共386页
资料共386页,剩余部分请下载后查看
Contents
Before You Start
About This Manual
Companion Reference Manual
Audience
About the SKILL Language
Quick Look at All the Chapters
What’s New
SKILL Development Help
Quick Reference Tool - Finder
Copying and Pasting Code Examples
Other Sources of Information
Product Installation
Other SKILL Development Documentation
Related SKILL API Documentation
Document Conventions
Syntax Conventions
Data Types
Getting Started
Overview
Relationship to Lisp
A Quick Look at the Cadence SKILL Language
Terms and Definitions
Invoking a SKILL Function
What Is a Return Value?
Simplest SKILL Data
How Do You Call a Function?
Operators Are SKILL Functions
Using Variables
Alternative Ways to Enter a Function
Solving Some Common Problems
What Is a SKILL List?
Building Lists
Accessing Lists
Modifying Lists
File Input/Output
Displaying Data
Writing Data to a File
Reading Data from a File
Flow of Control
Relational Operators
Logical Operators
The if Function
The when and unless Functions
The case Function
The for Function
The foreach Function
Developing a SKILL Function
Grouping SKILL Statements
Declaring a SKILL Function
Defining Function Parameters
Selecting Prefixes for Your Functions
Maintaining SKILL Source Code
Loading Your SKILL Source Code
Redefining a SKILL Function
Language Characteristics
Overview
Naming Conventions
Names of Functions
Cadence-Private Functions
Names of Variables
Function Calls
SKILL Syntax
Special Characters
Comments
White Space
Parentheses
Super Right Bracket
Backquote, Comma, and Comma-At
Line Continuation
Length of Input Lists
Data Characteristics
Data Types
Numbers
Strings
Atoms
Escape Sequences
Symbols
Characters
Creating Functions in SKILL
Basic Concepts
Terms and Definitions
Kinds of Functions
Syntax Functions for Defining Functions
procedure
lambda
nprocedure
defmacro
mprocedures
Summary of Syntax Functions
Defining Parameters
@rest Option
@optional Option
@key Option
Combining Arguments
Type Checking
Specifying the Argument Type Template
Local Variables
Defining Local Variables (let, prog)
Initializing Local Variables to Non-nil Values
Global Variables
Testing Global Variables
Avoiding Name Clashes
Naming Scheme
Reducing the Number of Global Variables
Redefining Existing Functions
Physical Limits for Functions
Data Structures
Access Operators
Symbols
Creating Symbols
The Print Name of a Symbol
The Value of a Symbol
The Function Binding of a Symbol
The Property List of a Symbol
Important Symbol Property List Considerations
Disembodied Property Lists
Important Considerations
Additional Property List Functions
Strings
Concatenating Strings
Comparing Strings
Getting Character Information in Strings
Indexing with Character Pointers
Creating Substrings
Converting Case
Pattern Matching of Regular Expressions
Pattern Matching Functions
Defstructs
Behavior Is Similar to Disembodied Property Lists
Additional Defstruct Functions
Accessing Named Slots in SKILL Structures
Extended defstruct Example
Arrays
Allocating an Array of a Given Size
Accessing Arrays
Association Tables
Initializing Tables
Manipulating Table Data
Association Table Functions
Traversing Association Tables
Implementing Sparse Arrays
Association Lists
User-Defined Types
Arithmetic and Logical Expressions
Evaluating Expressions
Constants
Variables
Function Calls
Creating Arithmetic and Logical Expressions
Role of Parentheses
Quoting to Prevent Evaluation
Arithmetic and Logical Operators
Predefined Arithmetic Functions
Bitwise Logical Operators
Bit Field Operators
Mixed-Mode Arithmetic
Function Overloading
Integer-Only Arithmetic
True (non-nil) and False (nil) Conditions
Controlling the Order of Evaluation
Testing Arithmetic Conditions
Differences Between SKILL and C Syntax
SKILL Predicates
Using Predicates Efficiently
Type Predicates
Control Structures
Control Functions
Conditional Functions
Iteration Functions
Selection Functions
Declaring Local Variables with prog
The prog Function
The return Function
Grouping Functions
Using prog, return, and let
Using the progn Function
Using the prog1 and prog2 Functions
I/O and File Handling
File System Interface
Files
Directories
Directory Paths
The SKILL Path
Working with the SKILL Path
Working with the Installation Path
Checking File Status
Working with Directories
Ports
Predefined Ports
Opening and Closing Ports
Output
Unformatted Output
Formatted Output
Pretty Printing
Input
Reading and Evaluating SKILL Formats
Reading but Not Evaluating SKILL Formats
Reading Application-Specific Formats
Reading Application-Specific Formats from Strings
System-Related Functions
Executing UNIX Commands
System Environment
Advanced List Operations
Conceptual Background
How Lists Are Stored in Virtual Memory
Destructive versus Non-Destructive Operations
Summary of List Operations
Altering List Cells
The rplaca Function
The rplacd Function
Accessing Lists
Selecting an Indexed Element from a List (nthelem)
Applying cdr to a List a Given Number of Times (nthcdr)
Getting the Last List Cell in a List (last)
Building Lists Efficiently
Adding Elements to the Front of a List (cons, xcons)
Building a List with a Given Element (ncons)
Adding Elements to the End of a List (tconc)
Appending Lists
Reorganizing a List
Reversing a List
Sorting Lists
Searching Lists
The member Function
The memq Function
The exists Function
Copying Lists
The copy Function
Copying a List Hierarchically
Filtering Lists
The setof Function
Removing Elements from a List
Non-Destructive Operations
Destructive Operations
Substituting Elements
Transforming Elements of a Filtered List
Validating Lists
The forall Function
The exists Function
Using Mapping Functions to Traverse Lists
Using lambda with the map* Functions
Using the map* Functions with the foreach Function
The mapc Function
The map Function
The mapcar Function
The maplist Function
The mapcan Function
Summarizing the List Traversal Operations
List Traversal Case Studies
Handling a List of Strings
Making Every List Element into a Sublist
Using mapcan for List Flattening
Flattening a List with Many Levels
Manipulating an Association List
Using the exists Function to Avoid Explicit List Traversal
Commenting List Traversal Code
Advanced Topics
Cadence SKILL Language Architecture and Implementation
Evaluation
Evaluating an Expression (eval)
Getting the Value of a Symbol (symeval)
Applying a Function to an Argument List (apply)
Function Objects
Retrieving the Function Object for a Symbol (getd)
Assigning a New Function Binding (putd)
Declaring a Function Object (lambda)
Evaluating a Function Object
Efficiently Storing Programs as Data
Macros
Benefits of Macros
Macro Expansion
Redefining Macros
defmacro
mprocedure
Using the Backquote (') Operator with defmacro
Using an @rest Argument with defmacro
Using @key Arguments with defmacro
Variables
Lexical Scoping
Dynamic Scoping
Dynamic Globals
Error Handling
The errset Function
Using err and errset Together
The error Function
The warn Function
The getWarn Function
Top Levels
Memory Management (Garbage Collection)
How to Work with Garbage Collection
Printing Summary Statistics
Allocating Space Manually
Exiting SKILL
Delivering Products
Contexts
What Are Contexts?
When to Use Contexts
Creating Contexts
Creating Utility Functions
Building the Contexts
Initializing Contexts
Loading Contexts
Customizing External Contexts
Potential Problems
Context Building Functions
Autoloading Your Functions
Encrypting and Compressing Files
Protecting Functions and Variables
Explicitly Protecting Functions
Protecting Variables
Global Function Protection
Writing Style
Introduction
Code Layout
Comments and Documentation
Function Calls and Brackets
Commas
Using Globals
Misusing Globals
Common Coding Style Mistakes
Inefficient Use of Conditionals
Misusing prog and Conditionals
Red Flags
Optimizing SKILL
Introduction
Focus Your Efforts
Use Profiling Tools
Optimizing Techniques
Macros
Caching
Mapping and Qualifying
Write Protection
Minimizing Memory
General Tips
Element Comparison
List Accessing
List Building
List Searching
List Sorting
Element Removal and Replacing
Alternatives to Lists
Miscellaneous Comparative Timings
Element Comparison
List Building
Mapping Functions
Data Structures
About SKILL++ and SKILL
Introducing the Cadence SKILL++ Language
What Is SKILL++?
Background of SKILL
Origins of Scheme
Scheme Is Supplied within the SKILL Environment
Relating SKILL++ to IEEE and CFI Standard Scheme
Syntax Differences
Semantic Differences
Syntax Options
Compliance Disclaimer
References
Extension Language Environment
Maintaining Existing SKILL Programs
Hiding Private Functions and Private Data with SKILL++
Specifying the Language
Contrasting Variable Scoping
SKILL++ Uses Lexical Scoping
SKILL Uses Dynamic Scoping
Example 1: Sometimes the Scoping Rules Agree
Example 2: When Dynamic and Lexical Scoping Disagree
Example 3: Calling Sequence Effects on Memory Location
Why Lexical Scoping Is Better for Reusable Code
Summary
Contrasting Symbol Usage
How SKILL Uses Symbols
How SKILL++ Uses Symbols
Contrasting the Use of Functions as Data
Assigning a Function Object to a Variable
Passing a Function as an Argument
SKILL++ Closures
Relationship to Free Variables
How SKILL++ Closures Behave
SKILL++ Environments
The Active Environment
The Top-Level Environment
Creating Environments
Functions and Environments
Persistent Environments
Using SKILL++
Introduction
Declaring Local Variables in SKILL++
Using let
Using letseq
Using letrec
Using procedure to Declare Local Functions
Sequencing and Iteration
Using begin
Using do
Using a Named let
Software Engineering with SKILL++
SKILL++ Packages
The Stack Package
Retrofitting a SKILL API as a SKILL++ Package
SKILL++ Modules
Stack Module Example
The Container Module
Using SKILL and SKILL++ Together
Introduction
Terminology
Communication Between SKILL and SKILL++
Selecting an Interactive Language
Starting an Interactive Loop (toplevel)
Exiting the Interactive Loop (resume)
Partitioning Your Source Code
Cross-Calling Guidelines
Avoid Calling SKILL Functions That Call eval, symeval, or evalstring
Avoid Calling nlambda Functions
Use the set Function with Care
Redefining Functions
Sharing Global Variables
Using importSkillVar
How importSkillVar Works
Evaluating an Expression with SKILL Semantics
Debugging SKILL++ Applications
Retrieving a Function Object (funobj)
Examining the Source Code for a Function Object
Pretty-Printing Package Functions
Inspecting Environments
Retrieving the Active Environment
Testing Variables in an Environment (boundp)
Using the -> Operator with Environments
Using the ->?? Operator with Environments
Evaluating an Expression in an Environment (eval)
Retrieving an Environment (envobj )
Examining Closures
General SKILL Debugger Commands
SKILL++ Object System
Introduction
The Common Lisp Object System
Basic Concepts
Classes and Instances
Generic Functions and Methods
Subclasses and Superclasses
Defining a Class (defclass)
Instantiating a Class (makeInstance)
Reading and Writing Instance Slots
Defining a Generic Function (defgeneric)
Defining a Method (defmethod)
Class Hierarchy
Browsing the Class Hierarchy
Getting the Class Object from the Class Name
Getting the Class Name from the Class Object
Getting the Class of an Instance
Getting the Superclasses of an Instance
Checking if an Object Is an Instance of a Class
Checking if One Class Is a Subclass of Another
Advanced Concepts
Method Argument Restrictions
Applying a Generic Function
Incremental Development
Methods versus Slots
Sharing Private Functions and Data Between Methods
Programming Examples
List Manipulation
Symbol Manipulation
Sorting a List of Points
Computing the Center of a Bounding Box
Computing the Area of a Bounding Box
Computing a Bounding Box Centered at a Point
Computing the Union of Several Bounding Boxes
Computing the Intersection of Bounding Boxes
Prime Factorizations
Evaluating a Prime Factorization
Computing the Prime Factorization
Multiplying Two Prime Factorizations
Using Prime Factorizations to Compute the GCD
Fibonacci Function
Factorial Function
Exponential Function
Counting Values in a List
Counting Characters in a String
Regular Expression Pattern Matching
Geometric Constructions
The Application Domain
The Implementation
The Classes
The Generic Functions
Describing the Methods by Class
The Source Code
Extending the Implementation
Index
SKILL Language User Guide Product Version 06.10 March 2003
 1990-2003 Cadence Design Systems, Inc. All rights reserved. Printed in the United States of America. Cadence Design Systems, Inc., 555 River Oaks Parkway, San Jose, CA 95134, USA Trademarks: Trademarks and service marks of Cadence Design Systems, Inc. (Cadence) contained in this document are attributed to Cadence with the appropriate symbol. For queries regarding Cadence’s trademarks, contact the corporate legal department at the address shown above or call 1-800-862-4522. All other trademarks are the property of their respective holders. Restricted Print Permission: This publication is protected by copyright and any unauthorized use of this publication may violate copyright, trademark, and other laws. Except as specified in this permission statement, this publication may not be copied, reproduced, modified, published, uploaded, posted, transmitted, or distributed in any way, without prior written permission from Cadence. This statement grants you permission to print one (1) hard copy of this publication subject to the following conditions: 1. The publication may be used solely for personal, informational, and noncommercial purposes; 2. The publication may not be modified in any way; 3. Any copy of the publication or portion thereof must include all original copyright, trademark, and other proprietary notices and this permission statement; and 4. Cadence reserves the right to revoke this authorization at any time, and any such use shall be discontinued immediately upon written notice from Cadence. Disclaimer: Information in this publication is subject to change without notice and does not represent a commitment on the part of Cadence. The information contained herein is the proprietary and confidential information of Cadence or its licensors, and is supplied subject to, and may be used only by Cadence’s customer in accordance with, a written agreement between Cadence and its customer. Except as may be explicitly set forth in such agreement, Cadence does not make, and expressly disclaims, any representations or warranties as to the completeness, accuracy or usefulness of the information contained in this document. Cadence does not warrant that use of such information will not infringe any third party rights, nor does Cadence assume any liability for damages or costs of any kind that may result from use of such information. Restricted Rights: Use, duplication, or disclosure by the Government is subject to restrictions as set forth in FAR52.227-14 and DFAR252.227-7013 et seq. or its successor.
SKILL Language User Guide Contents Before You Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Companion Reference Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 About the SKILL Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Quick Look at All the Chapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 What’s New . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 SKILL Development Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Quick Reference Tool - Finder Copying and Pasting Code Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Other Sources of Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Product Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Other SKILL Development Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Related SKILL API Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Document Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Syntax Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Relationship to Lisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 A Quick Look at the Cadence SKILL Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Terms and Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Invoking a SKILL Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 What Is a Return Value? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Simplest SKILL Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 How Do You Call a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Operators Are SKILL Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Alternative Ways to Enter a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Solving Some Common Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 What Is a SKILL List? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 March 2003 3 Product Version 06.10
SKILL Language User Guide Flow of Control File Input/Output Building Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Accessing Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Modifying Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Displaying Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Writing Data to a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Reading Data from a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 The if Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 The when and unless Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 The case Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 The for Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 The foreach Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Developing a SKILL Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Grouping SKILL Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Declaring a SKILL Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Defining Function Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Selecting Prefixes for Your Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Maintaining SKILL Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Loading Your SKILL Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Redefining a SKILL Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 2 Language Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Names of Functions Cadence-Private Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Names of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 SKILL Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Special Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 White Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 March 2003 4 Product Version 06.10
SKILL Language User Guide Data Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Super Right Bracket Backquote, Comma, and Comma-At . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Line Continuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Length of Input Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Escape Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Syntax Functions for Defining Functions 3 Creating Functions in SKILL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Terms and Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Kinds of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 lambda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 nprocedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 defmacro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 mprocedures Summary of Syntax Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Defining Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 @rest Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 @optional Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 @key Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Combining Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Type Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Specifying the Argument Type Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Defining Local Variables (let, prog) Initializing Local Variables to Non-nil Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Local Variables March 2003 5 Product Version 06.10
SKILL Language User Guide Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Testing Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Avoiding Name Clashes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Naming Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Reducing the Number of Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Redefining Existing Functions Physical Limits for Functions 4 Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Creating Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 The Print Name of a Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 The Value of a Symbol The Function Binding of a Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 The Property List of a Symbol Important Symbol Property List Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Disembodied Property Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Important Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Additional Property List Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Concatenating Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Comparing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Getting Character Information in Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Indexing with Character Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Creating Substrings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Converting Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Pattern Matching of Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Pattern Matching Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Defstructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 . . . . . . . . . . . . . . . . . . . . . . . . . 111 Behavior Is Similar to Disembodied Property Lists Additional Defstruct Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Accessing Named Slots in SKILL Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Extended defstruct Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 March 2003 6 Product Version 06.10
SKILL Language User Guide Allocating an Array of a Given Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Accessing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Association Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Initializing Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 Manipulating Table Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Association Table Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Traversing Association Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Implementing Sparse Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Association Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 User-Defined Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 5 Arithmetic and Logical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Function Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Creating Arithmetic and Logical Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Role of Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Quoting to Prevent Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Arithmetic and Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Predefined Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Bitwise Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Bit Field Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Mixed-Mode Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Function Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Integer-Only Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 True (non-nil) and False (nil) Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Controlling the Order of Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Testing Arithmetic Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Differences Between SKILL and C Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 SKILL Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Using Predicates Efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Type Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 March 2003 7 Product Version 06.10
SKILL Language User Guide 6 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Conditional Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Iteration Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Selection Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Declaring Local Variables with prog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 The prog Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 The return Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Using prog, return, and let Using the progn Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Using the prog1 and prog2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Grouping Functions 7 I/O and File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Directory Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 The SKILL Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Working with the SKILL Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Working with the Installation Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Checking File Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Working with Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Predefined Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Opening and Closing Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Unformatted Output Formatted Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Pretty Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168 Reading and Evaluating SKILL Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Reading but Not Evaluating SKILL Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Reading Application-Specific Formats Output Ports Input March 2003 8 Product Version 06.10
分享到:
收藏