0

I have a stack procedure which is designed in a object oriented programming paradigm, one of the nested procedures in my stack is a print. Since my stack is literally a list I can easily print it by just calling the global variable my-stack but I don't want to print it as a list, I would like to print it as a stack one thing on top of the other, is there a way?

(define (print)
(define (print-helper stack)
  (if (empty?)'()
      (print-helper (cdr stack))
))
(print-helper my-stack))

1 Answers1

0

If it's a stack, we want to print the last element added first. This should do the trick:

(define (print)
  (define (print-helper stack)
    (cond ((empty? stack) 'done)
          (else
           (print-helper (cdr stack))
           (display (car stack))
           (newline))))
  (print-helper my-stack))
Óscar López
  • 232,561
  • 37
  • 312
  • 386