learning-sicp

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

front-delete-deque.scm (1135B)


      1 (define-library (sicp solutions 3_23 front-delete-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 front-delete-deque!)
     13 
     14   (begin
     15     (define (front-delete-deque! deque)
     16       "Delete frontmost item of DEQUE if DEQUE is not empty, otherwise raise an error."
     17 
     18       (display (dll:doubly-linked-list->list (front-ptr deque))) (newline)
     19       (cond
     20        ((empty-deque? deque)
     21         (error "FRONT-DELETE-DEQUE! called with an empty deque" deque))
     22        ((null? (dll:link-rear (front-ptr deque))) ; The front link's rear pointer would point at '() only if it is the only link in the DEQUE.
     23         (set-front-ptr! deque '())
     24         (set-rear-ptr! deque '()))
     25        (else
     26         (set-front-ptr! deque
     27                         (dll:link-rear (front-ptr deque)))
     28         (dll:delete-front! (front-ptr deque))))
     29       deque)))