Closures and CALLER

0 views
Skip to first unread message

Aaron Sherman

unread,
May 17, 2005, 1:42:23 PM5/17/05
to Perl6 Language List
Is it a bad sign that I'm still on the first section of S29, getting up
to speed? Sigh... I'll get there, really. This is another question from
my reading this morning.

Ok, so log and log10:

multi sub Math::Basic::log (: Num ?$x = $CALLER::_, Num +$base);
&log10<> := &log<>.assuming:base(10);

What does log get in this case:

for @x {
log10();
}

Does the curried log10 execute the defaulting for the sub it's based on
(and thus need run-time access to the default value, which I assume is
not in the signature) or does it leave defaulting up to log, in which
case, how does log find the right $_?

--
Aaron Sherman <a...@ajs.com>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback


Rod Adams

unread,
May 17, 2005, 2:01:48 PM5/17/05
to Perl6 Language List
Aaron Sherman wrote:

>Ok, so log and log10:
>
> multi sub Math::Basic::log (: Num ?$x = $CALLER::_, Num +$base);
> &log10<> := &log<>.assuming:base(10);
>
>What does log get in this case:
>
> for @x {
> log10();
> }
>
>Does the curried log10 execute the defaulting for the sub it's based on
>(and thus need run-time access to the default value, which I assume is
>not in the signature) or does it leave defaulting up to log, in which
>case, how does log find the right $_?
>

I had assumed that wrapper a curries function generates does not alter
who the CALLER is. Therefore, when log10() is called, the CALLER for
log() is the same as the CALLER for log10.

IMO, if this is not the case, it severely limits the utility of curried
functions. Comments from @Larry requested.

-- Rod Adams

Larry Wall

unread,
May 17, 2005, 5:20:45 PM5/17/05
to Perl6 Language List

Makes sense to me. I don't think .assuming should assume anything that
is not explicitly specified as assumed, so defaults should not resolve
till the "real" call.

Larry

Aaron Sherman

unread,
May 18, 2005, 4:30:13 PM5/18/05
to "TSa (Thomas, Perl6 Language List
On Wed, 2005-05-18 at 14:57, "TSa (Thomas Sandlaß)" wrote:

> Aaron Sherman wrote:
> > Ok, so log and log10:
> >
> > multi sub Math::Basic::log (: Num ?$x = $CALLER::_, Num +$base);
> > &log10<> := &log<>.assuming:base(10);
>
> Sorry, I don't want to interfere but two nit-pickings from me:
>
> 1) It's &log10:() and &log:(: Num ?$, Num +$) these days, isn't it?
> And I'm unsure about the meaning of the first. And shouldn't you
> use the ::= operator?

Yes on part 2, but on part 1... not sure. Anyone?

> 2) More important: isn't the multi without invocants useless
> or even outright wrong? Or shall it indicate an undispatched,
> compile-time, declaration-based, overloaded function ala C++?
> Does such a thing exist in Perl6?

I don't know the MMD system well enough to be sure (I became aware of
how multi subs work two days ago). Certainly S06 doesn't imply that this
is valid. I'll have to re-read the relevant bits of A12, unless a
certain former maintainer wants to speak up.... :)

Reply all
Reply to author
Forward
0 new messages