MathGroup Archive 1992

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

Search the Archive

declaration-assignment-dynamic binding update

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: declaration-assignment-dynamic binding update
  • From: gaylord at ux1.cso.uiuc.edu
  • Date: Thu, 12 Mar 1992 05:11:50 -0600

translating ML code from Thomas Yan into Mathematica code:

 fun g(f,x) = let val c = 3 in f(x) end
    fun h() = let val c = 5
                   fun f(x) = x + c
                   val a = g(f,0)
                   val c = 7
                   val b = g(f,1)
               in (a,b) end
================================================
Clear[f, g, h]
g[f_, x_] := Module[{c = 3}, f[x]]
h[] := Module[{c = 5},
											f[x_] := x + c;
											a = g[f, 0];
											c = 7;
											b = g[f, 1];
											{a, b}]

h[]
{5, 8}

Clear[f, g, h]
g[f_, x_] := Module[{c = 3}, f[x]]
h[] := Module[{c = 5},
											f[x_] = x + c;
											a = g[f, 0];
											c = 7;
											b = g[f, 1];
											{a, b}]

h[]
{5, 6}

Clear[f, g, h]
g[f_, x_] := Block[{c = 3}, f[x]]
h[] := Block[{c = 5},
											f[x_] = x + c;
											a = g[f, 0];
											c = 7;
											b = g[f, 1];
											{a, b}]h[]
{5, 6}

Clear[f, g, h]
g[f_, x_] := Block[{c = 3}, f[x]]
h[] := Block[{c = 5},
											f[x_] := x + c;
											a = g[f, 0];
											c = 7;
											b = g[f, 1];
											{a, b}]

h[]
{3, 4}


according to Thomas Yan:
declaration gives (5, 6)
assignment gives (5, 8)  
dynamic binding gives (3, 4).


overall, for M:

using  = with either Block or Module gives {5, 6} which T. Yan calls
declaration.
(Mathematica calls = assignment)

using := with Module gives {5, 8} which T. Yan calls assignment.
(Mathematica calls := delayed assignment)


using := with Block gives {3, 4} which T. Yan calls dynamic binding and D.
Lichtblau calls dynamic scoping. 
(D.L. says binding is independent of assignment vs. declaration)

nothing like having an agreed upon notation (nothing at all like that).






  • Prev by Date: Re: A negative volume!
  • Next by Date: Re: LatticeReduce
  • Previous by thread: declaration-assignment-dynamic binding update
  • Next by thread: screen redraw