Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg15982] Re: MyPrependTo
  • From: David Reiss <David_B_Reiss_NoSpam at res.raytheon.com>
  • Date: Fri, 19 Feb 1999 03:27:03 -0500
  • Organization: Raytheon Company
  • References: <7ag26u$ag9@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

After the first call to push below you are changing the definition of
"stack" rather than "e". This is because after the first evaluation of
push[e,1] the value of "e" is inserted into the "someStack" part of the
definition of "push" before the right hand side is evaluated, thus giving an
added defintion for "stack" rather than for "e".


In[1]:= push[someStack_, elt_] := (someStack = Prepend[someStack, elt];)

In[2]:= e=stack["expression"]

Out[2]=
stack["expression"]

In[3]:= ?e

"Global`e"
e = stack["expression"]

In[4]:= ?stack

"Global`stack"

In[5]:= push[e,1]

In[6]:=
?e

"Global`e"
e = stack["expression"]

In[7]:= ?stack

"Global`stack"
stack["expression"] = stack[1, "expression"]

In[8]:= push[e,2]

In[9]:= ?e

"Global`e"
e = stack["expression"]

In[10]:= ?stack

"Global`stack"
stack["expression"] = stack[1, "expression"]

stack[1, "expression"] = stack[2, 1, "expression"]






Regards,

David




Will Self wrote:

> 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.
>
> In[2]:=
> push[someStack_, elt_] := (someStack = Prepend[someStack, elt];)
>
> In[3]:=
> e=stack["expression"]
> Out[3]=
> stack["expression"]
>
> In[4]:=
> push[e,1]
>
> In[5]:=
> e
> Out[5]=
> stack[1,"expression"]
>
> In[6]:=
> push[e,2]
>
> In[7]:=
> e
>
> Out[7]=
> stack[2,1,"expression"]
>
> In[8]:=
> Rest[e]
> Out[8]=
> stack[2,1,"expression"]    (* WHAT!!!!???? *)
>
> In[9]:=
> ?e
> "Global`e"
> e = stack["expression"]   (* DOUBLE WHAT!!!!???? *)
>
> Will Self





  • Prev by Date: Re: Pure Functions in rules
  • Next by Date: Re: MyPrependTo
  • Previous by thread: Re: MyPrependTo
  • Next by thread: Re: MyPrependTo