I'm a bit unhappy with variables and functions. Functions in Felix may not have side effects, but they're not referentially transparent because they can still depend on variables in their context.
I'd like to split them up into pure functions and the other kind. fun ... pure method .. may depend on variables Neither can modify their environment. There's a similar problem with "val" style variables (only worse); A val takes on the value of its initialiser when control passes through it, so it can depend on variables. The value cannot change, but it does depend on when the val is initialised. Worse, you can currently initialise a val twice, and, you can refer to it before it is initialised: var z = x; // not init yet var y = 1; label:> val x = y; // multiple initialisations ++y; goto label; I think I would like: const x = expr; // may not depend on variables Reference before use and multiple initialisation can be prevented for consts, by evaluation them all at the top of a function in order of dependencies (topological sort). A const cannot depend on a val parameter. This is because vals can be lazily evaluated, and so have a different value depending on when their initialising expression is evaluated. Hmmm. In fact because of this indeterminacy, you're not supposed to pass expressions to vals which contain generators. interestingly in functions (or methods) its safe to pass expressions depending on variables! This is because during execution, the value of the variable cannot change. HOWEVER if a closure is formed, all bets are off. We don't know when the closure will be executed so the variable could change between the point of closure formation and execution. This is a know problem in Felix (its NOT a bug, but its hard to deal with: for var i in 0 upto 10 do spawn_fthread { println$ i; }; done True the fthread is a procedure, but the point remains that this exact problem has bitten almost everyone: all the fthreads can print 10. you cannot fix this with a closure either, not even my passing i as an argument: proc f (y:int) () { println$ y; } for var i in 0 upto 10 do spawn_fthread ( f x ); done Doesn't help, because proc f will be inlined. It follows const expressions can only depend on consts and funs, not vals, vars, methods, or generators. [marking f noinline fixes it, but that's an implementation detail!] Unfortunately const is already used: const x : int = "x"; so I propose to change that to expr x : int = "x"; because actually the RHS can be any expression. in fact this is just an argument-less version of fun f: unit -> int = "x"; -- 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