learning-sicp

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

front-insert-deque.scm (912B)


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