Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

pass by reference

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93685] pass by reference
  • From: juan flores <juanfie at gmail.com>
  • Date: Sat, 22 Nov 2008 06:09:55 -0500 (EST)

Dear all,

How do you pass by reference in Mathematica?

Let us say we want to program push and pop.
--------
Push[el_, stack_] := Prepend[stack, el]
Pop[stack_] := {First[stack], Rest[stack]}

stack = {1, 2, 3}; newel = 5;

stack = Push[newel, stack]
{5, 1, 2, 3}

{lastel, stack} = Pop[stack]
{5, {1, 2, 3}}

stack
{1, 2, 3}
--------

Code is working, but it is kind of awkward to have to use pure
functional programming.  I have not been able to find the way to pass
parameters by reference (or name - i.e. macros).

Any pointers/ideas will be greatly appreciated.

Have a good one,

Juan Flores


  • Prev by Date: financial chart with volumes
  • Next by Date: Re: Coloring Histograms
  • Previous by thread: Re: financial chart with volumes
  • Next by thread: Re: pass by reference