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 of course 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.
For example,
function f(x)=x^2 f(3)
will print first the result of setting a function (a representation of
the function, in this case (`(x)=(x^2))
)
and then the expected 9. To avoid this, enter a separator
after the function definition.
function f(x)=x^2; f(3)
If you need to put a separator into your function then you have to surround with parenthesis. For example:
function f(x)=( y=1; for j=1 to x do y = y+j; y^2 );
Následující kód skončí chybou, pokud jej zadáte v nejvyšší úrovni programu, zatímco ve funkci bude pracovat bez problémů.
if Neco() then UdelatNeco() else UdelatNecoJineho()
Problémem je, že po té, co matematický nástroj Genius uvidí konec řádku po druhém řádku, usoudí, že příkaz už je celý a provede jej. Po té, co je provádění dokončeno, bude matematický nástroj Genius pokračovat na následujícím řádku, uvidí else
, a vyvolá chybu zpracování. Řešením je použít závorek. Matematický nástroj Genius nebude spokojen, dokud nenalezne všechny závorky uzavřené.
if Neco() then ( UdelatNeco() ) else ( UdelatNecoJineho() )