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.

function y ..<br />

= foo(x)<br />

function y = foo(a, b, c, d, ..<br />

e, f, g, h)<br />

The following examples are all illegal:<br />

function y = foo(x) // This is foo!<br />

function y = save_space(x); y = 1 + x<br />

function y = bar(x) ..<br />

y = 1 + x<br />

See also Section 4.4.<br />

2.4. Last Newline<br />

Chapter 2. Pitfalls<br />

The last line in a <strong>Scilab</strong> script is ignored if it is not terminated by a newline. 1 This is emphasized at<br />

several places in the official <strong>Scilab</strong> documentation, but it is so common to forget it especially when<br />

using emacs that we repeat it here. emacs however can be told always to add a final newline by<br />

adding (setq require-final-newline t) to the startup-file, .emacs. See “Learning GNU<br />

Emacs” [Cameron:1996] , Table C-8.<br />

Another weapon against this kind of syntax flaw, and a few other pesky things, is e.g. the Perl-script<br />

shown in Example 2-2, which fixes part of the format of a <strong>Scilab</strong> script.<br />

Example 2-2. Canonicalization of <strong>Scilab</strong> files<br />

use Text::Tabs;<br />

while () {<br />

chomp; # remove newline if there is one<br />

tr/\200-\377/ /; # map 8-bit chars to spaces<br />

s[\s+$][]; # kill whitespace at end of line<br />

$_ = expand $_; # convert tabs to spaces<br />

print "$_\n"; # print adding a newline<br />

}<br />

1. On UNI* systems the line terminator is ^J, which is writtan in C-style \n most of the time.<br />

22

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

Saved successfully!

Ooh no, something went wrong!