On Mon, 2007-09-03 at 10:34 +1000, skaller wrote:
> I am changing the operator . rules: in

OK, I have changed the semantics so that in 

        LHS . RHS

If LHS is a nominal type and RHS = name it tries Koenig lookup
on get_name first, then tries to do ordinary function lookup.

This should preserve the semantics of all programs using get_* methods.
You should note:

        module X { 
                struct Y { int x; }; 
                fun get_y(Y a)=> x * x; // y is defined as x squared
        }
        var a = X::Y 2;
        fun y(a: X::Y)=>a.x - 1;
        println a.y; // prints 4

Even though a local y function is defined, the get_y from
module X is preferred. This may seem counter-intuitive BUT
there is a reason:

        module X { 
                struct Y { int x; }; 
                fun get_y(Y a)=> x * x; // y is defined as x squared
        }
        var a = X::Y 2;
        var y = a.y; // OK!

Now you see, if the local y were used, we'd get a type error.

WELLLLLLlllll .... actually we wouldn't. Because already the
code is equivalent to:

        try get_y a in X
        with _ -> try y a

in other words, an error is simply ignored and the next lookup
tried.. so actually if we swapped the order around, the type
error would be ignored and we'd proceed to method lookup next.

Anyhow, note that get_* names ONLY work with nominal types
and Koenig lookup (lookup in the module in which the type
is defined).

And remember the reason for that lookup:

        var a = X::Y 2;

the module X isn't open.. so in 

        a.y

a normal lookup wouldn't find the projection function for y.

We have now the guideline:

        LIBRARY WRITER:
        IF your type is nominal, and you want a user defined
        projection function, put a get_* method in the same module
        as the type is defined (non-nominal types like tuples 
        don't have definitions, hence the restriction to nominal types).

        LIBRARY USER:
        OTHERWISE just use the name you want in a scope visible
        from the access expression (a.y above).

And remember: if you write

        px . f // px a pointer

it means

        (*px) . f

You cannot write projections for pointers.

        
-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to