[Abstract]
[Copyright Notice]
[Contents]
Sather - A Language Manual
This documentation is meant as a tutorial for learning to use the programming
language Sather. The whole file may be somewhat outdated in some details,
as it has only be partly revised from a text covering Sather 1.1 - there is still
work to do. If you find bugs or want to help revising this documentation, please
contact bug-sather@gnu.org
This Documentation is covered by the GPL.
Copyright (C) 199x by International Computer Science Institute ***
Copyright (C) 1999 by Free Software Foundation, Inc. ***
This file is part of the GNU Sather package. It is free software; you may
redistribute and/or modify it under the terms of the GNU General Public
License (GPL) as published by the Free Software Foundation; either
version 2 of the license, or (at your option) any later version. ***
This file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See Doc/GPL for more details. ***
The license text is also available from: Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- 1 Introduction
- 1.1 Acknowledgements
- 1.2 How to read this Document
- 1.3 Sources of Information
- 1.4 Obtaining the Compiler
- 1.4.1 How do I ask questions?
- 1.5 Summary of Features
- 1.5.1 Basic Concepts
- 1.5.2 Garbage Collection and Checking
- 1.5.3 No Implicit Calls
- 1.5.4 Separation of Subtyping and Code Inclusion
- 1.5.5 Iterators
- 1.5.6 Closures
- 1.5.7 Immutable and Reference Objects
- 1.5.8 IEEE Floating-Point
- 1.5.9 pSather
- 1.6 History
- 2 Classes and Objects
- 2.1 Preliminaries
- 2.1.1 Some basic classes - INT, FLT and STR
- 2.1.2 Printing output
- 2.1.3 Sather source files
- 2.1.4 Hello World
- 2.2 Defining Classes and Creating Objects
- 2.2.1 Defining Simple Classes
- 2.2.2 Checking whether an object has been created
- 2.2.3 Types Introduced
- 2.2.4 Hiding features: private and readonly
- 2.3 Class Data: shared and const
- 2.3.1 Shared Attributes - Restricted global variables
- 2.3.2 Class Constants
- 2.3.3 Accessing Class Data - the :: notation
- 2.4 Routine definitions
- 2.4.1 Routine Arguments and Modes
- 2.4.2 Local Variables - Scoping and Shadowing
- 2.4.3 Routine calls
- 2.4.4 Simple Overloading - Selecting a routine to call
- 2.5 Conditional Execution
- 2.5.1 if statements
- 2.5.2 case statements
- 2.5.3 Short circuit boolean expressions: and and or
- 2.6 Attribute Accessor Routines
- 2.6.1 Attribute assignment
- 2.7 Static Type Inference
- 2.7.1 Creation Expressions
- 2.7.2 Assignments and ::=
- 2.7.3 Arguments to a function call
- 2.8 Class Parameters
- 2.9 A Running Example: Employees
- 3 Loops and Iterators
- 3.1 Using iterators
- 3.2 Defining Iterators
- 3.2.1 yield statements
- 3.2.2 Explicitly leaving an iterator using quit
- 3.2.3 Control flow within an iterator
- 3.2.4 The once argument mode
- 3.2.5 out and inout argument modes
- 3.2.6 pre and post conditions in iterators
- 3.2.7 Argument evaluation in iterators
- 3.2.8 Points to note
- 3.3 Iterator Examples
- 4 Code Inclusion and Partial Classes
- 4.1 Include Clauses
- 4.2 Partial Classes and Stub routines
- 4.2.1 Mixins: A Prompt Example
- 5 Abstract Classes and Subtyping
- 5.1 Abstracting over Implementations
- 5.1.1 Implementing a Stack using an Array
- 5.1.2 A Stack Calculator
- 5.1.3 A Linked List Representation of a Stack
- 5.1.4 Switching Representations:Polymorphism
- 5.2 Abstract Class Definitions
- 5.3 Subtyping
- 5.3.1 The Type Graph
- 5.3.2 Dynamic Dispatch and Subtyping
- 5.4 Supertyping
- 5.5 Type Conformance
- 5.5.1 Contravariant conformance
- 5.5.2 Subtyping = substitutability
- 5.6 The typecase statement
- 5.7 The Overloading Rule
- 5.7.1 Extending Overloading
- 5.7.2 Permissible overloading
- 5.7.3 Overloading as Statically resolved Multi-Methods
- 5.7.4 Conflicts when subtyping
- 5.7.5 Conflicts during code inclusion
- 5.7.6 Points to note
- 5.7.7 Overloading in Parametrized Classes
- 5.7.8 Why not use the return type to resolve conflicts?
- 5.8 When Covariance Ails You
- 5.8.1 But don't animals eat food?
- 5.8.2 Solution 1: Refactor the type hierarchy
- 5.8.3 Solution 2: Eliminate the offending method
- 5.8.4 Solution 3: Dynamically Determine the Type
- 5.8.5 Solution 4: Parametrize by the Argument Type
- 6 Parametrized Classes and Arrays
- 6.1 Parametrized concrete types
- 6.2 Support for Arrays
- 6.2.1 Array Access
- 6.2.2 Array Classes: Including AREF and calling new();
- 6.2.3 Standard Arrays: ARRAY{T}
- 6.2.4 Multi-dimensional Arrays
- 6.3 Type Bounds
- 6.3.1 Why have typebounds?
- 6.3.2 Supertyping and Type Bounds
- 6.4 Parametrized Abstract Classes
- 6.5 Overloading
- 6.5.1 Overloading In the Parametrized Class Interface
- 6.5.2 Overloading Resolution within the Parametrized Class
- 7 Operator Redefinition
- 7.1 Method Names for Operators
- 7.2 Operator expressions
- 7.2.1 Operator precedence
- 7.3 Array Access Routines
- 8 Immutable Classes
- 8.1 Defining Immutable Classes
- 8.1.1 Immutable Class Example
- 8.1.2 Creating a new object
- 8.1.3 Initial value of immutable objects
- 8.1.4 Attribute access routines
- 8.1.5 Points to note
- 8.2 Using Immutable Classes
- 9 Closures
- 9.1 Creating and Calling Closures
- 9.1.1 Creating a closure
- 9.1.2 Calling a closure
- 9.1.3 Binding overloaded routines
- 9.1.4 Points to note
- 9.1.5 Binding some arguments
- 9.1.6 Leaving self unbound
- 9.2 Further Examples of Closures
- 9.2.1 Closures for Applicative Programming
- 9.2.2 Menu Structures
- 9.2.3 Iterator closures
- 10 Exceptions
- 10.1 Throwing and Catching Exceptions
- 10.1.1 Throwing Exceptions with raise
- 10.1.2 Catching Exceptions with protect
- 10.1.3 Usage to avoid
- 10.1.4 Alternatives to Exceptions
- 10.2 A more elaborate example
- 11 Safety Features
- 12 Built-in classes
- 12.1 Fundamental Classes
- 12.2 Tuples
- 12.3 The SYS Class
- 12.4 Object Finalization: $FINALIZE
- 12.5 Basic Classes and Literal Forms
- 12.5.1 Booleans and the BOOL class
- 12.5.2 Characters and the CHAR class
- 12.5.3 The string class, STR
- 12.5.4 Integers and the INT class
- 12.5.5 Infinite precision integers and the INTI class
- 12.5.6 Floating point numbers: the FLT and FLTD classes
- 12.6 Library Conventions
- 13 Interfacing with Fortran
- 13.1 Overview
- 13.1.1 External Fortran Call Example
- 13.1.2 Overall Organization
- 13.2 Name Binding
- 13.3 Datatype Mapping
- 13.4 Parameter Passing
- 13.5 Portability Issues
- 13.5.1 Portability of the Interface Implementation Code
- 13.5.2 Portability of the Generated Code
- 14 Interfacing with ANSI C
- 14.1 Overall Organization
- 14.2 Built-in C classes
- 14.3 User-defined External C types
- 14.3.1 Constants and C binding names
- 14.3.2 Attributes and C structs
- 14.3.3 Shared Attributes and C globals
- 14.4 Parameter Passing
- 14.5 Inlining C Code
- 15 Statement and Expression Catalogue
- 15.1 Statements
- 15.2 Expressions
- 15.2.1 void expressions
- 15.2.2 void test expressions
- 15.2.3 Short circuit boolean expressions: and and or
- 15.2.4 exception expressions
[Abstract]
[Copyright Notice]
[Contents]
Sather - A Language Manual
4 November 1999
B. Gomes, D. Stoutamire, B. Vaysman and H. Klawitter
Norbert Nemec nobbi@gnu.org