develooper Front page | perl.perl5.porters | Postings from September 2011

Re: Package:: still ambiguous

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
September 14, 2011 06:59
Subject:
Re: Package:: still ambiguous
Message ID:
CAMoYMM_ciB054QkXq0OqX0gjwG0UWOv6V_i_xWV8joMqNc=b3Q@mail.gmail.com
On 14 September 2011 14:55, Zefram <zefram@fysh.org> wrote:
> Rafael Garcia-Suarez wrote:
>>>        $obj = $pkg->new();   # unambiguously call class method
>>
>>That works with $pkg being a string, right now.
>
> No, that's how I started this thread.  If $pkg is, say, the string
> "Foo::Bar", then it is ambiguous between the package Foo::Bar and the
> I/O handle *Foo::Bar{IO}.  The I/O handle meaning takes precedence,
> if there is a handle of that name.
>
> $ perl -E 'package Foo::Bar { sub say { say "Foo::Bar::say(@_)" } } open(\*Foo::Bar, ">&STDOUT"); $pkg = "Foo::Bar"; $pkg->say(123)'
> 123

I stand corrected.

>>I would prefer avoiding thinking about $pkg as a special kind of
>>object.
>
> You're thinking of "object" in the OO sense.  I meant it in the looser
> sense, of anything that the language can manipulate by first-class
> mechanisms.  It's an object in the same sense in which an (unblessed)
> array is an object.  We could well call it merely a "package".  It would
> probably end up implemented as an svtype, SVt_PVPK.

Yes : to avoid ambiguity I wrote "first-class feature" instead of
"first-class object". Indeed a new svtype sounds right for this.
The ambiguity here is fed by the syntax : $pkg->new looks like a
regular method call, but it's a a class method call.
Since you propose a new first-class object why not new syntax ? A new
sigil maybe ? (but it will be hard to shove a new sigil in the current
lexer)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About