MathGroup Archive 2001

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

Search the Archive

Re: Memory Conservation

  • To: mathgroup at
  • Subject: [mg29922] Re: Memory Conservation
  • From: Jens-Peer Kuska <kuska at>
  • Date: Thu, 19 Jul 2001 03:56:51 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <9iomg8$i13$> <9j3a5e$in4$>
  • Sender: owner-wri-mathgroup at


Orestis Vantzos wrote:
> a) The main difference between Module and Block is just that; Module removes
> all local variables.

That is nonsense! Module[] has variables with *local* scope. That means,
that for



the function f2 can't access/modify the variable y defined in the
Module[] of
f2. That is the usual behaviour of programming languages 
(with exeption of LISP).




f2[] *can* access and modify the variable y. 
That is called dynamic scope.
Every function that is called form a Block[] has access to the Block[]
This sounds a bit strange but it is very useful. 
Here is an example
of a function that transform a polynom due to Horners rule

makeHorner[x_] := Fold[#2 + x*#1 &, 0, Reverse[coeff]]

PolynomToHorner[p_, x_] /; PolynomialQ[p, x] :=
    coeff = CoefficientList[p, x];

The makeHorner[] function don't need the coefficents as 
an function argument. This is a way to avoid, that large
data copyed to Mathematica's stack. It will usual faster
than Module[] and save stack memory.

*Both* Block[] and Module[] will clean the memory
on return ! The local scope of Module[] is not so clean
implemented as it should. Module[{y},...] will create
a variable y$?  where "?" is a number that changes for
every call of the Module[]. Since y$? is an other symbol
for ervery Module[] execution the called function can't
get the true symbol name if it is not passed as an argument.

BTW: Orestis ! please look into the manuals *before* you post
a false statement.


  • Prev by Date: Re: Thickness Isn't Thickness
  • Next by Date: parametric plots
  • Previous by thread: Re: Memory Conservation
  • Next by thread: weighting CA neighbors by distance