Re: MyPrependTo
- To: mathgroup at smc.vnet.net
- Subject: [mg15968] Re: MyPrependTo
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Fri, 19 Feb 1999 03:26:55 -0500
- Organization: Universitaet Leipzig
- References: <7ag26u$ag9@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Will,
the strange stuff is due to your strange use of evaluation.
If you what to use Set[] keep in mind that it has the attribute
HoldFirst[]. You can only assign a value to a symbol
(or assign lists of values to lists of symbols, or parts of a list to a
value)
I append the working version of definitions for push and pop.
SetAttributes[StackPush,HoldFirst]
SetAttributes[StackPop,HoldAll]
StackPush[someStack_Symbol,elt_]:=(Set[someStack,Prepend[someStack,elt]];
Null)
StackPop[e_Symbol]:=Module[{head},head=First[e];e=Rest[e];head]
I strongly recommend that you take a brake in Mathematica programming
and spend some winter evenings with the excelent book
"Programming in Mathematica" by Roman Maeder Third Edition.
Hope that helps
Jens
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]:=
---- snip snap snip snap ---