[Mono-dev] Functional programming like pure ansi C

Stefan Fink sf at granit.de
Thu Aug 16 05:38:39 EDT 2007


hallo,
we want to port our own scripting language (only the scripts) to mono (c#). i 
have a few questions :

1. Can i call a new Mono programm inside the other one ???

Example.....................

makro1.mak
--------------------------------------------------

program;
var
   int ret;
begin
    ret = MAKROSTART("makro2.mak HALLO");
    print string ("Makro 2 returned : "+ztostr(ret)+"\n");
end.



makro2.mak
----------------------------------------------------------------------
program;
var
  string str;
begin
    GET_VARTEXT("MAK_PARAM1",*str);
    print string (str+"\n");
    return(1);
end.




2. include functions from many files ????

Exampe........................


makro1.mak
------------------------------------------------

include("include1.mak");
include("include2.mak");
.....
....


program;
var
  real val,newval;
  string str,newstr;
begin
    str = "Hallo";
    newstr = strteil(str,1,2);
    print string (newstr);

   val = 0.2;
   newval = arccot(val);
   print string (ztostr(newval));
end.


include1.mak
----------------------------------------------

procedure strteil(string str, int pos, int anz);
var
   string newstr;
begin
 .....
    newstr = .....;
 ....
    return(newstr);   
end;

.....



include2.mak
---------------------------------------------------------

procedure arccot(real x);
begin
  return((PI/2)-atan(x));
end;

.....



3. call by value or call by reference ????


Example...............


makro1.mak
-------------------------------------------------------


procedure str_para (string s, string para, string trenner);
var
  int pos,len;
begin
  len = strlng(trenner);
  pos = strsuch(s,trenner);
  if (pos == 0) then
    pos = strlng(s)+1;
  para = strteil(s,1,pos-1);
  s = strentf(s,1,pos+len-1);
end;

program;
var
   string str,para;
begin
    str = "Hallo,du,Haus,Tanne";
   while (str != "") do
   begin
       str_para(*str,*para,",");
       print string ("Para : "+para+"\n");
   end;
end.


PS: * indicates call by reference       --      no * indicates call by value




4. evaluation at runtime

Example...........


program;
var
   int x,y,z;
begin
     x = 5;
     y = 6;
     z = berstr("x+y");
    print int (z);
end.


5. embedding mono in c / c++ application and call function from the script to
the application


Example..........


C-Application
----------------------------------------

void drawrect(double x1, double y1, double x2, double y2) {
...
}


void main() {
}


Mono Script (program)
--------------------------------------------------

....

  drawrect(1,1,5,5);
.....


-- 
Mit freundlichen Grüßen
   Stefan Fink



More information about the Mono-devel-list mailing list