in reply to Re: Functional Programming & method rewriting
in thread Functional Programming & method rewriting
About closures.
I don't generally use the hyper-technical definition that a closure is "anything that closes around a lexical", because that's true of any subroutine that is in a lexical environment.
I'm not sure how to interpret you, but it seems we view things differently. Either way a clarification probably would serve well. My definition of a closure in Perl is a subroutine that (deeply) binds a lexical variable. Whether it's called once or twice or a thousand times isn't relevant.
It's not about being "hyper-technical", it's about getting at the essence of what a closure is. That the bound variables doesn't go out of scope doesn't make it less of a closure, but its closureness doesn't get used. I understand that this is your point and I can almost sympathize with it, but just almost. It would be very confusing if a subroutine first wasn't a closure, but then became one when it was returned or assigned to variable with a broader scope.{ my $foo; sub foo { 1 } } # not a closure { my $foo; sub foo { $foo } } # a closure
Your point is supported by that we don't usually call &foo in
a closure. However, it is a closure and it's not wrong calling it one.my $GLOBAL = 1; sub foo { ... ; ... $GLOBAL ... ; ... ; }
ihb
See perltoc if you don't know which perldoc to read!
Read argumentation in its context!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Functional Programming & method rewriting
by revdiablo (Prior) on Oct 30, 2004 at 22:11 UTC |