Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Having found out about the second argument to Returnsecond argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

edited title
Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

What can be usedI use as the second argument to Return on yourin my own functions?

changed link to specific comment
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

Having found out about the second argument to Returnsecond argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

Having found out about the second argument to Return I played a bit with it, and the following tests all resulted in Return::nofunc:

f[x_]:=x
f[Return[3,f]]

SetAttributes[g,HoldAll];g[x_]:=x
g[Return[3,g]]

h[x_]:=f[x]
h[Return[3,f]]

SetAttributes[i,HoldAll];i[x_]:=f[x]
i[Return[3,f]]

On the other hand, the following works fine:

Module[{i},Return[3,Module]]

Does that mean the second argument of Return can only be used with a predefined list of symbols? If so, is there an easy way to find out that list? Otherwise, what am I doing wrong (and how would I do it right)?

Tweeted twitter.com/#!/StackMma/status/213354145531441152
Source Link
celtschk
  • 19.2k
  • 1
  • 51
  • 107
Loading