Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Returnin pure function

  • To: mathgroup at
  • Subject: [mg58887] Re: Returnin pure function
  • From: Bill Rowe <readnewsciv at>
  • Date: Fri, 22 Jul 2005 01:58:36 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On 7/21/05 at 3:46 PM, dh at (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?


f[x_]:=If[x==0, Error, x]


f=If[#==0, Error, #]&

will do what you want. That is,

f[x_] := If[x == 0, Error, x]; 
g = If[#1 == 0, Error, #1] & ; 
f /@ {0, 1} == g /@ {0, 1}

To reply via email subtract one hundred and four

  • Prev by Date: Re: Return[] in pure function
  • Next by Date: Re: Combinatorica functions doc
  • Previous by thread: Re: LegendreP error (bug?) in Mathematica
  • Next by thread: Re: Re: Returnin pure function