|
On 28 Sep 2006, at 01:41, Glenn Maynard wrote:
In case anyone's wondering, my own pet operator is unary +. I have a lot of coordinates specified in Lua expressions, and I hate having to write "10, -10" instead of "+10, -10". It doesn't even add anything to the VM, just parse it out and treat it as a no-op. (This one feels like something basic and fundamental missing from the language to me, where none of the others have.)
I think you could argue that one should have unary plus on grounds of symmetry. :)
I don't think it would be a no-op, it should coerce its operand to a number, just like unary minus does:
x='11' y='-'..x print(-x, -y)Did you know unary minus did that? It doesn't seem to be a very widely advertised feature.
One could avoid unary plus adding to the VM by compiling +x as (- - x) which would in most cases get constant folded anyway.
In AWK unary plus is my favourite "coerce to number operator", I'd much rather use it than the traditional suggestion of "_ + 0". It even works properly on some versions of AWK.
drj