Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix lazy evaluation of second argument to append-pipes for consistenc…

…y with make-pipe; fixes mappend-pipe laziness

Ignore-this: f3fed201712877e374d820d195f79ce1

  • Loading branch information...
commit d5b9a84109075ae4eaefae275eca7e0ed7575d7b 1 parent aaec8c5
@lichtblau lichtblau authored
Showing with 20 additions and 4 deletions.
  1. +11 −4 pipes.lisp
  2. +9 −0 xpath-test.lisp
15 pipes.lisp
@@ -128,12 +128,19 @@
(make-pipe result (map-pipe-filtering fn tail filter-test))
(map-pipe-filtering fn tail filter-test)))))
-(defun append-pipes (pipex pipey)
- "return a pipe that appends two pipes"
+(defmacro append-pipes (pipex pipey)
+ "return a pipe that appends two pipes.
+ The evaluation style of this macro has been chosen to be consistent
+ with MAKE-PIPE: The first argument is evaluated eagerly; the second
+ argument lazily."
+ `(%append-pipes ,pipex #'(lambda () ,pipey)))
+(defun %append-pipes (pipex pipey-fun)
(if (pipe-empty-p pipex)
- pipey
+ (funcall pipey-fun)
(make-pipe (pipe-head pipex)
- (append-pipes (pipe-tail pipex) pipey))))
+ (append-pipes (pipe-tail pipex) (funcall pipey-fun)))))
(defun mappend-pipe (fn pipe)
"lazily map fn over pipe, appending results"
9 xpath-test.lisp
@@ -627,3 +627,12 @@
'(("a" (("id" "1"))) ("c" (("id" "6"))))
(all-nodes (evaluate "//c[position()=2]|//a[@id='1']" d)))))
+(deftest mappend-lazy
+ (let* ((x nil)
+ (pipe (mappend-pipe (lambda (x) (list (- x)))
+ (make-pipe 1 (progn (setf x t) '(2))))))
+ (assert (not x))
+ (assert (eql -1 (pipe-head pipe)))
+ (assert (eql -2 (pipe-head (pipe-tail pipe))))
+ (assert x)))
Please sign in to comment.
Something went wrong with that request. Please try again.