Re: Scoping question
- To: mathgroup at smc.vnet.net
- Subject: [mg85717] Re: Scoping question
- From: dh <dh at metrohm.ch>
- Date: Wed, 20 Feb 2008 06:52:37 -0500 (EST)
- References: <fpdv0k$ref$1@smc.vnet.net>
Hi Yaroslav, the first "outer x is 1" comes from the application of: (Print["outer x is ", x]; f2[#]) & to the first element of Range[2]. The second from the application to the second element of Range[2]. The "outer x is 2" come from: f1[x + 1]. If you want to see how the sequence in which the functions are called, you may e.g. use Trace. E.g.: Trace[f1[1], f1[_] | f2[_]] hope this helps, Daniel Yaroslav Bulatov wrote: > The code below defines a function with parameter x. The body contains > another function definition which uses this parameter. Why do "inner x > is" and "outer x is" lines start reporting different values at one > point? > > f1[x_] := ( > f2[y_] := (Print["inner x is ", x]; If[x + 1 < 3, f1[x + 1], 1]); > (Print["outer x is ", x]; f2[#]) & /@ Range[2]; > ) > f1[1] >