std.algorithm - notes

bearophile bearophileHUGS at lycos.com
Tue Mar 4 06:42:13 PST 2008


Few comments to the std.algorithm of D 2.0 by Andrei Alexandrescu:

- Generally this module seems rich of many useful things. Tons of things I have written become little useful with this library of utilities. Tango has some of those things too. If not already done, I think Andrei Alexandrescu must stop and work with the Tango team to reduce duplicated efforts :-) The actual merging of Tango and Phobos can start from a "simple" module like this too (instead of keeping the silly working in parallel).
- I think most of it can be backported to D 1.0.
- map: flattening successive ranges is a conflation of two different functions, that is chain and map. It's much better to keep functions logically clean. Perl shows what problems gives the automatic flattening. When receiveds multiple iterables map has to map a multi-way function on them. See my d libs.
- it's useful to create lazy versions of map, filter, etc, I have called them xmap, xfilter, etc.
- Instead of defining map, filter, etc, I think a Python list comphrension is better, cleaner, simpler to read, etc.
- In my d libs everywere I give an AA, the functions iterate on their *keys*. This is much more useful, because given a key you can find its value, while generally the latter is too much slow.
- When the "length" attribute of the input iterable exists, it's used to pre-allocate the size of the final result in some functions like map().
- inPlace(): in other languages it's called map!(), so it may be called inMap, or mapBang, etc.
- overwriteAdjacent: I think "compact" may be fitting name (the similar string function can be removed).
- iterSwap: I don't understand it.
- "The schwartzSort function might require less temporary data and be faster than the Perl idiom or the decorate-sort-undecorate idiom present in Python and Lisp. This is because sorting is done in-place and only minimal extra data (one array of transformed elements) is created.": This is wrong, Python has the "key" argument of sort/sorted.
- max/min: nicely done. A max/min of iterables (without the need to use reduce) is useful too (even with 'key' function, see my d libs).

Bye,
bearophile



More information about the Digitalmars-d mailing list