stack.scm 420 B

12345678910111213141516171819202122
  1. (define (empty-stack) (box '()))
  2. (define (make-stack lst) (box lst))
  3. (define (stack-top s)
  4. (let ((stk (unbox s)))
  5. (if (null? stk)
  6. (error 'stack-top "null")
  7. (car stk))))
  8. (define (stack-pop! s)
  9. (let ((stk (unbox s)))
  10. (if (null? stk)
  11. (error 'stack-pop "null")
  12. (begin
  13. (set-box! s (cdr stk))
  14. (car stk)))))
  15. (define (stack-push! s v) (set-box! s (cons v (unbox s))))
  16. (define (stack-get s) (unbox s))