RosettaCodeData/Task/Stack/Racket/stack-2.rkt

9 lines
308 B
Racket
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
(struct stack ([items #:auto]) #:mutable #:auto-value '())
(define (push! x stack)
(set-stack-items! stack (cons x (stack-items stack))))
(define (pop! stack)
(begin0 (car (stack-items stack))
(set-stack-items! stack (cdr (stack-items stack)))))
(define (empty? stack)
(null? (stack-items stack)))