Last active
January 3, 2016 13:49
-
-
Save knjname/8472329 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $givenValue = 10 | |
| function testIfSupportingClosure(){ | |
| $givenValue = 4 | |
| { | |
| $givenValue = $givenValue + 1 | |
| echo "The givenValue is ${givenValue}." | |
| } | |
| } | |
| $closureA = testIfSupportingClosure | |
| $closureA.invoke() # The givenValue is 11. | |
| $closureA.invoke() # The givenValue is 11. | |
| $closureB = testIfSupportingClosure | |
| $closureB.invoke() # The givenValue is 11. | |
| $closureB.invoke() # The givenValue is 11. | |
| $givenValue = 20 | |
| $closureA.invoke() # The givenValue is 21. | |
| function testIfSupportingDynamicBinding($prc){ | |
| $givenValue = 100 | |
| $prc.invoke() | |
| } | |
| testIfSupportingDynamicBinding $closureA # The givenValue is 101. | |
| $closureA.invoke() # The givenValue is 21. | |
| # Hence, | |
| # We can say that PowerShell supports dynamic scope semantics. | |
| echo ($closureA -eq $closureB) # However, this is "False". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment