Skip to content

Instantly share code, notes, and snippets.

@banderson623
Created August 9, 2013 22:12
Show Gist options
  • Save banderson623/6197738 to your computer and use it in GitHub Desktop.
Save banderson623/6197738 to your computer and use it in GitHub Desktop.
stupid scheme...
(define empty-stack-v (lambda () (vector) ))
(define empty-stack-v? (lambda(stack) (equal? stack (empty-stack-v))))
(define push-v (lambda (stack item)
(if (eqv? stack (empty-stack-v)) (vector item)
(vector-append (vector item) stack))
))
(define pop-v (lambda (stack)
(if (equal? stack (empty-stack-v))
#f ; stack is empty
(vector-take-right stack (- (vector-length stack) 1))
)))
(define top-v (lambda (stack)
(if (equal? stack (empty-stack-v))
#f ; This is what happens when the stack is empty
(vector-ref stack (- (vector-length stack) 1))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment