learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

rear-insert-deque.scm (1167B)


      1 (define-library (sicp solutions chapter-3 exercise-23-stuff rear-insert-deque)
      2   (import (scheme base))
      3   (import (scheme write))
      4 
      5   (import (sicp solutions chapter-3 exercise-23-stuff empty-deque))
      6   (import (sicp solutions chapter-3 exercise-23-stuff front-ptr))
      7   (import (sicp solutions chapter-3 exercise-23-stuff rear-ptr))
      8   (import (sicp solutions chapter-3 exercise-23-stuff set-front-ptr))
      9   (import (sicp solutions chapter-3 exercise-23-stuff set-rear-ptr))
     10   (import (prefix (sicp solutions chapter-3 exercise-23-stuff 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)))