2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
48
Task/Y-combinator/PowerShell/y-combinator-2.psh
Normal file
48
Task/Y-combinator/PowerShell/y-combinator-2.psh
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
$Y = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($x)
|
||||
|
||||
$f.InvokeReturnAsIs({
|
||||
param ($y)
|
||||
|
||||
$x.InvokeReturnAsIs($x).InvokeReturnAsIs($y)
|
||||
}.GetNewClosure())
|
||||
|
||||
}.InvokeReturnAsIs({
|
||||
param ($x)
|
||||
|
||||
$f.InvokeReturnAsIs({
|
||||
param ($y)
|
||||
|
||||
$x.InvokeReturnAsIs($x).InvokeReturnAsIs($y)
|
||||
}.GetNewClosure())
|
||||
|
||||
}.GetNewClosure())
|
||||
}
|
||||
|
||||
$fact = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($n)
|
||||
|
||||
if ($n -eq 0) { 1 } else { $n * $f.InvokeReturnAsIs($n - 1) }
|
||||
|
||||
}.GetNewClosure()
|
||||
}
|
||||
|
||||
$fib = {
|
||||
param ($f)
|
||||
|
||||
{
|
||||
param ($n)
|
||||
|
||||
if ($n -lt 2) { 1 } else { $f.InvokeReturnAsIs($n - 1) + $f.InvokeReturnAsIs($n - 2) }
|
||||
|
||||
}.GetNewClosure()
|
||||
}
|
||||
|
||||
$Y.invoke($fact).invoke(5)
|
||||
$Y.invoke($fib).invoke(5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue