clarification on namespaces

Lars T Hansen lth at acm.org
Mon Jun 11 05:09:44 PDT 2007


"namespace" is not a pragma, it just creates a new namespace object
with some identity.  You can pass these around as values:

  namespace ns1, ns2;

  var x = ns1;
  new Name(x, "foo")

you can't use namespace values in declarations, so "x var int y = 37"
won't do, but IIRC you can use them in expressions, eg x::y.  From the
reference implementation:

>> namespace ns = "foo";
>> ns
[user-defined namespace foo]
>> var v = ns
>> v
[user-defined namespace foo]
>> ns var x = 10
>> x
[stack] []
**ERROR** EvalError: uncaught exception: ReferenceError: unresolved
lexical reference {multiname: [ns public '']::x } (near
builtins/Error.es:83.47-83.47)
>> ns::x
10
>> v::x
10

--lars

On 6/11/07, Peter Hall <peter.hall at memorphic.com> wrote:
> On 6/11/07, Lars T Hansen <lth at acm.org> wrote:
> > Nit: The way I currently understand the spec the first argument to the
> > Name constructor if called with two arguments must be a namespace
> > value, not a string, but this introduces no particular problems:
> >
>
> is it necessary to use the pragma? Surely you create a new
> Namespace()... otherwise it does introduce a problem..
>
> Peter
>



More information about the Es4-discuss mailing list