Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

strictness and fully qualified global vars

6 views
Skip to first unread message

Alexey Trofimenko

unread,
Dec 28, 2004, 10:55:11 PM12/28/04
to perl6-l...@perl.org
in perl5 C<use strict> doesn't save us from typo bugs in code like

use strict;
print $OtherPackage::erroneuos_name;

in perl5 C<our $var> auotovivifies ${__PACKAGE__ . "::"}{var} glob at
compile time, so there's something one could check with C<exists>, but to
do it manually is senseless.
And there are no globs in perl6..

So, what about perl6? would it be possible to require declaration of
global vars before their first use, even if vars in question are in other
package? would it be default behaviour?

hmm, I wonder, is there any sense in C<our $Package::var> in that case.

P.S. I have one (almost unrelated to topic) observation: if sigil is a
part of a variable name, then C< Package::$var > makes more sense than
perl5 C< $Package::var >. (AFAIK, PHP5 works this way) And this requires
less magic from perl.
On the other hand it's considerably harder to interpolate that..

Ashley Winters

unread,
Dec 28, 2004, 11:44:47 PM12/28/04
to perl6-l...@perl.org
On Wed, 29 Dec 2004 06:55:11 +0300, Alexey Trofimenko
<la-t...@yandex.ru> wrote:
> P.S. I have one (almost unrelated to topic) observation: if sigil is a
> part of a variable name, then C< Package::$var > makes more sense than
> perl5 C< $Package::var >. (AFAIK, PHP5 works this way) And this requires
> less magic from perl.

I agree... that's inconsistent.

I have another question: Are package/class/grammar namespaces valid
objects in Perl6? I would assume yes, so you can call methods on them
for meta-purposes.

Would there be a default Namespace::postcircumfix:«< >» operator,
which would make the above code look like: Package<$var> aka
Package.<$var>? This would continue to make sense even when the
namespace objects are passed to a function:

sub foo (Class $who) {
my $thing := $who<$var>;
my &func := $who<&func>; # how would I do this otherwise?
}

I assume the second line can't really be done through stringification
due to singletons. Well, on second thought, you could make $foo.meta
(or whatever) start answering to CLASS(0xDEADBEEF) style classnames.
Those are probably needed for debugging or something anyways.

Ashley Winters

Luke Palmer

unread,
Dec 29, 2004, 12:31:47 AM12/29/04
to Ashley Winters, perl6-l...@perl.org
Ashley Winters writes:
> sub foo (Class $who) {
> my $thing := $who<$var>;
> my &func := $who<&func>; # how would I do this otherwise?
> }

In current Perl 6:

sub foo (Class $who) {
my $thing := $::($who)::var;
my &func := &::($who)::func;
}

However, I agree that $Package::var is weird since the variable's name
is $var, not just var. Package::$var looks really odd to me, but maybe
it's the right thing to do. For interpolation, we could just force
curlies; package variables aren't interpolated much anyway.

Luke

Ashley Winters

unread,
Dec 29, 2004, 1:31:37 AM12/29/04
to perl6-l...@perl.org
On Tue, 28 Dec 2004 22:31:47 -0700, Luke Palmer <lu...@luqui.org> wrote:
> Ashley Winters writes:
> > sub foo (Class $who) {
> > my $thing := $who<$var>;
> > my &func := $who<&func>; # how would I do this otherwise?
> > }
>
> In current Perl 6:
>
> sub foo (Class $who) {
> my $thing := $::($who)::var;
> my &func := &::($who)::func;
> }

Okay, I see. S10 says ::() is the catch-all symbolic naming syntax.
However, $who would be a reference to a class object itself. Does it
automagically accept hard-references, or would Class objects have to
stringify to their global ::*::ClassName?

More to the point, is %::(%foo) an identity op?

Ashley

Larry Wall

unread,
Jan 4, 2005, 1:55:59 PM1/4/05
to perl6-l...@perl.org
On Tue, Dec 28, 2004 at 10:31:37PM -0800, Ashley Winters wrote:

We will probably make hard refs work inside ::() just to make it easier
to translate Perl 5 to Perl 6. But possibly it should require a laxity
pragma to enable it. If we end up with people simply writing $::($x)
everywhere instead of ${$x}, we haven't gained anything over Perl 5,
and we've lost strict refs. I don't want people to get in the habit
of using ::() for hard refs unless they explicitly want symbolic refs
as well. I was hoping that the mere length of $::() over ${} would
be enough to discourage that kind of thinking, but now I'm not so sure.

Larry

0 new messages