Re: Re: exchanging 2 elements in a list (problem with Block)
- To: mathgroup at smc.vnet.net
- Subject: [mg27791] Re: [mg27631] Re: exchanging 2 elements in a list (problem with Block)
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Fri, 16 Mar 2001 04:37:45 -0500 (EST)
- Organization: University of California, Berkeley
- References: <933FF20B19D8D411A3AB0006295069B0286951@dassne02.darmstadt.dsh.de> <3AAF97B7.8494FB81@cs.berkeley.edu> <000d01c0acc9$9995a8e0$9b16989e@machine1>
- Sender: owner-wri-mathgroup at wolfram.com
I guess the examples of why Block is preferable to Module don't seem convincing to me. The first example is simply to avoid having the variable i evaluated. In a language with single-level evaluation it should be possible to quote variables. Thus Table [Quote[i]^j,{j,3}] ; Hold[] in Mathematica is not the same as this. I find Hold to be unuseable. For reasons of the evaluation strategy in Mathematica, I suppose Quote[] is difficult. In my view, the result of Module is right, even though the printout is bad. Establishing a local variable i and then squaring it should not return the variable associated with the global name i. I don't understand what example 2 does. If the intention is to dynamically hide the definition of Dot and all its rules by the Block[{Dot}...] then I suppose that is of some use. I didn't know that would work for built-in "functions", and I suspect that it doesn't. That is Foo[x_]:=foobar[x] Block[{Foo},Print[Foo[3]]] prints Foo[3] not foobar[3] so the definition of Foo is blocked. (works) And similarly for Block[{Sin},Print[Sin[1.2]]] (works) but not for Block[{Plus},Print[Plus[1,1]]] (doesn't work). or Block[{Times=Plus},4!] (doesn't work[??]) I think the point of the other examples is to use dynamic scope to hide definitions temporarily. That's OK if used with restraint. Block[{D=3}, ...f[x]] presumably breaks the Derivative function in the "call" to f[]. The Module "bugs" though are related to the erroneous implementation of Module in mathematica. Faking the module variables but by having equivalent user-syntax alternatives looks like an implementation or perhaps a design error.