learning-sicp

My embarrassing half assed SICP run.
Log | Files | Refs

rear-insert-deque.scm (1006B)


      1 (define-library (sicp solutions 3_23 rear-insert-deque)
      2   (import (scheme base))
      3   (import (scheme write))
      4 
      5   (import (sicp solutions 3_23 empty-deque))
      6   (import (sicp solutions 3_23 front-ptr))
      7   (import (sicp solutions 3_23 rear-ptr))
      8   (import (sicp solutions 3_23 set-front-ptr))
      9   (import (sicp solutions 3_23 set-rear-ptr))
     10   (import (prefix (sicp solutions 3_23 doubly-linked-list) dll:))
     11 
     12   (export rear-insert-deque!)
     13 
     14   (begin
     15     (define (rear-insert-deque! deque item)
     16       "Insert ITEM to the rear of DEQUE and returns the changed DEQUE."
     17       (display (dll:doubly-linked-list->list (front-ptr deque))) (newline)
     18       (let ([new-link (dll:make-link item)])
     19         (cond
     20          ((empty-deque? deque)
     21           (set-front-ptr! deque new-link)
     22           (set-rear-ptr! deque new-link))
     23          (else
     24           (dll:link-up-front-to-rear! (rear-ptr deque)
     25                                       new-link)
     26           (set-rear-ptr! deque
     27                          new-link))))
     28 
     29       deque)))