-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.scm
More file actions
43 lines (32 loc) · 856 Bytes
/
Copy pathstack.scm
File metadata and controls
43 lines (32 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
;; Stack routines. Based on dfa2.sc in the benchmarks code supplied
;; with Stalin 0.11
(define (make-stack)
(box '()))
(define (stack-empty? s)
(null? (unbox s)))
(define (stack-push! s obj)
(set-box! s (cons obj (unbox s)))
s)
(define (stack-pop! s)
(let ((l (unbox s)))
(set-box! s (cdr l))
(car l)))
(define (stack-depth s)
(let ((l (unbox s)))
(- (length l) 1)))
(define (stack-peek s)
(let ((l (unbox s)))
(car l)))
(define (stack-ppeek s)
(let ((l (unbox s)))
(values (car l) (car (cdr l)))))
(define (stack-rest s)
(let ((l (unbox s)))
(cdr l)))
(define (list->stack lst)
"Create a stack seeded with the elements of lst.
The head of lst becomes the top of the stack."
(box lst))
(define (stack->list s)
"Return the stack contents as a list, top first. Non-destructive."
(unbox s))