Skip to content

test_25_more_scoping

David Pollak edited this page Jan 13, 2012 · 1 revision

More Scoping

Another test for scoping. We assign a local variable moo to the result of the internal fact computation and then return moo.

fact n = n & "hello" // propper scoping this fact is not the inner fact

f n = /* test that the function closes over local scope */
  fact n = if n == 0 then 1 else n * fact(n - 1)
  moo = fact n /* This is the local reference to 'n' */
  moo // one level of indirection -- a local variable

res = f 7 // == 5040