1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Σύνταξη ανωτάτου επιπέδου</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Εγχειρίδιο Genius"><link rel="up" href="ch07.html" title="Chapter 7. Προχωρημένος προγραμματισμός με GEL"><link rel="prev" href="ch07.html" title="Chapter 7. Προχωρημένος προγραμματισμός με GEL"><link rel="next" href="ch07s03.html" title="Επιστροφή συναρτήσεων"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Σύνταξη ανωτάτου επιπέδου</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Προχωρημένος προγραμματισμός με GEL</th><td width="20%" align="right"> <a accesskey="n" href="ch07s03.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-toplevel-syntax"></a>Σύνταξη ανωτάτου επιπέδου</h2></div></div></div><p lang="en">
The syntax is slightly different if you enter statements on
the top level versus when they are inside parentheses or
inside functions. On the top level, enter acts the same as if
you press return on the command line. Therefore think of programs
as just a sequence of lines as if they were entered on the command line.
In particular, you do not need to enter the separator at the end of the
line (unless it is part of several statements inside
parentheses). When a statement does not end with a separator on the
top level, the result is printed after being executed.
</p><p lang="en">
For example,
</p><pre lang="en" class="programlisting">function f(x)=x^2
f(3)
</pre><p lang="en">
will print first the result of setting a function (a representation of
the function, in this case <code class="computeroutput">(`(x)=(x^2))</code>)
and then the expected 9. To avoid this, enter a separator
after the function definition.
</p><pre lang="en" class="programlisting">function f(x)=x^2;
f(3)
</pre><p lang="en">
If you need to put a separator into your function then you have to surround with
parenthesis. For example:
</p><pre lang="en" class="programlisting">function f(x)=(
y=1;
for j=1 to x do
y = y+j;
y^2
);
</pre><p lang="en">
</p><p lang="en">
The following code will produce an error when entered on the top
level of a program, while it will work just fine in a function.
</p><pre lang="en" class="programlisting">if Something() then
DoSomething()
else
DoSomethingElse()
</pre><p lang="en">
</p><p lang="en">
The problem is that after <span class="application">Genius Mathematics Tool</span> sees the end of line after the
second line, it will decide that we have whole statement and
it will execute it. After the execution is done, <span class="application">Genius Mathematics Tool</span> will
go on to the next
line, it will see <code class="literal">else</code>, and it will produce
a parsing error. To fix this, use parentheses. <span class="application">Genius Mathematics Tool</span> will not
be satisfied until it has found that all parentheses are closed.
</p><pre lang="en" class="programlisting">if Something() then (
DoSomething()
) else (
DoSomethingElse()
)
</pre><p lang="en">
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch07.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch07.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch07s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. Προχωρημένος προγραμματισμός με GEL </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Επιστροφή συναρτήσεων</td></tr></table></div></body></html>
|