Lazy lists
Jacob Carlborg
doob at me.com
Wed Feb 23 07:30:00 PST 2011
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
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list