learning-sicp

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

front-insert-deque.scm (1073B)


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