Changes between Version 12 and Version 13 of Languages/Scheme


Ignore:
Timestamp:
May 19, 2018, 9:10:32 AM (4 years ago)
Author:
schiptsov
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Languages/Scheme

    v12 v13  
    161161                     (if #f #t))))))
    162162}}}
     163
     164== Streams ==
     165{{{#!scheme
     166(define-syntax stream-cons
     167  (syntax-rules ()
     168    ((_ x xs)
     169     (cons x (delay xs)))))
     170}}}
     171{{{#!scheme
     172(define (stream-cdr xs)
     173  (force (cdr xs)))
     174}}}
     175{{{#!scheme
     176(define (stream-map f xs)
     177  (stream-cons (f (car xs)) (stream-map f (stream-cdr xs))))
     178}}}
     179{{{#!scheme
     180(define (stream-filter f xs)
     181  (if (f (car xs))
     182      (stream-cons (car xs) (stream-filter f (stream-cdr xs)))
     183      (stream-filter f (stream-cdr xs))))
     184}}}
     185{{{#!scheme
     186(define (stream-take n xs)
     187  (if (<= n 0)
     188      '()
     189      (cons (car xs) (stream-take (- n 1) (stream-cdr xs)))))
     190}}}
     191{{{#!scheme
     192(define (repeat x)
     193  (stream-cons x (repeat x)))
     194}}}
     195{{{#!scheme
     196(define (iterate f x)
     197  (stream-cons x (iterate f (f x))))
     198}}}
     199{{{#!scheme
     200(define (replicate n x)
     201  (stream-take n (repeat x)))
     202}}}
     203
    163204== Newton's method ==
    164205