Whenever I define a function say funct(n), then can I assign value of n to a different variable such as m so that I can compare value of n which changes within the function with the initial value of m. Further, since I have nested and sometimes independent other functions, is there a way to make the m variable universal?
What I did is:
fun funct(n)= let val m=n in if (condition) then...
Further, here funct calls funct1 and funct1 calls funct2. The error message reads
Error: unbound variable or constructor: m
for funct2
Error: unbound variable or constructor: funct1
for funct1
Error: unbound variable or constructor: funct1
for funct
I suppose the single correction of m would solve the wholse cascade of errors.
You can access any identifier from scopes which are deeper than the one the identifer has been defined in. E.g.
In this example,
funct1has access ton, which has been defined in an outer scope (namely as a parameter offunct).Be careful though, in functional languages like ML, identifiers have a different meaning from those in imperative languages like C. In your example,
nandmare not variables, meaning the values denoted by the identifiers will not change. You can only redefine the identifiers; however, code that uses an identifier before its redefinition will always refer to the original value of that identifier.