Lazy lists
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Feb 23 04:57:50 PST 2011
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.map(x => x + x + x))
>>
>> 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.
But then
Iterator.iterate(List("#"))(nextCarpet) drop n next) foreach println
a sort of a stuttering Yoda evokes.
Andrei
More information about the Digitalmars-d
mailing list