Leonid wrote in chapter iv of his book : "… Module, Block and With. These constructs are explained in detail in Mathematica Book and Mathematica Help, so I will say just a few words about them here. …"
From what I have read ( been able to find ) I am still in the dark. For packaged functions I ( simply ) use Module, because it works and I know the construct. It may not be the best choice though. It is not entirely clear to me ( from the documentation ) when, where or why to use With ( or Block ).
A more practical difference between
BlockandModulecan be seen here:So if you wish to return eg
x, you can useBlock. For instance,does not work; to make it work, one could use
(of course this is not ideal, it is simply an example).
Another use is something like
Block[{$RecursionLimit = 1000},...], which temporarily changes$RecursionLimit(Modulewould not have worked as it renames$RecursionLimit).One can also use
Blockto block evaluation of something, egie, it returns
Sin[0.5]which is only evaluated after theBlockhas finished executing. This is becauseSininside theBlockis just a symbol, rather than the sine function. You could even do something like(use
Traceto see how it works). So you can useBlockto locally redefine built-in functions, too: