    ;;;
    ;;; stacks.scm
    ;;;
    ;;; Stacks as lists.
    ;;;
    ;;; pz, aDu, October 2000.
    
    ;;; To create a new data abstraction, we need a constructor, selectors, 
    ;;; predicates, manipulators, a printer, and a representation.
    ;;;
    ;;; These are, as follows:
    ;;;
    ;;; make-stack ..... the constructor, makes an empty stack
    ;;; empty-stack? ... a predicate to test if a stack is empty
    ;;; push-obj ....... adds an object on the top of the stack
    ;;; pop-obj ........ removes the top object from the stack
    ;;; top-obj ........ returns the top object w/o removing it
    ;;; print-stack .... prints out the stack
    ;;;
    ;;; The representation will be a list, where the head of the
    ;;; stack is at the head of the list.
    
    
    ;;; make-stack
    ;;;
    ;;;
    
    (define (make-stack)
      nil)
    
    
    ;;; empty-stack?
    ;;;
    ;;;
    
    (define (empty-stack? s)
      (null? s))

    
    ;;; push-obj
    ;;;
    ;;;
    
    (define (push-obj obj s)
      (cons obj s))
    
    
    ;;; pop-obj
    ;;;
    ;;;
    
    (define (pop-obj s)
      (if (empty-stack? s)
          (error "Cannot pop anything off an empty stack!")
          (cdr stack)))
    
    

    ;;; top-obj
    ;;;
    ;;;
    
    (define (top-obj s)
      (if (empty-stack? s)
          (error "Nothing in an empty stack to look at!")
          (car stack)))
    
    
    ;;; print-stack
    ;;;
    ;;;
    
    (define (print-stack s)
      (newline)
      (display "[")
      (map (lambda (obj)
    	 (display obj)
    	 (display " "))
           s)
      (display "]"))
    

    ;;;
    ;;; end.

