Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: MyPrependTo

  • To: mathgroup at
  • Subject: [mg15966] Re: MyPrependTo
  • From: "Allan Hayes" <hay at>
  • Date: Fri, 19 Feb 1999 03:26:54 -0500
  • References: <7ag26u$>
  • Sender: owner-wri-mathgroup at

Will Self wrote in message <7ag26u$ag9 at>...
>In trying to create my own version of PrependTo, I ran into some strange
>stuff that I don't understand.  I am calling my function "push".  Please
>look at the session below and explain these mysterious happenings.
>It seems clear that there is more than one symbol e kicking around,
>but I can't make head or tail of it.  See also my next message for
>the larger context.
>push[someStack_, elt_] := (someStack = Prepend[someStack, elt];)
>stack[2,1,"expression"]    (* WHAT!!!!???? *)
>e = stack["expression"]   (* DOUBLE WHAT!!!!???? *)
>Will Self



>push[someStack_, elt_] := (someStack = Prepend[someStack, elt];

push[s,e] causes the evaluation of  value[s] = Prepend[s,e]
not the evaluation of s = Prepend[s,e]

So, after



simply adds the assignment  stack[e] = stack[1,e]
so that we now have stored

s = stack[e]
stack[e] = stack[1,e]

(nowhere is e = stack[1,e] stored; the current value of e has to be
constructed from the two preceding definitions:  e -> stack[e] ->stack[1,e])

Now: Rest[e] evauates as follows

Rest[e] -> Rest[stack[e]] -> Rest[stack[1,e]] -> stack[e] -> stack[1,e]

The last step is the surprise!


SetAttributes[push, HoldFirst]

When ?e is entered it gives the value of e by using the current stored
definitions: this does not reveal the mechanism above.
Using FullDefinition[e] will reveal all.


Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

  • Prev by Date: Re: Plot[] problem (plnr) - help !!!
  • Next by Date: Re: Pure Functions in rules
  • Previous by thread: Re: MyPrependTo
  • Next by thread: Re: MyPrependTo