SPUG: It gaugtht bettuh...
Dave Olszewski
cxreg at pobox.com
Fri Jul 8 09:08:21 PDT 2016
On Fri, 8 Jul 2016, Mark Hinds wrote:
> Dyck, David wrote:
> > It's been a while since I read
> > http://perldoc.perl.org/perlref.html#Function-Templates
> >
> > Did you see this note at the bottom:
> > CAVEAT: Aliasing does not work correctly with closures. If you try to
> > alias lexical variables from an inner subroutine or eval, the aliasing will
> > only be visible within that inner sub, and will not affect the outer
> > subroutine where the variables are declared. This bizarre behavior is
> > subject to change.
>
> Hi Dave,
>
> Interesting, but I'd never even think use such a construct. Even if I did
> want to create a local function it could simply put it into a simple
> my variable and all would be well, no?
>
> HandleEvent(SomeEvent, sub {
> my $x = $_[0] + 23;
> my $localFunc = sub { return $x *2 };
> return $localFunc->();
> });
I haven't experienced this as it relates to a pretty new feature of Perl
(lvalue references), but it sounds more nuanced
sub foo {
my $x = 1;
my $bar = sub {
\(my $y) = \($x);
$y = 3;
}
return $bar;
}
so in that case, the $x in the returned closure would be aliased and
modified by the assignment to $y, but the outer closed-over $x is not
affected.
>
>
>
>
>
>
> > -----Original Message-----
> > From: spug-list [mailto:spug-list-bounces+david.dyck=fluke.com at pm.org] On
> > Behalf Of Mark Hinds
> > Sent: Thursday, July 7, 2016 7:06 AM
> > To: SPUG Members <spug-list at pm.org>
> > Subject: SPUG: It gaugtht bettuh...
> >
> >
> > OK, it looks like this list isn't quite dead yet... :-)
> >
> > I've been using perl since sometime back in the 90's.
> >
> > I ended up using it in an embedded linux system about 10 years ago
> > to replace a guile based scripting engine - That's one ugly M...
> >
> > I used mod Event to create a pure event system to handle bunches of
> > serial IO and timer events. Worked/works great. Perl is a quite
> > a CPU big, but still compares well with other dynamic languages.
> >
> > Seems that Python has taken over from Perl these days. I never liked
> > Python - using indention as fundamental element of syntax is obnoxious -
> > IMHO.
> >
> > I suppose Perl's goofy syntax make people cringe - I find it a rather
> > charming idiosyncrasy myself :-)
> >
> > Question - Perl's anonymous functions seem to operate perfectly well
> > as closures - they capture the referenced environment properly and
> > free it when they themselves are no longer referenced. The guile
> > folks disputed that me those many years ago. Thoughts?
> >
> >
> >
> >
> >
> >
> > _____________________________________________________________
> > Seattle Perl Users Group Mailing List
> > POST TO: spug-list at pm.org
> > SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> > MEETINGS: 3rd Tuesdays
> > WEB PAGE: http://seattleperl.org/
> >
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays
> WEB PAGE: http://seattleperl.org/
>
>
More information about the spug-list
mailing list