On Wed, Aug 10, 2005 at 10:47:47AM +0200, Juerd wrote:
: Larry Wall skribis 2005-08-09 16:19 (-0700):
: > So either something in the context tells us what "Foo" means, or
: > it will be taken as a list operator that hasn't been declared yet.
: 
: Is there, by the way, a pragma to force predeclaration of subs, to gain
: compile time typo checking?

You get compile time checking of those anyway--it's just deferred
a bit.  The undeclared list operator must be declared by the end of
this compilation unit or it's an error.  (We should probably say
the same for parenthesized calls.)  However, the visibility of an
autoloader turns off this compile-time error checking.

We can get away with this in Perl 6 because bindings to positionals
happen lazily.  So all we have to check for syntactically is that we
don't have a subsequent declaration that changes the syntax from list
to unary (or none-ary).

In the case of multi subs, there just has to be at least one
declaration visible by the end of the current compilation unit.
Since most such declarations will be made visible by "use" anyway, it
doesn't seem like a big problem.  At worst we might need a stub syntax
to declare that something is to be forced (like a class forcing role
methods to be multi) without declaring one of the actual multis.  So

    multi foo {...}

says that short name "foo" will eventually be a set of multies.

It would still be possible to have a pragma that forces predeclaration,
of course.  And lexically scoped subs always have to be predeclared.
You can't call a lexically scoped sub whose first "my" declaration is
after the call.

Hmm.  Does that mean that lexical stubs/subs are declared/defined like this:

    my sub foo {...}
    my sub foo { say "I'm real now" }

or like this:

    my sub foo {...}
    sub foo { say "I'm real now" }

The former seems cleaner somehow, except that it also implies that
multiple "my $x" are declaring the same $x.  I can see arguments for
both sides.  If &foo is just short for "sub foo", then the second
form should work just fine.  But people might prefer to my-ify the
second form just to document that it's not a package sub, and maybe
that should be allowed.

Larry

Reply via email to