I think that I almost understand "shadowing", maybe ...
val pi = 3.14159; fun area (r) = pi*r*r; area 2.0; => 12.56636
So far so good ...
re-declare pi ... val p1 = 0.0;
Here is where things get blurry for me. When/how is the *new* pi available? Is it only available if re-declared in a *block* of code, making it local to that block and therefore usable there and only there?
After re-declaring pi above, executing the "area" function uses the original pi.
I get that!
What I'm not sure of is how to use the re-declared pi. TIA ...
Duke,
To use the re-declared pi, you just cite it in an expression as normal. The new declaration overrides the earlier one in the subsequent code, but as you are aware, the references to pi prior to the redeclaration remain bound to the original declaration, as in the following example:
val x = 99;
val x = 99: int
x + 22;
val it = 121: int
val x = 100;
val x = 100: int
x + 22;
val it = 122: int
Regards,
Rob
On 24 Jan 2026, at 16:20, Duke Normandin sidney.reilley.ii@gmail.com wrote:
I think that I almost understand "shadowing", maybe ...
val pi = 3.14159; fun area (r) = pi*r*r; area 2.0; => 12.56636
So far so good ...
re-declare pi ... val p1 = 0.0;
Here is where things get blurry for me. When/how is the *new* pi available? Is it only available if re-declared in a *block* of code, making it local to that block and therefore usable there and only there?
After re-declaring pi above, executing the "area" function uses the original pi.
I get that!
What I'm not sure of is how to use the re-declared pi. TIA ...
-- Duke _______________________________________________ Poly/ML mailing list -- polyml@lists.polyml.org To unsubscribe send an email to polyml-leave@lists.polyml.org
On Sat, 24 Jan 2026 23:01:04 +0000 Rob Arthan rda@lemma-one.com wrote:
Thanks for for reply, Rob!
To use the re-declared pi, you just cite it in an expression as normal. The new declaration overrides the earlier one in the subsequent code, but as you are aware, the references to pi prior to the redeclaration remain bound to the original declaration, as in the following example:
So, in the example I gave in my original post, the function `area' is also bound to the first declaration of pi. The re-declaration of pi is available immediately for everything using it afterwards, but NOT the function `area'. Unless I re-declare the `area' function as well.
Is that correct?