X-Git-Url: http://git.kpe.io/?p=pipes.git;a=blobdiff_plain;f=pipes-example.lisp;fp=pipes-example.lisp;h=2cf07f6a9f5bda662e1a0ec58ab79c002f325a53;hp=c5722ec41034b26f28118bd02df71cc3626c7fa4;hb=eaad3792a9bf28ec7bfe579f9f0955d213e014f0;hpb=108cf113175bc41454b5b028d78fe00e67c37d83 diff --git a/pipes-example.lisp b/pipes-example.lisp index c5722ec..2cf07f6 100644 --- a/pipes-example.lisp +++ b/pipes-example.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id: pipes-example.lisp,v 1.1 2002/11/02 17:49:10 kevin Exp $ +;;;; $Id: pipes-example.lisp,v 1.2 2002/11/07 20:26:13 kevin Exp $ ;;;; ;;;; This file, part of pipes, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -17,13 +17,12 @@ (defun integers (&optional (start 0) end) - "a pipe of integers from START to END." (if (or (null end) (<= start end)) - (make-pipe start (integers (+ start 1) end)) + (make-pipe start (integers (+ start 1) end)) nil)) (defun fibgen (a b) - (make-pipe a (fibgen b (+ a b)))) + (make-pipe a (fibgen b (+ a b)))) (defun fibs () (fibgen 0 1)) @@ -32,9 +31,8 @@ (defun divisible? (x y) (zerop (rem x y))) - (defun no-sevens () - (pipe-filter #'(lambda (x) (not (divisible? x 7))) (integers))) + (pipe-filter #'(lambda (x) (not (divisible? x 7))) (integers))) (defun sieve (stream) @@ -67,23 +65,23 @@ (pipe-map #'- (pi-summands (+ n 2))))) (defun pi-stream () - (scale-pipe 4d0 (partial-sums (pi-summands 1)))) + (scale-pipe 4d0 (partial-sums (pi-summands 1)))) (defun square (x) (* x x)) (defun euler-transform (s) - (let ((s0 (pipe-elt s 0)) - (s1 (pipe-elt s 1)) - (s2 (pipe-elt s 2))) - (if (and s0 s1 s2) - (if (eql s1 s2) ;;; series has converged + (let ((s0 (pipe-elt s 0)) + (s1 (pipe-elt s 1)) + (s2 (pipe-elt s 2))) + (if (and s0 s1 s2) + (if (eql s1 s2) ;;; series has converged +empty-pipe+ - (make-pipe (- s2 (/ (square (- s2 s1)) - (+ s0 (* -2 s1) s2))) - (euler-transform (pipe-tail s)))) + (make-pipe (- s2 (/ (square (- s2 s1)) + (+ s0 (* -2 s1) s2))) + (euler-transform (pipe-tail s)))) +empty-pipe+))) - + (defun ln2-summands (n) (pipe-map (/ 1d0 n) @@ -105,9 +103,9 @@ (defun run-examples () (let ((*print-length* 20)) (format t "~&pi-stream: ~S" - (pipe-display (pi-stream) 10)) + (pipe-values (pi-stream) 10)) (format t "~&euler-transform: ~S" - (pipe-display (euler-transform (pi-stream)) 10)) + (pipe-values (euler-transform (pi-stream)) 10)) (format t "~&accelerate-sequence: ~S" - (pipe-display + (pipe-values (accelerated-sequence #'euler-transform (pi-stream)) 10))))