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: Re: MyPrependTo

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16112] Re: [mg15988] Re: MyPrependTo
  • From: David Withoff <withoff>
  • Date: Thu, 25 Feb 1999 08:25:04 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

> > In[2]:=
> > push[someStack_, elt_] := (someStack = Prepend[someStack, elt];)
>
> Is it legal in Mathematica to assign a function parameter?

Yes, it is legal to assign values to function arguments.  That is how
built-in assignment functions work.  Assignments are just functions
(Set, SetDelayed, etc.) that assign values to their arguments.

> I think not, because they are avaluated before going in the
> function body (ie, parameters are passed by value, not by
> reference or pointers)

If the value is to be assigned to the original function argument,
rather than to the expression that results after the function argument
has been evaluated, then yes it is necessary to do something, such
as using Unevaluated, or setting the HoldFirst attribute, to prevent
the default normal-order evaluation (evaluating the function arguments
before evaluating the function).  Evaluation control is separate from
the issue of making assignments.  These evaluation controls determine
whether the assignment will be made to the original function argument,
or to the expression that results after the argument has been evaluated.
Mathematica allows you to do either one.

> The solution is to use a golbal stack parameter, or to use
> Return[]
>
> Push[...] := ( Return[Prepend[...]]);
> e = Push[e,1];

Return has no effect in this example, so no, this is not a solution.

> 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.

Expressions are pointers.  You can use them just like you use pointers
in any other programming language.  If you have a simple example that
illustrates your question, you might try posting it to the group,
or sending it to Wolfram Research technical support.

> 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

Dave Withoff
Wolfram Research


  • Prev by Date: Mathematica and Java
  • Next by Date: Lock up
  • Previous by thread: Re: MyPrependTo
  • Next by thread: log log plot