previous | index | next

pop!

Must:
  1. Check for empty stack

  2. Decrement height

  3. Return the modified stack
     (define pop!
       (lambda (ra-stack)
	 (if (empty-ra-stack? ra-stack) ;; 1
	     (error "POP!: attempted pop from an empty stack")
	     (begin
	       (set-height! ra-stack (- (height ra-stack) 1)) ;; 2
	       ra-stack))))  ;; 3

     (define set-height!  ; not for public use
       (lambda (ra-stack new-height)
	 (vector-set! ra-stack 0 new-height)))
Scheme's begin form evaluates all expressions in its scope sequentially.

previous | index | next