Scilab Bag Of Tricks

The Scilab-2.5.x IAQ (Infrequently Asked Questions)

Lydia E. van Dijk

Hammersmith Consulting

Christoph L. Spiel

Hammersmith Consulting

sci-BOT – the Scilab Bag Of Tricks – is a collection of Scilab experience that come from every day use. We warn of common pitfalls, discuss stylistic issues, shed light on unknown spots, and show many different ways of increasing the performance of Scilab functions.

The document is not meant to be comprehensive or even suitable to a particular level of knowledge. Some sections are at the beginners level, some even surprise long-time users.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no invariant sections, with the Front-Cover Texts being "Scilab Bag Of Tricks", and with no Back-Cover Texts. A copy of the license is included in the appendix "GNU Free Documentation License".

Trademarks:

DIGITAL™ is a trademark of Digital Equipment Corp.
IBM™ is a trademark of International Business Machines Corp.
Intel™ is a trademark of Intel Corp.
Matlab™ is a trademark of The Mathworks, Inc.
Microsoft™ and Microsoft Windows™ are trademarks of Microsoft Corp.
PostScript™ is a trademark of Adobe, Inc.
SGI™ is a trademark of Silicon Graphics International, Inc.
SUN™ is a trademark of Sun Microsystems, Inc.
TeX™ is a trademark of the American Mathematical Society


Copyrights:

GNU/Linux© copyrighted by Linus Torvalds
GNUPlot© copyrighted by Thomas Williams, Colin Kelley and many others
MuPAD© copyrighted by Benno Fuchsensteiner
Octave© copyrighted by John W. Eaton
Pari© copyrighted by C. Batut, K. Belabas, D. Bernardi, H. Cohen, and M. Olivier
PlotMTV© copyrighted by Kenny Toh
Scilab© copyrighted by INRIA, France
Tela© copyrighted by Pekka Janhunnen



Table of Contents
Preface
1. Outline
2. Other Formats of sci-BOT
3. Packed examples
4. Typographic conventions
5. Scilab Release History by Enrico Segre
6. Contributions
7. Acknowledgments
1. Introduction
2. Common Pitfalls
2.1. The Infamous Dot
2.2. Vector Construction
2.3. Function head
2.4. Last Newline
2.5. Variable Lifetime And Scoping
2.5.1. Local Variable Scoping
2.5.2. Global Variables
2.5.3. Clearing Variables
2.6. Dangerous Range Generation
3. Programming Style
3.1. Spacing and Formatting
3.1.1. Intra-Expression Spacing
3.1.2. Line Breaking
3.1.3. Setting Brackets Apart
3.1.4. Vertical Spacing
3.2. Indentation
3.3. Single Quotes vs. Double Quotes
3.4. Choice Of Control Structures
3.4.1. while/for
3.4.2. if/select
3.4.3. Strict Block Structure/Early Return
3.5. Size of a Function
4. Unknown Spots
4.1. Keywords and Commands
4.2. Operator Overloading[1]
4.2.1. Overloading crash course
4.2.2. Overload syntax
4.2.3. Overloading example
4.3. Operator Precedence And Associativity
4.3.1. Numeric Operators
4.3.2. Relational Operators
4.3.3. Logical Operators
4.4. Implicit Cast To Boolean
4.5. Integers by Enrico Segre
4.5.1. Missed Opportunities
4.5.2. Digest of Integer Go And No-Gos
4.6. Miscellaneous Unknown Spots
4.6.1. Maximum variable name length
4.6.2. Starting scilex
4.6.3. Tuple Assignment
4.6.4. Dot as Member Selector
5. User Functions
5.1. Functions
5.1.1. On(e)line Function Definitions
5.1.2. Nested Function Definitions
5.1.3. Functions Without Parameters or Return Value
5.1.4. Named Parameters
5.1.5. Bulletproof Functions
5.1.6. Function Variables
5.1.7. Functions as Parameters in Function Calls
5.1.8. Omitting Parentheses on Function Call by Glen Fulford
5.1.9. Functions in tlists and mlists
5.1.10. macrovar
5.2. Libraries of sci-functions
5.2.1. getf vs. lib
5.2.2. genlib
5.2.3. Library Caveats
5.2.4. Loading Non-Functions With lib
6. Performance
6.1. High-Level Operations
6.1.1. Vectorized Operations
6.1.2. Avoiding Indexing and Resizing
6.1.3. Built-In Vector-/Matrix-Functions
6.1.4. Evaluation of Polynomials
6.2. Extending Scilab
6.2.1. Comparison Of The Link Overhead
6.2.2. Preparing And Compiling External Subroutines
6.2.3. Pushing It Further
6.3. Building an Optimized Scilab
7. Scilab Core
7.1. Introduction To Pseudo-Ada
7.2. Internal Data Structure
7.2.1. Parameter Stack And Data Stack
7.2.2. Storage of Complex Matrices
7.3. Writing Native Scilab Functions
7.3.1. Simple Functions
7.3.2. Functionals
7.3.3. Dispatch Tables
7.4. Error Handling
7.4.1. Fatal Errors
7.4.2. Warnings
7.4.3. Messages
7.5. Fortran Interface to Scilab's Core
7.5.1. Query
7.5.2. Access Object
7.5.3. Create Object
7.5.4. Miscellaneous
7.6. C Interface to Scilab's Core
7.6.1. Query
7.6.2. Access Object
7.6.3. Create Object
7.6.4. Miscellaneous
8. Further Information
8.1. Coping With Scilab
8.1.1. Distribution Size
8.1.2. Bug Hunting
8.2. Local Documents
8.3. Hyperlinks
9. Notes for Contributers
9.1. Writing Style
9.2. Technicalities
9.2.1. DocBook
9.2.2. Tables
9.2.3. Examples
9.2.4. Graphics
9.2.5. Mathematics
9.2.6. Index terms
10. Complete Examples
10.1. frac.sci
10.2. benchmark.sci
10.3. listdiff.sci
10.4. whatis.sci
10.5. Auto-Determination of Precedence and Associativity
10.5.1. assoc.sci
10.5.2. prec.sci
10.5.3. parser.sci
10.6. cat.sci
10.7. quadpack.sci
A. GNU Free Documentation License
0. PREAMBLE
1. APPLICABILITY AND DEFINITIONS
2. VERBATIM COPYING
3. COPYING IN QUANTITY
4. MODIFICATIONS
5. COMBINING DOCUMENTS
6. COLLECTIONS OF DOCUMENTS
7. AGGREGATION WITH INDEPENDENT WORKS
8. TRANSLATION
9. TERMINATION
10. FUTURE REVISIONS OF THIS LICENSE
B. GNU General Public License
0. APPLICABILITY[1]
1. VERBATIM COPYING
2. MODIFICATIONS
3. DISTRIBUTION
4. TERMINATION
5. ACCEPTANCE
6. REDISTRIBUTION
7. CONSEQUENCES
8. LIMITATIONS
9. FUTURE REVISIONS OF THIS LICENSE
10. AGGREGATION WITH INDEPENDENT WORKS
11. NO WARRANTY
12. LIABILITY
Bibliography
Index
List of Tables
4-1. Reserved Words
4-2. Commands
4-3. List of all operand type codes
4-4. List heads used by Scilab
4-5. Operator type codes
4-6. Arithmetic Operators
4-7. Boolean Operators
4-8. Selected Functions and Operators That Work With Integers
4-9. Selected Functions and Operators That Do Not Work With Integers
6-1. Comparison of various vectorization levels
6-2. Mode Specifiers for gsort
6-3. Direction Specifiers for gsort
6-4. Performance comparison of different polynomial evaluation routines
7-1. pAda to Fortran-77 and C type mappings – elementary types
7-2. pAda type mappings – Scilab Fortran-77 interface
7-3. pAda type mappings – Scilab C interface
7-4. TypeString Identifiers
9-1. DocBook approximation of a DIN conforming table
List of Figures
6-1. Benchmark results for the mirror functions
9-1. Table formatted according to DIN 55301
List of Examples
2-1. Building a matrix column-by-column and row-by-row
2-2. Canonicalization of Scilab files
2-3. Shadowing of local variables
2-4. Accessing variables from the enclosing scope
2-5. Dynamic Scoping
2-6. Equivalent Representation of a Colon-Expression
3-1. Function whocat
3-2. Function mysign
4-1. Manually launching scilex
5-1. Function tauc
5-2. Function accepting named arguments
5-3. Function accepting optional arguments
5-4. Function cat
5-5. Generate names for lib: gen-names
6-1. Variants of a matrix mirror function
6-2. Naive functions to evaluate a polynomial
6-3. Less naive functions to evaluate a polynomial
6-4. Sample interface description (".desc")
6-5. Makefile for static Scilab interfaces via intersci
7-1. Multiplication of complex matrices
7-2. Simple native Scilab function
7-3. Scilab functional
7-4. Handling of warnings in Scilab
9-1. SGML-code for a DIN compliant table
9-2. Inclusion of graphics
9-3. Inclusion of mathematics