04.03.2013 Aufrufe

PDF-Version - am Institut für Baustatik

PDF-Version - am Institut für Baustatik

PDF-Version - am Institut für Baustatik

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

f (1,2);<br />

5<br />

For more complicated functions, the procedure statement can be used. Its syntax is:<br />

proc (n<strong>am</strong>e-sequence)<br />

local n<strong>am</strong>e-sequence;<br />

global n<strong>am</strong>e-sequence;<br />

options n<strong>am</strong>e-sequence;<br />

statement-sequence;<br />

end;<br />

The proc (n<strong>am</strong>e-sequence) is the procedure header, and the n<strong>am</strong>e-sequence is a formal par<strong>am</strong>eter<br />

list. These are the internal variable n<strong>am</strong>es for values that you would pass during calls to the<br />

procedure. The global and local n<strong>am</strong>e-sequence are optional clauses listing the global and local<br />

variables, and options n<strong>am</strong>e-sequence is an optional clause of settings that influence the procedure's<br />

behaviour at runtime.<br />

Notice that there is no specification for the n<strong>am</strong>e of the procedure. Since procedures are objects that<br />

can be assigned to variables, the n<strong>am</strong>e of the variable you assign it to is used as the n<strong>am</strong>e of<br />

procedure. The value of the procedure is usually the value of the last expression evaluated. Other<br />

values may be returned by using explicit return, error return, or return through a par<strong>am</strong>eter. See the<br />

Maple V Progr<strong>am</strong>ming Guide for more information on return types.<br />

Ex<strong>am</strong>ple:<br />

> # Out of curiosity, see if "x" is a mathematical<br />

variable:<br />

> x;<br />

x<br />

> f := proc(x)<br />

> x^2 + 1;<br />

> end;<br />

f := proc(x) x^2+1 end<br />

> f(2);<br />

5<br />

> x;<br />

x<br />

In this ex<strong>am</strong>ple, the global variable "x" is not affected by the formal par<strong>am</strong>eter "x", which is local to<br />

function "f".<br />

11.6.2.1 Local Variables<br />

In addition to global variables, local variables may be used in procedures to make temporary<br />

assignments without affecting the rest of the Maple session. Changing the value of a local variable in a<br />

procedure does not affect the value of a variable with the s<strong>am</strong>e n<strong>am</strong>e in another procedure, or of a<br />

global variable of the s<strong>am</strong>e n<strong>am</strong>e. Changing the value of a global variable changes it for the entire<br />

Maple session.<br />

Local variables also have one other very important distinction: they are not subject to the default full<br />

evaluation. This is because local variables commonly do not require full evaluation, so performance is<br />

improved by this exception to the general evaluation scheme.<br />

Ex<strong>am</strong>ple:<br />

> # Set value of global "a":<br />

> a := 0;<br />

a := 0<br />

> g := proc(x)<br />

> local a, b;<br />

> a := b^2 + x;<br />

> print(a);<br />

122

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!