|
|
On 14/05/2011 08:53 AM, Warp wrote:
> Invisible<voi### [at] devnull> wrote:
>> 1. Writing
>
>> Iterator<Foo> it = list1.iterator();
>> ArrayList<Foo> list2 = new ArrayList<Foo>();
>> while (it.hasNext()) list2.add(bar(it.next()));
>
>> is way more work than writing
>
>> list2 = map bar list1
>
> Argument from verbosity is seldom a good argument in programming.
> Just because something is shorter doesn't necessarily mean it's better.
You don't think the intension of the second example is clearer at a glance?
> Anyways, many languages have constructs to make that shorter.
Some have a "foreach" construct that can make this kind of thing shorter.
Curiously, Smalltalk had a few library functions to do this kind of
thing. Then again, in Smalltalk, every block of code is an object. That
allowed Smalltalk to offer a #do: method for most container classes.
That means you can then simplement #collect:, #select: and #reject: in
terms of #do:. For example,
list2 := map collect: [ x | x bar ]
That's nearly the same level of directness as Haskell.
> Curiously,
> the next C++ standard will introduce constructs that allow you to write:
>
> for(auto& v: list1) list2.push_back(v);
And that does what? Copy the list?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|