The first object |

anfang(), ende()(the German word for beginning and for end) in between these we have to write our programs. Therefore the smallest example of a main() routine inside SYMMETRICA is the following:

main() { anfang(); ende(); }This routine is of course not very exciting, since just nothing happens if it is carried out.

To begin with the object oriented way of evaluation of *n!* we have to define a function
that associates with an
object called *input* an object called *output* in such a way that
if input is the object arising from the number *n*, the output object is
the object corresponding to the desired number *obfak(n)*. We call this
function that hopefully does what we want

obfak(input,output)Since we have to tell the computer that input and output are meant to be objects, the definition will start as follows:

obfak(input,output) OP input, output; { }Note that

Then we have to introduce further variable objects which we shall need later on
in the recursion, let us call them *h1,h2*. We have to reserve storage space
for these variables which will be objects, and therefore we include a line
*OP h1,h1;*
Hence the first lines of the program now look as follows:

obfak(input,output) OP input, output; { OP h1,h2; }In order now to program the recursion we have to begin with the starting values

einspand

m_i_iallows to build an object from a number. Hence the desired routine looks as follows:

obfak(input,output) OP input, output; { OP h1,h2; if (einsp(input)) return(m_i_i(1L,output)); }Now we are going to program the recursion formula where the variable objects

obfak(input,output)\\ OP input, output; { OP h1,h2; if (einsp(input)) return(m_i_i(1L,output)); h1=callocobject(); copy(input,h1); dec(h1); h2=callocobject(); obfak(h1,h2); mult(h2,input,output); freeall(h1); freeall(h2); }(The command

#include "def.h" #include "macro.h" main() { OP a,b; anfang(); a= callocobject(); b= callocobject(); scan(INTEGER,a);obfak(a,b);println(b); freeall(a);freeall(b); ende(); } obfak(input,output) OP input, output; { OP h1,h2; if (einsp(input)) return(m_i_i(1L,output)); h1=callocobject(); copy(input,h1); dec(h1); h2=callocobject(); inc(h1); obfak(h1,h2); mult(h2,input,output); freeall(h1); freeall(h2); }This is the complete program (it can be found in

makeAfter a short while, if

a.outto run the program. You will then be asked for an integer. You will find on your screen the following prompt:

integerobjectYou answer this question by typing, say 10 an then you press the return key. After a very short time you will get the reply 3.628800 (Note that long integers are broken up into groups of 6, seperated by a dot.) You can rerun the program typing

harald.fripertinger@kfunigraz.ac.at,

last changed: November 19, 2001

The first object |