MathGroup Archive 2009

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

Search the Archive

Return in function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105621] Return in function
  • From: dh <dh at metrohm.com>
  • Date: Fri, 11 Dec 2009 06:46:49 -0500 (EST)


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




  • Prev by Date: Re: CVS Install on Windows XP for Workbench
  • Next by Date: Re: ListPointPlot3D[] couldn't rotate the graph
  • Previous by thread: Re: Notebook
  • Next by thread: Re: Return in function