Re: Return Ambiguity
- To: mathgroup at smc.vnet.net
- Subject: [mg97512] Re: Return Ambiguity
- From: Raffy <raffy at mac.com>
- Date: Sat, 14 Mar 2009 05:42:32 -0500 (EST)
- References: <gpaotd$qeb$1@smc.vnet.net> <gpdacm$jrb$1@smc.vnet.net>
No ambiguity? :p What do these return? (Return[#]; 1) &[2] Block[{}, Return[1]; 2] If[True, Return[1]; 2] (Do[Return[1], {1}]; 2) (Block[{}, Return[1]]; 2) Do[Return[Evaluate[Return[1]]], {1}] f := (Module[{}, If[True, Return[1]]]; 2); f 1 /. {1 :> (Return[1]; 2)} It seems like the documentation should say: 1. Properly exits to nearest Do[...]-instruction or SetDelayed- evaluation. 2. Exits all other evaluations oddly by wrapping result in head Return, including a pure function. I feel that Catch/Throw introduces significant speed overhead. A simple return shouldn't need to invoke pattern matching. Usually, the use of Return can be avoided, however, often the equivalent Return-less code usually has excessive indenting. I'd say a proper replacement, would be a function that returns to nearest scoping construct, ie. Block/Module/With.