[plt-scheme] Re: Lexical Scoping, References and Side Effects

From: tbourdon (tbourdon at gmail.com)
Date: Wed Sep 2 10:42:18 EDT 2009

As I said, "For my second implementation I had the stack-push function
just return the updated stack but as you can see this leads to
successive set! calls" and that's the whole point. I don't want stack-
push to return anything. I want it to change the state of the stack
that's passed in so the caller can reference that stack's changed
state later. In other words, is there a way for the following to work?

(define stack ()) ; stack is defined as empty list.
(stack-push stack 1) ; stack-push pushes 1 onto stack.
(stack-top stack) => 1 ; stack-top returns 1.

On Sep 2, 12:30 am, Matthias Felleisen <matth... at ccs.neu.edu> wrote:
> On Aug 30, 2009, at 7:42 PM, tbourdon wrote:
>
>
>
> > Hello -
>
> > I'm currently teaching myself  Scheme by working through "Teach
> > Yourself Scheme in Fixnum Days" and "The Little Schemer". As I was
> > working through the sources I decided to break off and implement some
> > stack data structures. So far I've implemented the stack functions
> > three different ways and I've noticed that I really can't (or haven't
> > found a way) to create a reference to a stack and pass it around to be
> > operated on.
>
> > For example; I can't come up with an implementation for a stack-push
> > function where the following works:
>
> > (define stack ())
> > (stack-push stack 1)
> > (stack-top stack) => 1
>
> You omitted the most important part of your quasi-spec? What should  
> stack-push return?
>
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.