HaloO,

David Green wrote:
On 2008-May-3, at 5:04 pm, John M. Dlugosz wrote:
What does this mean?

our sub outer ()
 {
  ...
  our sub inner () { ... }
 }


inner;  # defined?
>
I don't know why it would be any more illegal than "sub foo { our $var... }". The inner sub would be in the package's scope, but the name "inner()" would be available only in outer's scope. So that use of "inner" in the last line would be an error.

Why that? I would think assuming that inner has a defined body,
the our scope is around the outer somewhere. So the call there
should succeed. Or is this not like our works? I assume that sub
is not an our scope, BTW.

Just to ensure that I get the our behavior right, consider

    sub foo
    {
       our $inner = 3;
    }
    sub bar
    {
       our $inner = 4; # redeclaration error?
    }
    say $inner;

Does this print 3 even when foo was never called? IOW, is the assignment
in foo a real one that only happens when foo is invoked or is it a
pseudo-assignment that initializes the variables as if the whole
statement where outside of foo? The latter would actually mean that
the line in foo behaves different with or without the our. Without the
our, the say would print 3, 4 or undef depending on the call sequence of
foo and bar, right? Now how does that compare to sub definition?

    sub foo
    {
        our sub inner { 3 }
    }
    sub bar
    {
        our sub inner { 4 } # redefinition error?
    }
    say inner;

My favorite is what the spec already seems to say: a symbol can be
declared/defined exactly once in a scope. Usage prior to declaration/definition is an error. Usage of undeclared/undefined
symbols is parsed provisionally as if defined/declared with our
immediately before this use. Take e.g. class definition in a sub

    sub foo
    {
        our class inner { has $.x = 3 }
    }
    sub bar
    {
        our class inner { has $.x = 4 } # redefinition error?
    }
    say inner.new.x;

The consequence of a sub not doing Package is that there are
no separate foo::inner and bar::inner classes as in

    class foo
    {
        our class inner { has $.x = 3 }
    }
    class bar
    {
        our class inner { has $.x = 4 }
    }
    say inner.new.x; # error: no inner in scope


My personal idea is to unify class and sub by allowing sub to do
Package.

Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to