MathGroup Archive 1999

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

Search the Archive

Caution with Block vs Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16433] Caution with Block vs Module
  • From: Arnold Gregory Civ AFRL/SNAT <Gregory.Arnold at sn.wpafb.af.mil>
  • Date: Sat, 13 Mar 1999 02:21:45 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

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
_________________________________________________________
D. Gregory Arnold, Ph.D.
Bldg 620  AFRL/SNAT          garnold at mbvlab.wpafb.af.mil
2241 AVIONICS CIR            Voice:  (937) 255-1115 x4388
WPAFB OH 45433-7321            FAX:  (937) 656-4414
_________________________________________________________



  • Prev by Date: Mathematica & Finite Elements
  • Next by Date: orthonormalization : it seems easy ... but.....
  • Previous by thread: Mathematica & Finite Elements
  • Next by thread: Re: Caution with Block vs Module