Juerd:
2005/11/23, Juerd <juerd (AT) convolution (DOT) nl>:
Flavio S. Glock skribis 2005-11-23 10:13 (-0200):
Can we have:
say 1Inf;
It's important, I think, to note that this isn't item context, but list
context. Str list context, but still list context. Which means 1Inf
isn't stringified as a whole. &say will have an array that represents
the lazy list. It should iterate over that rather than output it all at
once, anyway, for reasons of conserving memory.
Ah, ok - but I believe that say() is slurpy, which means the list must
be instantiated first.
to output an infinite stream, instead of just looping forever?
How do you imagine anything outputs infinite stuff, without looping
forever? I don't think stdout knows about our kind of laziness :)
There are some reasons for this - you can see what's happening, and
press ctrl-C; or you may wish for it to output until there is a
timeout; or maybe you are writing a daemon which is supposed to run
forever anyway.
TH, it would be nice if
say substr( ~(1Inf), 0, 10 )
printed "1 2 3 4 5".
Here, 1Inf is stringified as a whole, while with say, each of the
individual elements of the list are separately stringified. The question
of lazy strings is an interesting one. It would be very useful, and
would also allow GREAT things like
my $revfoo := reverse $foo;
$revfoo ~~ s/foo/bar/g;
I wonder if it's doable, though
I believe it is - I've come to this idea while trying to write down
the Array spec, and it seems pretty feasible.
Juerd
Thanks!
- Flavio