projects
/
pipes.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
r3536: *** empty log message ***
[pipes.git]
/
pipes-example.lisp
diff --git
a/pipes-example.lisp
b/pipes-example.lisp
index c5722ec41034b26f28118bd02df71cc3626c7fa4..2cf07f6a9f5bda662e1a0ec58ab79c002f325a53 100644
(file)
--- a/
pipes-example.lisp
+++ b/
pipes-example.lisp
@@
-7,7
+7,7
@@
;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Apr 2000
;;;;
;;;; 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
;;;;
;;;;
;;;; This file, part of pipes, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
@@
-17,13
+17,12
@@
(defun integers (&optional (start 0) end)
(defun integers (&optional (start 0) end)
- "a pipe of integers from START to END."
(if (or (null end) (<= start 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)
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 fibs ()
(fibgen 0 1))
@@
-32,9
+31,8
@@
(defun divisible? (x y)
(zerop (rem x y)))
(defun divisible? (x y)
(zerop (rem x y)))
-
(defun no-sevens ()
(defun no-sevens ()
-
(pipe-filter #'(lambda (x) (not (divisible? x 7))) (integers)))
+ (pipe-filter #'(lambda (x) (not (divisible? x 7))) (integers)))
(defun sieve (stream)
(defun sieve (stream)
@@
-67,23
+65,23
@@
(pipe-map #'- (pi-summands (+ n 2)))))
(defun pi-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)
(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+
+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+)))
+empty-pipe+)))
-
+
(defun ln2-summands (n)
(pipe-map (/ 1d0 n)
(defun ln2-summands (n)
(pipe-map (/ 1d0 n)
@@
-105,9
+103,9
@@
(defun run-examples ()
(let ((*print-length* 20))
(format t "~&pi-stream: ~S"
(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"
(format t "~&euler-transform: ~S"
- (pipe-
display
(euler-transform (pi-stream)) 10))
+ (pipe-
values
(euler-transform (pi-stream)) 10))
(format t "~&accelerate-sequence: ~S"
(format t "~&accelerate-sequence: ~S"
- (pipe-
display
+ (pipe-
values
(accelerated-sequence #'euler-transform (pi-stream)) 10))))
(accelerated-sequence #'euler-transform (pi-stream)) 10))))