On 5/8/2014 10:46 AM, Andrei Alexandrescu wrote:
However output range means the string operation will be done eagerly, whereas
lazy has advantages (nice piping, saving on work etc).
The lazy vs eager issue seems at first blush to be an esoteric, potayto-potahto
bikeshed.
But I think it's more interesting than that.
Lazy means that the computation is divided into two pieces:
1. creating an engine to do the calculations
2. feeding the data to the engine to generate a result
This, of course, reminds me of regex. By creating the regex engine separately,
and then using that engine for multiple sets of data, one can afford to spend
extra computational effort at optimizing the engine. Creating the engine can
even be done at compile time (as Dmitry's most excellent regex engine does).
Engines can make it easier to parallelize computation.
And lastly, it's easy to make an eager version by wrapping a lazy one. But to
make a lazy version from an eager one means reimplementing it.