From 6eab42aca0276eb2a534c32a272532d023163824 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Sun, 17 Jul 2016 00:41:13 +0200 Subject: [PATCH] Avoid recursive stream-append in stream-concatenate This fix prevents exceeding `max-lisp-eval-depth' for streams returned by stream-concatenate. --- packages/stream/stream.el | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/stream/stream.el b/packages/stream/stream.el index 8b71a1b..853251e 100644 --- a/packages/stream/stream.el +++ b/packages/stream/stream.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; Keywords: stream, laziness, sequences -;; Version: 2.2.0 +;; Version: 2.2.1 ;; Package-Requires: ((emacs "25")) ;; Package: stream @@ -377,7 +377,17 @@ will be found by calling FUNCTION on the preceding element." "Concatenate all streams in STREAM-OF-STREAMS and return the result. All elements in STREAM-OF-STREAMS must be streams. The result is a stream." - (seq-reduce #'stream-append stream-of-streams (stream-empty))) + (stream-make + (while (and (not (stream-empty-p stream-of-streams)) + (stream-empty-p (stream-first stream-of-streams))) + (cl-callf stream-rest stream-of-streams)) + (if (stream-empty-p stream-of-streams) + nil + (cons + (stream-first (stream-first stream-of-streams)) + (stream-concatenate + (stream-cons (stream-rest (stream-first stream-of-streams)) + (stream-rest stream-of-streams))))))) (defun stream-of-directory-files-1 (directory &optional nosort recurse follow-links) "Helper for `stream-of-directory-files'." -- 2.8.1