aboutsummaryrefslogtreecommitdiff
path: root/data/stack.scm
blob: c28d64875a69a3c59f1bc6fa56654692e743597a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(define-module (data stack)
  #:use-module (control monad)
  #:use-module (control monad state))

;;; Simple stateful stack module for showing the state monad
;;; in action. These functions assume that they are in a
;;; (state list) monad. But dynamic types!

(define (pop)
  (do st <- (get)
      let top = (car st)
      (put (cdr st))
      (return-state top)))

(define (peek)
  (do st <- (get)
      (return-state (car st))))

(define (push v)
  (do st <- (get)
      (put (cons v st))))