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

single named param

12 views
Skip to first unread message

Gaal Yahas

unread,
Sep 12, 2006, 6:20:17 AM9/12/06
to perl6-l...@perl.org
I was writing tests for signatures and came across this ambiguity:

:(:$x)

Does this mean a single named parameter called $x, or a default invocant
and a single required positional named $x?

--
Gaal Yahas <ga...@forum2.org>
http://gaal.livejournal.com/

Gaal Yahas

unread,
Sep 12, 2006, 6:59:23 AM9/12/06
to aud...@audreyt.org, perl6-l...@perl.org
On Tue, Sep 12, 2006 at 06:46:50PM +0800, Audrey Tang wrote:
> >Does this mean a single named parameter called $x, or a default invocant
> >and a single required positional named $x?
>
> "A default invocant" prolly doesn't make sense there... There's
> nothing to "default" to. :-)

What invocant is constructed in this signature then?

method foo ($just_a_named_param)

Is the signature for &foo really the same as that of bar?

sub bar ($just_a_named_param)

I was sort of assuming you could tell by a signature if it was for a
method or a sub.

Audrey Tang

unread,
Sep 12, 2006, 6:46:50 AM9/12/06
to Gaal Yahas, perl6-l...@perl.org
2006/9/12, Gaal Yahas <ga...@forum2.org>:

> Does this mean a single named parameter called $x, or a default invocant
> and a single required positional named $x?

"A default invocant" prolly doesn't make sense there... There's


nothing to "default" to. :-)

Audrey

Larry Wall

unread,
Sep 12, 2006, 10:26:22 AM9/12/06
to perl6-l...@perl.org
On Tue, Sep 12, 2006 at 01:59:23PM +0300, Gaal Yahas wrote:

: On Tue, Sep 12, 2006 at 06:46:50PM +0800, Audrey Tang wrote:
: > >Does this mean a single named parameter called $x, or a default invocant
: > >and a single required positional named $x?
: >
: > "A default invocant" prolly doesn't make sense there... There's
: > nothing to "default" to. :-)
:
: What invocant is constructed in this signature then?
:
: method foo ($just_a_named_param)
:
: Is the signature for &foo really the same as that of bar?
:
: sub bar ($just_a_named_param)

Maybe methods and submethods turn

method foo ($just_a_named_param)

into

method foo ($ : $just_a_named_param)

Since we regularized invocants, there's much less need for an empty
invocant, so maybe the $ is required there if you put the :. If so, we
should probably explicitly say that there are no variables of the form
"$:", "$;", or "$,", so those will always be taken as "$ :", "$ ;", and
"$ ," respectively. At least within signatures.

In any case, prefix ':' is not an operator. In :(:$foo) the :$
starts a token, so you'd have to put space between to mean :(: $foo).

: I was sort of assuming you could tell by a signature if it was for a
: method or a sub.

I'm trying to decide if

sub ($self: $just_a_named_param)

can meaningfully put anything into $self. It seems doubtful, and it should
probably be

submethod ($self: $just_a_named_param)

So for the jet-lagged moment I think your assumption is valid. I might
jet-delag at any moment, however...

Larry

Mark Stosberg

unread,
Sep 12, 2006, 1:08:55 PM9/12/06
to perl6-l...@perl.org
Larry Wall wrote:
>
> I'm trying to decide if
>
> sub ($self: $just_a_named_param)
>
> can meaningfully put anything into $self. It seems doubtful, and it should
> probably be
>
> submethod ($self: $just_a_named_param)

I agree. If

sub ($self: $foo)

works than it reduces privacy, since someone could call a sub like
externally, when it wasn't intended.

Mark

Audrey Tang

unread,
Sep 12, 2006, 7:46:35 PM9/12/06
to Gaal Yahas, perl6-l...@perl.org

在 Sep 12, 2006 6:59 PM 時,Gaal Yahas 寫到:

> What invocant is constructed in this signature then?
> method foo ($just_a_named_param)
>
> Is the signature for &foo really the same as that of bar?
>
> sub bar ($just_a_named_param)

As Larry said, they shouldn't be the same; the first one is

&foo.signature === :($ : $just_a_named_param);

The second one is:

&bar.signature === :($just_a_named_param);

> I was sort of assuming you could tell by a signature if it was for a
> method or a sub.

That's correct; the "method" keyword augments the signature with an
unnamed
"$" invocant if it's not explicitly specified. (In Pugs.Val.Code
terms, that's nullID for
both the p_label slot and (v_name . p_variable).)

Cheers,
Audrey


0 new messages