2009/5/13 <codesite-nore...@google.com>: > > > Comment #17 on issue 265 by JeanPhilippe.bernardy: Slow pasting > http://code.google.com/p/yi-editor/issues/detail?id=265 > > I applied the patch, but I'm not sure what the purpose of the "lazy" > function is; can > you explain? >
Ok. So it's used in an expression like "zip a (lazy b)" where b takes a long time. Denotationally, a better name would have been "assumeInfinite". I happen to know the second argument to zip is as long as the first, so "zip" does not need to pattern match on the second list to see where it ends. Operationally it avoids evaluating the second list unless it's needed. As an example, imagine syntax highlighting gets stuck in an infinite loop: Prelude> let lazy l = head l : lazy (tail l) Prelude> let syntax = syntax Prelude> map fst (zip [1,2,3,4,5] syntax) ^CInterrupted. Prelude> map fst (zip [1,2,3,4,5] (lazy syntax)) [1,2,3,4,5] My first approach was to write a specialised version of zip, but using the "lazy" function is nice because it lets you swap the arguments to zip, for example: Prelude> map snd (zip (lazy syntax) [1,2,3,4,5]) [1,2,3,4,5] This stops prepareAction evaluating syntax highlighting. The next optimisation would be to avoid scanning a screenful of text on every keystroke just to work out line numbers for setMarkPointB. --~--~---------~--~----~------------~-------~--~----~ Yi development mailing list yi-devel@googlegroups.com http://groups.google.com/group/yi-devel -~----------~----~----~----~------~----~------~--~---