Michel Fortin: > > But you don't need a new string for each line to evaluate max over line > > lengths; the current byLine works. > > That's true. > > > > Generally I think buffer reuse in byLine() is too valuable to let go. > > I also agree it's wasteful.
See my answers to Andrei. > But I think bearophile's experiment has illustrated two noteworthy > problems. The first issue is that calling filter! on the > already-consumed result of byLine() gives you a seg fault. I reproduced > this locally, but haven't pinpointed the problem. Maybe beside that one there is yet another problem, I have had problems in creating a version that opens and scans the file twice. > The second one is this: > > array(file.byline()) > > which gives a wrong result because of the buffer reuse. Either it > should not compile or it should idup every line (both of which are not > entirely satisfactory, but they're better than getting wrong results). I don't agree. dupping every line is like performing a limited deep-dup, and this is not the job of array(). Not compiling again is not the job of array(). So the problem needs to be solved elsewhere, array() is OK, I think. > I think a range should be able to express if the value can be reused or > not. If the value can't be reused, then the algorithm should either not > instantiate, or in some cases it might create a copy. Generally in a nonfunctional language iterables need to exhaust :-) Bye, bearophile
