Re: Caution with Block vs Module
- To: mathgroup at smc.vnet.net
- Subject: [mg16491] Re: Caution with Block vs Module
- From: sb.nospam at stonetics.com (Stonewall Ballard)
- Date: Tue, 16 Mar 1999 03:59:44 -0500
- Organization: Stonetics, Inc.
- References: <7cd485$o0s@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Greg,
You have to be careful any time you pass unevaluated variables into a
function. I don't think that Block is unique in causing problems with
that. Or even Mathematica. Lisp macros can suffer from this problem as
well.
- Stoney
In article <7cd485$o0s at smc.vnet.net>, Arnold Gregory Civ AFRL/SNAT
<Gregory.Arnold at sn.wpafb.af.mil> wrote:
> Hello all:
>
> I just "discovered" a nuance of Block which I did not anticipate so I
> thought I would share it with all of you.
>
> I started using Block as the head of all my functions after reading the
> message a few weeks ago on Block vs. Module. I thought I understood the
> differences, but the following example took me a long while to track down
> :(
>
> test[eq_]:=Block[{x},x=eq; Return[1]];
>
> test[c*x]
>
> This gives a RecursionLimit. This occurs because only the value of x is
> blocked. Therefore test effectively says "x=c*x", which if you try it
> directly will also give you a RecursionLimit. Based on this aspect of
> Block, I think Module is the most appropriate method (in general) to use for
> functions!
>
> Greg
--
Stonewall Ballard Stonetics, Inc.
sb.nospam at stonetics.com http://www.stonetics.com/