# procedural representation for the stack? (LIFO structure)

I'm trying to do the exercise 2.12 of the book Essential of programing languages 3rd edition.

They ask me to do a procedural representation for a stack, like they did in the example of page 40 with enviroment.

This is the example.

(define empty-env
(lambda ()
(lambda (search-var)
(report-no-binding-found search-var))
)
)

(define extend-env
(lambda (saved-var saved-val saved-env)
(lambda (search-var)
(if (eqv? search-var saved-var)
saved-val
(apply-env saved-env search-var)
)
))
)

(define apply-env
(lambda (env search-var)
(env search-var))
)


In the exercise they ask me for the next procedures:

push, pop, top, and empty-stack?


I think I did the push, top and empty-stack. But I can't figure out how to do the pop.

Thank you.

-
how did you do the pop ? –  AJed Jan 15 '13 at 2:54
I didn't do it, that's what I want to know. –  Andrés Felipe Téllez Crespo Jan 15 '13 at 3:06
I m sorry, I meant the top .. –  AJed Jan 15 '13 at 3:33
Top is an observer, and beacuse the stack is a function, one can just evaluate the stack in any number, because the push just do the work. –  Andrés Felipe Téllez Crespo Jan 15 '13 at 3:37
Maybe I'm missing something, but what is the problem? Can you explain two things for us, (a) what is the definition of pop, and (b) what you are not certain of. pop is probably supposed to return a new stack without the top element, so why do you not simply return a new stack, but with doing rest on the data? –  Pål GD Jan 16 '13 at 9:19
show 1 more comment