Re: run-once code
On Tue, 13 Jan 2004 20:37:21 -0800 David Storrs <[EMAIL PROTECTED]> wrote: > Given this code: > > if ( some_expensive_lookup_function() >= $MAX_RECORDS ) { >mark_that_we_have_reached_max_records(); >return; > } > > After I enter that block once, I never want to evaluate the condition > again--I want the code to completely disappear from the bytecode (or, > at least, be jumped around). How would I do that in Perl 6? Another approach would be to just memoize the subroutine. Thanks to the spiffy new subroutine signature syntax it's absurdly easy e.g sub some_expensive_lookup_function() is cached { ... } That's side-stepping the implications of memoizing a subroutine of course, but it does save maintaining state in user-level code. Dan
Re: Aliasing an array slice
On 5 Jul 2003, Luke Palmer wrote: > > return [EMAIL PROTECTED] $begin .. $end ]; > > I fear that this might take a reference to each element in the slice, > rather than a reference to the slice Yes, that would indeed return a list of refs in perl5. Can it also be assumed that the magic hyper-operation of \() in perl5 will translated to perl6, or (hopefully) will this behaviour become more explicit with something like ^\() (is the carat still the hyper-operator character btw?) ? > Actually, you can't reference a slice! Where the heck does the > reference point? Maybe this is a poor simile since references aren't pointers, but I would imagine if references to slices were to exist they'd be something *like* a pointer to a specific index in an array in C e.g #include int main(void) { char *str = "a list of characters"; char *p = &str[2]; puts(p); return 0; } __output__ list of characters Of course this isn't directly orthogonal to a reference of an array slice but hopefully it illustrates my point. Or perhaps this could all just be simply implemented with a tie() or some other such magic. Just thinking out loud here :) Dan Brook
Aliasing an array slice
Will it be possible (or sane even) to bind a variable to an array slice e.g ## correct syntax? my @array = << a list of values >>; my @array_slice := @array[ 1 .. @array.end ]; Or would this merely bind @array_slice to the list returned by the slice, or would it DTRT (in my eyes at least) and bind it to that particular slice of @array? Dan Brook
Re: "Disappearing" code
On Thu, 09 Jan 2003 19:55:20 -0500 John Siracusa <[EMAIL PROTECTED]> wrote: > Has there been any discussion of how to create code in Perl 6 that's > there under some conditions, but not there under others? I'm thinking > of the spiritual equivalent of #ifdef, only Perlish. If the perl6 command-line options are anything like perl5 then you can just use the -P switch if preprocessor commands are your thing. > In Perl 5, there were many attempts to use such a feature for > debugging and assertions. There has also been a proposal for patching perl5 to add assertions which was recently discussed[1] on p5p, which if accepted has implications for assertions in perl6 surely. Dan [1] http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2002-11/msg00325.html