PowerShell: passing blocks as parameters to functions?

Yeah, you're going recursive because the $block reference in the scriptblock passed into function B gets evaluated in the context of function B and as a result, evaluates to the value of B's $block parameter.

Yeah, you're going recursive because the $block reference in the scriptblock passed into function B gets evaluated in the context of function B and as a result, evaluates to the value of B's $block parameter. If you don't want to change the parameter name (don't blame you) you can force PowerShell to create a new closure in A to capture the value of $block within function A e.g. : function A($block) { B {Write-Host 2; &$block}.GetNewClosure() } function B($block) { Write-Host 1 &$block } A {Write-Host 3}.

Thx. Is there any standard shortcut for creating closures from blocks (e.g. ${})? – TN.

Dec 1 '09 at 19:27 No. The GetNewClosure() method is the only way I'm aware of. – Keith ll Dec 1 '09 at 19:51 Keith – bwerks Jun 10 at 18:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions