On 18/08/2012, at 4:28 AM, Dobes Vandermeer wrote: > > Parameters are not supposed to behave this way unless you tell them to ... > this is ridiculous. If you don't think this is a bug, you are insane.
It's known I'm insane :) It's not a bug. You DID tell them to. The default for parameters is "val". By using a val parameter you're allowing the compiler to choose the evaluation strategy. That's the specification. Its not a bug. I agree it leads to surprises, the question is: how do we fix it WITHOUT losing optimisation opportunities? if you need eager evaluation: proc b(var i:int)() = { // ^^^^ // i += 1; println$ "b, i = "+i; } proc a() { var i = 0; bb := b(i); i = 10; bb; } a(); // prints b, i = 0 ^^^^^^^^^^^^^ Or: noinline proc b(i:int)() = { //^^^^^^ // i += 1; println$ "b, i = "+i; } proc a() { var i = 0; bb := b(i); i = 10; bb; } a(); // prints b, i = 0 You should note that inline has semantics precisely because it controls evaluation strategy. Unlike C/C++, where evaluation is fixed at eager for function calls (and lazy almost everywhere else), up to "sequence points". You probably know some things in C/C++ aren't specified: x[i++] = x[i++] or something like that (its not undefined, just unspecified which order is used). In Felix its the same, evaluation strategy of vals/functions is unspecified (eager or lazy) by default, or explicitly val, but you can control it as in C -- rewrite you code using var, noinline, pointers, or some other mechanism that resolves it. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language