Re: MyPrependTo

*To*: mathgroup at smc.vnet.net*Subject*: [mg16011] Re: MyPrependTo*From*: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>*Date*: Sat, 20 Feb 1999 02:52:03 -0500*Organization*: Universitaet Leipzig*References*: <7ag26u$ag9@smc.vnet.net> <7aj9no$ils@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi Dan, _IT_IS_ILLEGAL_ (!!!!) to assign a "function parameter". Because Mathematica don't know what function parameters are. the definition someFunc[a_,b_]:=doSomething gives a pattern ! a_ and b_ are *not* paramters in the sense of C, FORTRAN, Pascal ... a_ and b_ are patterns and can stand for any expression value. A pattern is some general construct. Let me give you an example. In the natural language "dog" in "Any dog eat meat." is a pattern you can match this pattern by "Fluffy is a dog" (dog-> Fluffy) and get a true sentence. If you assign a pattern in the expression you say all dogs are Fluffy and that is clearly nonsense. In fact it is so that assigments to pattern in function rules can mix up Mathematica completly. In earlyer versions the kernel crashes or give total strange results. Now only the strange results are present. Will Self gaves a nice example of the unpredicable nonsense produced by Mathematica when a pattern inside a function definition get an assigment. Regards Jens Dan Truong wrote: > > > In[2]:= > > push[someStack_, elt_] := (someStack = Prepend[someStack, elt];) > > Is it legal in Mathematica to assign a function parameter? > I think not, because they are avaluated before going in the > function body (ie, parameters are passed by value, not by > reference or pointers) > > The solution is to use a golbal stack parameter, or to use > Return[] > > Push[...] := ( Return[Prepend[...]]); > e = Push[e,1]; > > BTW: does anyone know how to pass a pointer to an object > so it can be modified and returned? HoldFirst etc. do not > do that. > > -- > Dan N. Truong, IRISA, Campus de Beaulieu, 35042 Rennes Cedex, FRANCE > tel:(+33)2 99 84 25 39 fax:(+33)2 99 84 25 28 > mailto:dtruong at irisa.fr http://www.irisa.fr/caps/PEOPLE/Dan > gsm:06 14 78 06 95 -> http://www.sfr.fr/html/annexes/sms/sendsms.html