lisp - Issue on displaying successive items of an infinite stream -



lisp - Issue on displaying successive items of an infinite stream -

; defining stream-for-each (define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-car s)) (stream-for-each (stream-cdr s))))) ; defining method display stream (define (display-stream s) (stream-for-each display-line s)) (define (display-line x) (newline) (display x)) ; creating stream uses newton-raphson ; method find square root of 2 (define (sqrt-improve guess x) (avg guess (/ x guess))) (define (sqrt-stream x) (define guesses (cons-stream 1.0 (stream-map (lambda (guess) (sqrt-improve guess x)) guesses))) guesses)

now testing it..

=> (stream-ref (sqrt-stream 2) 11) value: 1.414213562373095

so seems stream working correctly; when seek , display it:

=> (display-stream (sqrt-stream 2)) 1. ;the procedure #[compound-procedure 13 stream-for-each] has been called 1 argument; requires 2 arguments.

from see, stream-for-each beingness called 2 args, must missing something. appreciate clarification. code taken from: http://mitpress.mit.edu/sicp/full-text/book/book-z-h-24.html#%_sec_3.5.3

you're missing argument in recursive phone call (stream-for-each (stream-cdr s)). function stream-for-each has contract procedure? stream? -> 'done you've provided stream (which error says).

stream lisp scheme

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -