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 );
Le code suivant provoque une erreur lorsqu'il est saisi au niveau supérieur d'un programme alors qu'il fonctionne très bien dans une fonction.
if QuelqueChose() then FaireQuelqueChose() else FaireAutreChose()
Le problème est que lorsque l'Outil de maths Genius rencontre la fin de la ligne après la seconde ligne, il décide que l'instruction est complète et il l'exécute. Après l'exécution l'Outil de maths Genius se rend à la ligne suivante, voit l'instruction else
et affiche une erreur de syntaxe. Pour régler ce problème, utilisez des parenthèses. L'Outil de maths Genius ne sera pas satisfait tant qu'il n'aura pas trouvé que toutes les parenthèses sont fermées.
if QuelqueChose() then( FaireQuelqueChose() ) else ( FaireAutreChose() )