Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: function's local constants interdependence

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69613] Re: function's local constants interdependence
  • From: dimmechan at yahoo.com
  • Date: Sun, 17 Sep 2006 22:45:43 -0400 (EDT)
  • References: <eejaql$40m$1@smc.vnet.net>

Hi Igor.

You should use Block.

Clear["Global*"]
ff[x_, y_] := Block[{a = x, b = 2*a}, {a, b}]
ff[x, y]
{x, 2*x}

You can also execute the following commands to see the difference.

Clear["Global*"]
ff[x_, y_] := With[{a = x, b = 2*a}, {a, b}]
Trace[ff[x, y], TraceOriginal -> True]

Clear["Global*"]
ff[x_, y_] := Block[{a = x, b = 2*a}, {a, b}]
Trace[ff[x, y], TraceOriginal -> True]

Clear["Global*"]
ff[x_, y_] := Module[{a = x, b = 2*a}, {a, b}]
Trace[ff[x, y], TraceOriginal -> True]

Regards
Dimitris Anagnostou

Î?/Î? rych έγÏ?αÏ?ε:
> Could someone please help me find a decent way to have local constants
> defined using one another in order?
> Simple "With[" doesn't work:
>
> Clear[a,b,x,y]
> ff[x_,y_]:=With[{a=x, b=2*a},{a,b}]
> ff[x,y]
> > {x,2 a}
>
> where I'd like it be >{x, 2 x}. I suspect it would work with "Module["
> but I especially wanted them to be constants.
>
> Do I have to nest With[ ? Or is there a prettier way?
> Thanks
> Igor


  • Prev by Date: Re: function's local constants interdependence
  • Next by Date: webMathematica, Packages, and hostSRV.com
  • Previous by thread: Re: function's local constants interdependence
  • Next by thread: attention 64 bit Mathematica users - would you please test a command for me?