MathGroup Archive 2009

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

Search the Archive

Re: Return in function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105686] Re: Return in function
  • From: magma <maderri2 at gmail.com>
  • Date: Tue, 15 Dec 2009 07:27:51 -0500 (EST)
  • References: <hftbe9$cjh$1@smc.vnet.net>

On Dec 11, 12:46 pm, dh <d... at metrohm.com> wrote:
> Version 7.0.1
>
> Hello,
>
> I am not sure if this is a feature or a bug. If you use Return in an
>
> anonymous function, not only the return value is returned, but also
>
> "Return" itself. Consider:
>
> (If[# == 2, Return[a]; #, #]) & /@ {1, 2, 3}
>
> this gives:
>
> {1, Return[a], 3}
>
> The same thing happens with:
>
> Function[x, If[x == 2, Return[a]; x, x]] /@ {1, 2, 3}
>
> However, the following works as expected:
>
> f[x_] := (If[x == 2, Return[a]; x, x]);
>
> f /@ {1, 2, 3}
>
> Daniel

It looks like a bug.
One thing I do not understand: what is the point of writing Return[a];
x in the definition of f[x_] ?
Anything after Return is discarded anyway.


  • Prev by Date: Free online Mathematica seminars in December
  • Next by Date: Re: Buying and running older version of Mathematica on a Netbook
  • Previous by thread: Re: Return in function
  • Next by thread: Re: Return in function