Powershell script blocks are not closures

I’ve been experimenting some more with the script blocks, and I’ve found that my description of them as sort-of-closures in my other post is wrong. Here is an example that demonstrates it: PS > function g { param($block) $a=234; &$block; }PS > function f { $a=123; g { “The value of `$a is $a” }…

4

calling the script blocks in PowerShell

The script blocks are the PowerShell way to pass a chunk of code as an argument to a command. So when you write something like dir -Recurse . | where { $_ -match “\.txt” } that thing in the braces {} is a script block. Essentially, an anonymous function. Some might also say that it’s a…

2