On 7/10/12 11:17 AM, Jonathan M Davis wrote:
On Tuesday, July 10, 2012 10:21:23 Andrei Alexandrescu wrote:
On 7/10/12 5:35 AM, Jacob Carlborg wrote:
On 2012-07-10 08:59, Dmitry Olshansky wrote:
Can you do it in other languages?

Sure, in Ruby, but that only works on arrays:

p [5, 3, 5, 6, 8].uniq.map{ |e| e.to_s }.sort

This is very inefficient.

I agree that if efficiency wasn't a concern for std.algorithm, its API
would have been different. As things are, I think std.algorithm strikes
a very good balance between efficiency and usability.

The other thing that affects a lot is infinite ranges. The functions with lazy
results work wonderfully with infinite ranges but would generally result in
infinite loops if used with functions with eager results.

auto vals = map!"a % 10"(rndGen());

works great, but you'd be forced to use take directly on rndGen pretty much
all the time you wanted to do something like that if functions like map were
lazy.

But I suspect that the sort of people who will be complaining about map not
returning an array are also the sort of people who won't be all that familar
with operating on infinite lists and at least initially probably won't care.

- Jonathan M Davis

It's also about the unnecessary work done eagerly on finite but long inputs.

Andrei

Reply via email to