Keep It Simple, Stupid | |
PerlMonks |
callback or call now?by John M. Dlugosz (Monsignor) |
on Oct 16, 2002 at 18:39 UTC ( [id://205792]=perlmeditation: print w/replies, xml ) | Need Help?? |
In Module Design strawman - Exporter::VA, I’m planning a feature where if the argument is a code ref, it is called immediatly (by the code exploring this structure that is; obviously an undecorated function would be called “immediatly” when building the data structure) to get the real result. e.g. fobble => \&figure_it_out. However, there seems to be a demand for importing by hard link, also. This is easy for other types of symbols, but a contradiction for functions. That is, $x => \$_internal_x is distinguishable from $y => \&generate_y, but if the symbol is itself a function, you can't tell them apart. Originally I decided to let it mean “call back”, since you can write &foo => sub { \&_hard_link } to get the other case. But can it be simpler/easier? Well, I think I've got it! How about, for function symbols, a code ref means “now”, and a ref to a scalar means “later”? That is, The extra backslash is only one more character, rather than any other form of decorating it which has to surround it and/or involve more words. And, the meaning of backslash is consistant with “take it literally, not special meaning now”. I think the idea would make a handy idiom for any situation like this, when you're configuring things with code blocks. For example, in user-interface building, Tk has a few forms with various semantics. Any thoughts? —John
Back to
Meditations
|
|