about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/stream-pack.scm
blob: 826b06c9bee07efd91578869ddbf966b8bc2b1fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;; review notes for 4/10/98
;;can you deadlock on this?

(parallel-execute  (exchange-account a b)(exchange-account a c)) ?


what do these do:

(define a (cons-stream a a))

(define a (cons-stream 'a a))
(show-stream a)
(define a (cons-stream a a))
(show-stream a)


what is the difference between eq?  and equal?

(eq? () '())


(pair? ())

;; pack a finite stream with infinite newelements on end

(define (pack-stream s newelement)
  (if (stream-null? s)
     (cons-stream newelement(pack-stream s newelement))
    (cons-stream (stream-car s) (pack-stream (stream-cdr s) newelement))))

;or (buggy)

(define (pack-stream s newelement)
  (if (stream-null? s) (let ((a (cons-stream newelement a))) a)
    (cons-stream (stream-car s) (pack-stream (stream-cdr s) newelement))))


; or (still buggy)

(define (pack-stream s newelement)
  (if (stream-null? s) (let ((a nil))
                             (set! a (cons-stream newelement a)))
    (cons-stream (stream-car s) (pack-stream (stream-cdr s) newelement))))
; ok

(define (pack-stream s newelement)
  (if (stream-null? s) (let ((a nil))
                         (set! a (cons-stream newelement a))
                         a)
      (cons-stream (stream-car s) (pack-stream (stream-cdr s) newelement))))