good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Or: Hey Rocky, Watch Me Pull A Closure Out Of My HatOr: This Is Your Brain, This is Your Brain On PerlWhat follows is a (silly) example of how to make methods behave in interesting ways. Or, more accurately, it is an abuse of closures. Anyhow, for those who need brain cells fried, here you go:
Output:
You can sort of see how this would be extended to write methods such as postfix_later or do_this_after_five_times or whatever. How did I come up with this? I was bored. Kids, don't get bored. It's dangerous. (The observant will note the doubly nested closure to seal @args that have could have been eliminated with a shift in array context. Again, I tell you, I was bored) In reply to Functional Programming & method rewriting by SpanishInquisition
|
|