Lazy lists

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Feb 23 07:36:38 PST 2011


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] = (
>>>> 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
>
> Ok, I see now that my answer can be misinterpreted. When I wrote the
> answer I was actually referring to the lambda syntax used in the "map"
> function.
>
> x => x + x + x
>

I understand that. What I meant to say is that it's difficult to have a 
language that excels on all fronts.

Andrei


More information about the Digitalmars-d mailing list