foreach_reverse is better than ever
Michel Fortin
michel.fortin at michelf.com
Mon Feb 15 07:19:15 PST 2010
On 2010-02-15 09:04:11 -0500, Leandro Lucarella <llucax at gmail.com> said:
> Andrei Alexandrescu, el 14 de febrero a las 20:24 me escribiste:
>> There are two operations: reverse the thing in place, and span it in
>> retrograde order.
>
> I think reverse (in-place) and reversed (returns a range that iterates in
> reverse order) are *very* clear in terms of that distinction.
But now how do you distinguish between a function returning the
reversed form of something and a function returning true when that
thing is reversed?
:-)
In Ruby syntax things are generally pretty easy:
something.reverse! # reverse in place ('dangerous!' method)
something.reverse # reverse a copy
something.reversed? # return whether something is reversed or not
Cocoa would use a slightly different notation:
[something reverse]; // reverse in place
[something reversedSomething]; // reverse a copy
[something isReversed]; // return whether something is reversed or not
Both conventions are very clear and scale well even for words like
'split' which are identical in their past and present tense.
It's unclear to me how we want this to be done in D...
something.reverse(); // reverse in place
something.reversed; // reverse a copy
something.reversed(); // ditto
something.reverse(); // ditto
something.reversed; // return whether something is reversed or not
something.isReversed; // ditto
If we want some consistency, someone with authority over Phobos will
have to draw some guidelines about this, and sooner the better.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list