Lazy lists in Str context

2005-11-23 Thread Flavio S. Glock
Can we have: say 1..Inf; to output an infinite stream, instead of just looping forever? OTOH, it would be nice if say substr( ~(1..Inf), 0, 10 ) printed 1 2 3 4 5. Flattened lists would still loop forever (or fail): say **(1..Inf); $s = substr( ~( **(1..Inf) ), 0, 10 ); - Flavio

Re: Lazy lists in Str context

2005-11-23 Thread Rob Kinyon
On 11/23/05, Flavio S. Glock [EMAIL PROTECTED] wrote: Can we have: say 1..Inf; to output an infinite stream, instead of just looping forever? OTOH, it would be nice if say substr( ~(1..Inf), 0, 10 ) printed 1 2 3 4 5. Flattened lists would still loop forever (or fail): say

Re: Lazy lists in Str context

2005-11-23 Thread Juerd
Flavio S. Glock skribis 2005-11-23 10:13 (-0200): Can we have: say 1..Inf; 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 1..Inf isn't stringified as a whole. say will have an array that represents the

Re: Lazy lists in Str context

2005-11-23 Thread Larry Wall
On Wed, Nov 23, 2005 at 12:07:08PM -0500, Rob Kinyon wrote: : On 11/23/05, Flavio S. Glock [EMAIL PROTECTED] wrote: : OTOH, it would be nice if : :say substr( ~(1..Inf), 0, 10 ) : : printed 1 2 3 4 5. : This would work, I think, if ranges were convertable to iterators, Range objects are

Re: Lazy lists in Str context

2005-11-23 Thread Flavio S. Glock
Juerd: 2005/11/23, Juerd [EMAIL PROTECTED]: Flavio S. Glock skribis 2005-11-23 10:13 (-0200): Can we have: say 1..Inf; 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 1..Inf isn't stringified as a

Re: Lazy lists in Str context

2005-11-23 Thread Juerd
Larry Wall skribis 2005-11-23 11:16 (-0800): Range objects are supposed to *be* iterators, but pugs isn't there yet, last I checked. Is the associated sigil @ or $? Either way, there's a problem. $foo can't flatten in list context, which .. does want, which would be inconsistent, but with @, it

Re: Lazy lists in Str context

2005-11-23 Thread Larry Wall
On Wed, Nov 23, 2005 at 05:24:11PM -0200, Flavio S. Glock wrote: : Ah, ok - but I believe that say() is slurpy, which means the list must : be instantiated first. It's * instantiated, but not ** instantiated, so the iterators buried in the .specs of the list aren't forced to evaluate yet. And

Re: Lazy lists in Str context

2005-11-23 Thread Larry Wall
On Wed, Nov 23, 2005 at 08:35:09PM +0100, Juerd wrote: : Larry Wall skribis 2005-11-23 11:16 (-0800): : Range objects are supposed to *be* iterators, but pugs isn't there yet, : last I checked. : : Is the associated sigil @ or $? Either way, there's a problem. No, either way it does what you

Re: Lazy lists in Str context

2005-11-23 Thread Flavio S. Glock
2005/11/23, Larry Wall [EMAIL PROTECTED]: I think the last one is more feasible than the middle one, at least by default. The problem is that stringification is considered a result of a kind of scalar context, and ordinary scalar context is not lazy in Perl 6. So we'd probably need to set

Re: Lazy lists in Str context

2005-11-23 Thread Rob Kinyon
On 11/23/05, Flavio S. Glock [EMAIL PROTECTED] wrote: How about allowing reduce() to return a scalar with the same laziness as the list: [EMAIL PROTECTED] - a lazy string if @list is lazy [EMAIL PROTECTED] - a lazy number if @list is lazy It would look like: $foo = substr(

Re: Lazy lists in Str context

2005-11-23 Thread Luke Palmer
On 11/23/05, Larry Wall [EMAIL PROTECTED] wrote: Basically, we're attaching the whole lazy/nonlazy mess to the list/scalar distincion, which I think is a really good default. We use ** and lazy() to violate those defaults. I think you might be mixing up the scope of laziness here. Having a