but sometimes unexpected when you don't know! :)

Hi,

I was playing around with using library functions to clarify my next 
question, when I encounted the optimizing features of felix. I had 
actually encountered it before when I was comparing performance between 
felix and ocaml when I thought the console output might be skewing the 
results because the ocaml version seemed to be buffering, so I removed 
the display of the results of the tests, and suddenly felix was 
infinitely more efficient than ocaml because it saw running the function 
was useless, as the result wasn't being used. Pretty cool!

Anyway, how do you use an external function that has side-effects, and 
still get the result? I had inferred a guess about generators from 
comments (the manual doesn't seem to have caught up to them yet) using 
"gen jseek ..." but that gives the same results.

I'm using svn from a few days ago (the current head build crashes).

//------------
#import <flx.flxh>

open Long;
type file = "FILE *";
fun jopen: string -> file = 'std::fopen($1.data(), "rw")';
fun jvalid : file -> bool = '$1!=(FILE*)0';
fun jseek: file * long * int -> int = 'std::fseek($1, $2, $3)';
proc jclose: file = '(void)std::fclose($1);';
fun jtell: file -> long = 'std::ftell($1)';

var fil = jopen ("t.txt");
if jvalid fil do
    print "jopen returned 0\n";
else
    print "jopen returned ... something\n";
done;
val x = jseek(fil, 0L, 2);
// uncommenting out the following to stop previous being elided
//print "jseek returned ";
//print x;
//endl;
val p = jtell(fil);
print "file size is ";
print p;
endl;
jclose(fil);
//------------

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to