On Mon, 2007-09-24 at 06:08 +1000, skaller wrote: Hmmm .. how about translating this:
> namespace Foo { val a = 1; } > namespace Foo { val b = 2; } > module Foo::Bar { val c = 3; } > > println Foo::a; > println Foo::b; > println Foo::Bar::c; > > open Foo; > println a; > println b; > println Bar::c; > > open Foo::Bar; > println c; To this: /////////////////////////// module _Foo_0 {} module _Foo_1 { inherit _Foo_0; val a = 1; } module _Foo_2 { inherit _Foo_1; val b = 2; } module _Foo_3 { inherit _Foo_2; module Bar { val c = 3; } } println Foo::a; println Foo::b; println Foo::Bar::c; open Foo; println a; println b; println Bar::c; open Foo::Bar; println c; module Foo { inherit _Foo_3; } ///////////////////////////// 1 2 3 1 2 3 3 /////////////////////////////// Now, this keeps the initialisation order 'in order of writing'. However lookup is NOT the same as a collated module. Each namespace can only refer backwards to previous definitions. Furthermore, you can 'override' a definition: namespace X { val x = 1; } namespace X { val x = 1; } // OK! because local definitions can hide inherited ones. There is another very sexy alternative that 'fixes' these problems: I'll illustrate with the implementation: //////////////////////////////////////// module A1 { inherit A; val x = 1; } module A2 { inherit A; val y = x+1; } module A { inherit A1; inherit A2; } open A; val c = A::x + y; println c; ////////////////////////////////////////// This allows us to look forward as well as backwards. What's more, with this change: module A2 { inherit A; val x = 22; val y = x+1; } we get: [EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ f ns Symbol 4762 Symbol 4766 CLIENT ERROR [lookup_name_in_table_dirs] Conflicting nonfunction definitions for x found in open modules In ./ns.flx: line 19, cols 1 to 17 18: 19: val c = A::x + y; ***************** 20: Hmm .. wow .. I'm always surprised when arcane features like 'inherit' actually works .. because I know how they're mis-implemented ... lol! At present the collation routine * Knows the first time a namespace is used * Is called at then end of the scope so either technique is trivial to implement. The only tricky thing is polymorphism .. I'm not sure if inherit's can be polymorphic, or if you can do specialisations like with open: inherit[t] A[t,t]; although that isn't needed here .. but module A1[t] { inherit A[t]; .. } is required. Oh, another tricky thing might be 'requires' clauses. So which is it? The chain or cycle? Or something else? The cycle is consistent with Felix approach that a scope is a set .. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language