Felix has a number of shortcuts some of which are useful and others not so useful. Not so useful ones impose brain overload on the beginning (and experienced) programmer.
So I'm reading the tutorials and I want to chuck out half the stuff in the introductory tutorial because it's headed up by "Scripting Technology" which means "simply stuff to write one off programs with". Some stuff will get moved, and some RE-moved. Here are two candidates for removal. 1. fun variables // do "fun" vars really work? var a = 1; fun f : int => a; println$ f; ++a; println$ f; proc pf(fun f:int) { println$ f; } pf {a}; ++a; pf {a}; What's a fun var you say? I asked that too and had to experiment to find out :) Basically a fun variable is a function which is usually defined as an expression depending on mutable state. The key feature is that the "variable" magically changes as the variables its initialiser depend on change. In other words, its lazy evaluation! As you can see, a fun variable of type T is REALLY an impure accessor function of type 1 -> T. When you write the variable name, f in the above example, it is magically applied to () to get its current value. So passing an expression to fun parameter means passing a closure (modulo inlining of course). You can see this in the actual call above: pf {a}; Since a is an int, and {a} is a shorthand for fun () => a and the REAL type of the procedure pf is (1->int) -> 0 we have to actually pass a closure explicitly. Unlike the local variable case the "conversion" is not done automatically. This stuff was implemented before I invented the # shorthand: #f // means f () So basically all "fun" variables do is save writing: fun f () => a; // can use fun f => a; instead #f // can use f instead Conceptually the IDEA is that this is a variable lazily evaluated and it is in the language to "balance out" a normal var, which is eagerly evaluated, and val which could be either. We have 3 evaluation strategies and 3 kinds of variable. But who can remember fun f => a notation, using => instead of = ?? Is it useful? I don't think I ever used it. Should I remove it or is the symmetry worthwhile? 2. ref variables This is exactly the same idea as fun variables. // What do ref variables do? ref pa <- a; println$ pa; ++a; println$ pa; proc pr (ref pa:int) { println$ pa; } pr &a; ++pa; pr &a; A ref variable is just a pointer. It is initialised by the syntax ref v:int <- a; but the REAL type is &int. When a ref variable is seen it is magically dereferenced. As you can see, you have to pass a pointer to a procedure with a ref parameter. Ref variables are sort of like C++ references (hence the name). Now the evaluation strategy intention here requires you understand that there is actually a FOURTH evaluation strategy in Felix: explicitly controlled evaluation strategy. This strategy is a special one that ONLY applies to objects (i.e. storage locations) not general expressions. We take the address of the storage location, deferring WHEN we will fetch the value to a later decision. We can then fetch the value at some time and KEEP that value in another place. So we are above to fetch a value at a particular time t1 and use it later at time t2. And modification prior to t1 influence the value fetched, modification after t1 have no impact. Of course you KNOW how pointers work! And you must realise that the time at which you evaluate a dereference is cruicial If the dereference is delayed by lazy evaluation or brought forward by eager evaluation from what you expect, you may get the wrong value. SO .. in keeping with the idea that using pointers is yet another "hook" into control of evaluation strategy -- a sort of "closure" for data if you like -- we have a special name for it: ref. But all this was before I invented the new syntax p*.mem // same as (*p).mem v&.mem // same as (&v).mem which allows some expressions to be written without parenthesis clutter. SO I am thinking to GET RID OF fun and ref variables. Any comments appreciated. It's a tradeoff between symmetry "in principle" with the fact I never use these things and can't remember what they do anyhow :) -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language