cl-rw

Layered streams for Common Lisp
git clone https://logand.com/git/cl-rw.git/
Log | Files | Refs

commit fbbb4b359a4bdf9cfcb0df60e3c12eb277bbb6fc
parent ae596097844679ea388dc014c2ffa656b1a4477e
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 21 Oct 2017 20:24:21 +0200

nicer flat reader

Diffstat:
Mrw.lisp | 33+++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/rw.lisp b/rw.lisp @@ -31,6 +31,7 @@ :copy :fibonacci-reader :filter-reader + :flat-reader :line-reader :next :next-octets @@ -559,15 +560,27 @@ (defun flat-reader (reader) (let ((r (list reader))) - (lambda () - (loop - (unless r - (return)) - (let ((z (funcall (car r)))) - (if z - (if (functionp z) - (push z r) - (return z)) - (pop r))))))) + (labels ((rec () + (when r + (let ((z (next (car r)))) + (cond + ((functionp z) + (push z r) + (rec)) + (z) + (t + (pop r) + (rec))))))) + #'rec))) + +;;(disassemble (flat-reader (reader '(1 2 3)))) ;;(slurp (flat-reader (reader (list (reader (list 1 2)) (reader (list (reader (list 3 4)) 5)))))) +;;(slurp (flat-reader (reader '(1 2 3)))) + +;; ? no writers, only readers -> pull bytes in write loop + +;; flat input octets -> cons tree -> [writer] flat output octets +;; flat input octets -> cons tree -> octet-reader tree -> [writer] flat output octets + +;; https://rosettacode.org/wiki/Flatten_a_list