Re: Returnin pure function
- To: mathgroup at smc.vnet.net
- Subject: [mg58896] Re: Returnin pure function
- From: dh <dh at metrohm.ch>
- Date: Sat, 23 Jul 2005 05:32:03 -0400 (EDT)
- References: <dbq2gu$6vb$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Bill, the idea behind my question is a simple way to prematurely leave a function. sincerely, Daniel Bill Rowe wrote: > On 7/21/05 at 3:46 PM, dh at metrohm.ch (dh) wrote: > > >>Hi, I seems to me that there is a bug in the implementation of pure >>functions. If somebody can explain the following behaviour it would >>be interessting. If not, maybe Wolfram can contribute something. >>Consider f[x_]:= If[x==0,Return[Error],x]; f /@ {1,0} gives >>{1,Error} what is fine. Now replace the function by a pure >>function: If[#==0,Return[Error],#]& /@ {1,0} this gives >>{1,Return["Error"]}. The Return statement has not been evaluated. > > > Why do you want to use Return in this manner? > > Either > > f[x_]:=If[x==0, Error, x] > > or > > f=If[#==0, Error, #]& > > will do what you want. That is, > > In[6]:= > f[x_] := If[x == 0, Error, x]; > g = If[#1 == 0, Error, #1] & ; > f /@ {0, 1} == g /@ {0, 1} > > Out[8]= > True > -- > To reply via email subtract one hundred and four >