Skip to content

Instantly share code, notes, and snippets.

@knjname
Last active January 3, 2016 13:49
Show Gist options
  • Select an option

  • Save knjname/8472329 to your computer and use it in GitHub Desktop.

Select an option

Save knjname/8472329 to your computer and use it in GitHub Desktop.
$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