First many thanks for giving the internal perspective (I was hoping you would take the time to do this!). I am not terribly familiar with the Perl source code, but it seems that the op code names in
opcode.h are consistent with your point about map being a shorthand for a looping op-tree. In
EXTCONST char* const PL_op_name[], not only does "map" have an op code name, but I also see two others: "mapstart" and "mapwhile". Are these the opcodes for the loop you are talking about? (sometimes header files can be deceiving if you don't know the code base well)
grep acts like map with regard to returns. It also seems to treat its block like a loop and, not surprisingly, it too has three op code names: "grep", "grepstart", and "grepwhile".
On the other hand, I'm thinking that sort may be implemented like something closer to function. Unlike "map" or "grep" it has only the one op-code "sort". Also, as mentioned earlier on this thread, it treats returns as if the block was an eval {} or anonymous subroutine. What is your take given your greater experience with internals?
Also, is there any guideline or rule of thumb that can be used to determine how routines listed in index-functions are going to treat a block? It seems like there ought to be something other than testing code samples, knowing internals, or word-of-mouth from other Perl programmers.
Best, beth
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.