Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Functional Programming & method rewriting

by ihb (Deacon)
on Oct 30, 2004 at 21:21 UTC ( [id://404062]=note: print w/replies, xml ) Need Help??


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.

{ my $foo; sub foo { 1 } } # not a closure { my $foo; sub foo { $foo } } # a closure
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.

Your point is supported by that we don't usually call &foo in

my $GLOBAL = 1; sub foo { ... ; ... $GLOBAL ... ; ... ; }
a closure. However, it is a closure and it's not wrong calling it one.

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

    First off, I want to thank you for actually engaging in a conversation, rather than simply writing me off as whiney and pedantic. I posted about something that I wanted to discuss, not just whine about. :-)

    That it doesn't go out of scope doesn't make it less of a closure, but its closureness doesn't get used.

    Indeed, that's true. I suppose I shouldn't try to fight against the technical definition. Rather than saying it's not a closure, I should have said it's not very useful to talk about its closure-ness.

    However, it is a closure and it's not wrong calling it one.

    Ok, fair enough. I officially change my position on the matter. Again, thank you for responding. I hope our friend SpanishInquisition is not too upset about the matter to read what I've written here, so he won't think I'm a completely horrible person.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://404062]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found