06.07.2013 Views

Scilab Bag Of Tricks - Claymore

Scilab Bag Of Tricks - Claymore

Scilab Bag Of Tricks - Claymore

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table of Contents<br />

Preface ...............................................................................................................................................13<br />

1. Outline...................................................................................................................................13<br />

2. Other Formats of sci-BOT.....................................................................................................14<br />

3. Packed examples ...................................................................................................................15<br />

4. Typographic conventions ......................................................................................................15<br />

5. Acknowledgments.................................................................................................................16<br />

1. Introduction...................................................................................................................................17<br />

2. Common Pitfalls............................................................................................................................19<br />

2.1. The Infamous Dot ..............................................................................................................19<br />

2.2. Vector Construction............................................................................................................20<br />

2.3. Function head.....................................................................................................................21<br />

2.4. Last Newline ......................................................................................................................22<br />

2.5. Variable Lifetime And Scoping..........................................................................................22<br />

2.5.1. Local Variable Scoping..........................................................................................23<br />

2.5.2. Global Variables ....................................................................................................26<br />

2.5.3. Clearing Variables .................................................................................................27<br />

3. Programming Style.......................................................................................................................29<br />

3.1. Spacing and Formatting .....................................................................................................29<br />

3.1.1. Intra-Expression Spacing.......................................................................................29<br />

3.1.2. Line Breaking ........................................................................................................29<br />

3.1.3. Setting Brackets Apart...........................................................................................30<br />

3.2. Indentation .........................................................................................................................30<br />

3.3. Single Quotes vs. Double Quotes ......................................................................................32<br />

3.4. Choice <strong>Of</strong> Control Structures.............................................................................................32<br />

3.4.1. while/for.............................................................................................................33<br />

3.4.2. if/select.............................................................................................................34<br />

3.4.3. Strict Block Structure/Early Return.......................................................................35<br />

3.5. Size of a Function ..............................................................................................................36<br />

4. Unknown Spots .............................................................................................................................37<br />

4.1. Operator Overloading.........................................................................................................37<br />

4.1.1. Overloading crash course ......................................................................................37<br />

4.1.2. Overload syntax.....................................................................................................39<br />

4.1.3. Overloading example.............................................................................................45<br />

4.2. Operator Precedence And Associativity ............................................................................47<br />

4.2.1. Numeric Operators ................................................................................................47<br />

4.2.2. Relational Operators..............................................................................................48<br />

4.2.3. Logical Operators ..................................................................................................48<br />

4.3. Implicit Cast To Boolean ...................................................................................................49<br />

4.4. Functions ............................................................................................................................50<br />

4.4.1. Functions Without Parameters or Return Value ....................................................50<br />

4.4.2. Named Parameters.................................................................................................51<br />

5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!