Thanks Elian. The bare blocks have been stumping me. One of the reasons I've been so interested (and why I'm delving into internals) is that I'd like to be able to write subs that are somewhat lexically scoped for iterators and such (Without using anonymous subs, OO etc). I would like to be able to write subs that act like builtins that DWIM. I could start adding ops to the language, but I don't want to even think about writing stuff that I would need to recompile perl on a given target with my own patches.
There are ways of doing what I want with closures and objects easily enough but I am just obsessed with doing it the way I want.
For example ,take a hypothetical sub called elements(\@;$), that non-destructively grabs N elements of off an array lazily.
I'd like to be able to say...
while(my @els = elements(@array, 5) ){
# Do stuff while we have elements...
}
I can think of a couple of ways we might be able to have this DWIM.
- Install a localized version outside of the caller's scope or otherwise dynamically redefine it for the scope in such a way that it will be restored. (Meaning the first time it is called in a scope, the sub (which is a sub generator) redefines the subname locally and calls the newly installed version. Subsequent calls go straight to the new version until the scope ends and the original sub generator is called next time a scope is entered.
- Install a lexical marker in the caller's (xcv_outside?)pad so and use Padwalker to reference our current state. Now we can act lexically, though I dont' think pads are "cleared" so I don't know if this would work in all cases (like if the loop is exited prematurely and there are still elements left to iterate)
- Source filters. Ugh. Don't really like them. Feels wrong.
-Lee
"To be civilized is to deny one's nature."
edited: Mon Nov 18 15:34:59 2002
by jeffa - s/<\/ul>/<\/ol>/
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.