[DGD] function pointers
Noah Gibbs
noah_gibbs at yahoo.com
Sat Jun 25 10:08:45 CEST 2011
Real closures do significant variable binding -- the mapping of variable names to variable values that exists when the closure is created. The simple object/method pair doesn't do anything of the kind. Dworkin's patch gives function pointers/values, but doesn't do closures, of course.
If you're saying, "what are closures good for?", the answer is that the closure encapsulates state (private variables, but handled without having to manually copy every value the function might depend on, for all point-able functions, and far more efficient than a full copy). That can be useful for privacy. It can be useful for "snap shots" -- having the returned value depend on what state was when the closure was created, not when it's evaluated. It can be useful for mappings or similar higher-order functions that don't always do the same thing. Mapping the "times two" operation doesn't benefit from closures, but mapping the "times the area of the polygon I'm currently iterating over" operation probably does.
Nothing *requires* this, of course. Obviously we're all talking Turing-complete languages here, so you can always claim false equivalence through the (mathematically proven) argument that "well, sure, but you can build anything out of anything." Closures are still very convenient things.
The DGD hack for function pointers is a less-convenient way to deal with them than real function values -- which is fine, the language lacks the vast majority of the abstractions you'd want to take real advantage of that. It's not that sort of language. The same may be true of closures, hard to say. But closures are still tremendously useful in a language designed for higher-order functions, and with proper facilities for them.
This sounds abstract and up in the air, but isn't. jQuery is an excellent example and works extensively with higher-order functions. The Ruby on Rails platform is even more so.
________________________________
From: Shentino <shentino at gmail.com>
To: All about DGD and Hydra <dgd at dworkin.nl>
Sent: Saturday, June 25, 2011 5:02 AM
Subject: Re: [DGD] function pointers
I agree that function pointers, as presently implemented, are syntactic
sugar.
When taking full fledged closures into account, however, I am less certain.
There was a length discussion on the issue but I was too high on caffeine
and sleep deprived to remember any of the bigger points.
What can you functionally do with a closure that you cannot do with an ({
obj, funcname }) pair?
Even Skotos manages to use Merry as a sort of code-as-data abstraction,
which in my mind further weakens the case for closures.
FluffOS compatibility remains IMHO the strongest actual justification.
___________________________________________
https://mail.dworkin.nl/mailman/listinfo/dgd
More information about the DGD
mailing list