NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
Dynamic Features (Score:2)
printfis just soooo lame)Now, with interpolation and eval, you can fake closures, but it's a royal PITA. Here's the classic make_adder example in Perl:
Re:Dynamic Features (Score:2)
Re:Dynamic Features (Score:2)
Reducing this down to "allow dynamic code generation" and "attach data to code" is a false economy in specification. Once you have true closures (which imply lexical scoping), a whole new way to code is opened up for you. Instead of writing ridiculously long classes to, say, find files, you can have small simple classes that are responsible for the algorithmic structure of finding files and nothing else -- selecting symlinks, directories, writable files, whatnot is all your responsibility to handle in a callback.
You can punt with eval if you don't have closures, but that's like using two liters of grain alcohol instead of a shot of novocaine before doing minor dental surgery. Eval and interpolation turn that grain alcohol into something more palatable, like Irish Whiskey, but it's still fundementally the wrong solution.
Limping along with pre-processors and static code generators is still a bad problem. You might as well be programming in C at that point. That strategy recognizes the need for code that writes code, but ignores the fact that you really need to be alble to do that at runtime (like, when you need to construct a callback to File::Find, and maybe something with persistent state to select the first ten results).
Reply to This
Parent
Re:Dynamic Features (Score:2)
By changing the wording from "have closures" to "easily attach data to code" (with the implied "at runtime") I was attempting to restate the problem as a problem rather than as a solution. Closures are a solution to the problem and you've layed out the problem quite well. I would rather not assume that closures are the only way to do it. Or eval. Or pluggable functions (*foo = \&bar). Maybe there is a way to do it efficiently and concisely with anonymous cl
Re:Dynamic Features (Score:2)
As you stated the problem above, there are some design decisions that are fundementally wrong in language design today. Like no namespaces, no way to include files, etc.
"No Closures" is as big a design flaw as "no anonymous functions", "no eval" and "no interpolation". You can find all sorts of ways around that problem, but fundementally, there's no good reason to not have closures. Rephrasing that, there's no defensible reason for asking your users to jump through hoops to achieve the same result
Re:Dynamic Features (Score:2)
Anonymous classes are a form of closure. It's how Java fakes closures in particular, and it's a cleaner solution for some problems. (You could define anon classes with dynamic scoping rules a la Tcl, but why?)
The issues are very closely related, but not identical.
If you say no to closures and yes to anon classes, you're really saying no jam! and more orange marmalade!