Re: Lazy lists

2011-02-24 Thread Jacob Carlborg
On 2011-02-23 16:36, Andrei Alexandrescu wrote: On 2/23/11 9:30 AM, Jacob Carlborg wrote: On 2011-02-23 13:57, Andrei Alexandrescu wrote: On 2/23/11 5:10 AM, Jacob Carlborg wrote: On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def

Re: Lazy lists

2011-02-24 Thread spir
On 02/24/2011 09:55 AM, Russel Winder wrote: On Wed, 2011-02-23 at 23:51 +0100, spir wrote: [ . . . ] (sequence(["#"])(nextCarpet) drop n next) foreach println Hey guys, it's PostScript, no it's Forth ;-) Note that method chaining in typical OO syntax writes the process in chronologic

Re: Lazy lists

2011-02-24 Thread Russel Winder
On Wed, 2011-02-23 at 23:51 +0100, spir wrote: [ . . . ] > (sequence(["#"])(nextCarpet) drop n next) foreach println Hey guys, it's PostScript, no it's Forth ;-) -- Russel. = Dr Russel Winder t: +44 20 7585 220

Re: Lazy lists

2011-02-23 Thread spir
On 02/23/2011 01:57 PM, Andrei Alexandrescu wrote: On 2/23/11 5:10 AM, Jacob Carlborg wrote: On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def nextCarpet(carpet: List[String]): List[String] = ( carpet.map(x => x + x + x) ::: carpet

Re: Lazy lists

2011-02-23 Thread Andrei Alexandrescu
On 2/23/11 9:30 AM, Jacob Carlborg wrote: On 2011-02-23 13:57, Andrei Alexandrescu wrote: On 2/23/11 5:10 AM, Jacob Carlborg wrote: On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def nextCarpet(carpet: List[String]): List[String] =

Re: Lazy lists

2011-02-23 Thread Jacob Carlborg
On 2011-02-23 13:57, Andrei Alexandrescu wrote: On 2/23/11 5:10 AM, Jacob Carlborg wrote: On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def nextCarpet(carpet: List[String]): List[String] = ( carpet.map(x => x + x + x) ::: carpet.ma

Re: Lazy lists

2011-02-23 Thread Jacob Carlborg
On 2011-02-23 13:13, bearophile wrote: Jacob Carlborg: def sierpinskiCarpets(n: Int) = (Iterator.iterate(List("#"))(nextCarpet) drop n next) foreach println Again Scala shines with its beautiful lambdas compared to Ds ugly string version. In software engineering there aren't many free thin

Re: Lazy lists

2011-02-23 Thread bearophile
Andrei: > popFrontN(c, 3); > ... use c.front() ... Right. I have used the c.popFrontN(3); syntax and then I have not read the error message well. A drop(range, n) is an expression, it allows to write it as this: drop(c, 3).front > You shouldn't need array most at all. Use chain() instead of ~

Re: Lazy lists

2011-02-23 Thread Andrei Alexandrescu
On 2/22/11 8:28 PM, bearophile wrote: import std.stdio, std.string, std.algorithm, std.array, std.range; string[] nextCarpet(string[] c) { auto b = array(map!q{a ~ a ~ a}(c)); return b ~ array(map!q{a ~ a.replace("#"," ") ~ a}(c)) ~ b; } void main() { auto c = recurrence!((a, n){

Re: Lazy lists

2011-02-23 Thread Andrei Alexandrescu
On 2/23/11 5:10 AM, Jacob Carlborg wrote: On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def nextCarpet(carpet: List[String]): List[String] = ( carpet.map(x => x + x + x) ::: carpet.map(x => x + x.replace('#', ' ') + x) ::: carpet.ma

Re: Lazy lists

2011-02-23 Thread bearophile
Jacob Carlborg: > > def sierpinskiCarpets(n: Int) = (Iterator.iterate(List("#"))(nextCarpet) > > drop n next) foreach println > > Again Scala shines with its beautiful lambdas compared to Ds ugly string > version. In software engineering there aren't many free things. For some of the Scala fe

Re: Lazy lists

2011-02-23 Thread Jacob Carlborg
On 2011-02-23 03:28, bearophile wrote: This is a Scala implementation of a function that prints the carpet: def nextCarpet(carpet: List[String]): List[String] = ( carpet.map(x => x + x + x) ::: carpet.map(x => x + x.replace('#', ' ') + x) ::: carpet.map(x => x + x + x)) def sierpin

Re: Lazy lists

2011-02-22 Thread spir
On 02/23/2011 03:28 AM, bearophile wrote: A task from the RosettaCode site asks to generate a Sierpinski carpet like this, on given order: ### # ## ## ## ## ## ## ## ## # ### ### ## ## ### # # # ## # # ## # # # ### ##

Lazy lists

2011-02-22 Thread bearophile
A task from the RosettaCode site asks to generate a Sierpinski carpet like this, on given order: ### # ## ## ## ## ## ## ## ## # ### ### ## ## ### # # # ## # # ## # # # ### ## ## ### ### # #