;;;; 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
;;;;
(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))
(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)
(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)
(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))))