On Mon, 2006-10-02 at 12:49 +1000, Jonathan Kelly wrote:
> > (a) make x a var (iable)
> > (b) make jseek a gen (erator)
> > (c) write
> >
> > ignore(jseek(fil,0L,2))
> I'm not sure how to turn it into a generator. I tried
>
> gen jseek: file * long * int -> int = 'std::fseek($1, $2, $3)';
Yes, that's right.
> but it still ellided the call. Changing the val to var didn't help
> either.
Damn cat is smarter than me :)
> It's probably a silly example as I would test the value anyway,
> but I am more interested in how to define an external function so even
> if I ignored the return value, it doesn't optimise away the
> side-effects, which is what I'm guessing a generator is.
If you use a proc, it will call it: for example
proc jseek: ptr[int] * file * long * int =
"*$1=std::fseek($2,$3,$4);"
;
var x : int;
jseek(addr x, fil, 0L, 2);
A generator isn't quite a function with side effects.
Actually what it is is a function which has to be
called as written, not duplicated. So it is lifted
out of an expression.
In theory, generators may have 'internal state' but
not external side effects. The canonical examples are
random ()
malloc (99)
new Anything (..)
next_integer()
These things are not transparent like 'sin x' which
can be copied about and always gives the same result.
They have state .. but not side effects like changing
visible variables etc.
Still, it looks like a bug that a call to a generator
can be elided. The intuitive rule is that they must
be called exactly the number of times they're
physically written in the code.
There is a specific 'unused variable elimination' pass
in the optimisation schema, it's the guilty party.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
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