1(define-record-type Stack
2 (%make-stack store)
3 stack?
4 (store stack-store stack-store-set!))
5
6(define (make-stack)
7 (%make-stack '()))
8
9(define (stack-clear! stack)
10 (stack-store-set! stack '()))
11
12(define (stack-size stack)
13 (length (stack-store stack)))
14
15(define (stack-empty? stack)
16 (zero? (stack-size stack)))
17
18(define (stack-push stack elem)
19 (stack-store-set!
20 stack
21 (cons elem (stack-store stack))))
22
23(define (stack-pop stack)
24 (let* ((lst (stack-store stack))
25 (top (car lst)))
26 (stack-store-set! stack (cdr lst))
27 top))
28
29(define (stack-pops stack amount)
30 (if (<= amount 1)
31 (list (stack-pop stack))
32 (cons
33 (stack-pop stack)
34 (stack-pops stack (dec amount)))))