MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

implementing a stack

  • To: mathgroup at
  • Subject: [mg15922] implementing a stack
  • From: wself at (Will Self)
  • Date: Wed, 17 Feb 1999 23:33:56 -0500
  • Sender: owner-wri-mathgroup at

I would like to implement a simple stack in Mathematica.
I can use PrependTo for "push", but in that case how do
I implement "pop"?  I have thought about this and I see
that I can do it by creating a global variable that keeps
a list of pairs: the symbols that serve as the names
of the stacks, and the stacks themselves; and having pop
and push access and manipulate this list.  Is that really
what I have to do?

push[a, 1] should push the number 1 onto the stack a, and
return nothing,
pop[a] should return whatever is on the top of stack a, and
reset a to be the rest of the stack.

Will Self

  • Prev by Date: log log plot
  • Next by Date: Pure Functions in rules
  • Previous by thread: log log plot
  • Next by thread: Re: implementing a stack