On Fri, 2002-04-12 at 09:52, Jonathan Scott Duff wrote:
> On Fri, Apr 12, 2002 at 09:40:16AM -0400, Aaron Sherman wrote:

> > >     sub printRec()     { printRec($_) } # No args, therefore no new topic.
> > >     sub printRec($rec) { .chomp; print ":$rec:\n" } # 1 arg
> > 
> > I think was he was saying is that your first printRec would not have a
> > $_ available to it (lexically scoped, as I understand it).
> > 
> > You've got a problem here, which I don't think there's a mechanism for.
> 
> If $_ is lexical by default (did larry say this somewhere?), then I'm
> sure we can make it dynamic on request ala:

Nope, I don't think that works. If the caller of printRec has to do
something special, we're meeting the original request which is to be
able to write print, which scoops up $_ without any special case code.

Now, we can say, "you just can't ever write print." I can understand why
we would, but why NOT just allow the subroutine author to indicate that
the subroutine acquires the current topic as a parameter default? It
would seem nice and clean. Either

    foo($a=$_){}
    
as Graham suggests, or

    foo(->$a){}
    
which was mine. Either one works. I guess with the aliasing of $_,
Graham's seems cleaner to me.

Of course, the other conversation pending, we might end up with:

    foo($a//=$_){}

which doesn't do the same thing as print, but may be the best we can do
with the syntax we have.

> I read the original posters message the same as Piers though.

Ok, what did you get from it that's different?


Reply via email to