Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -19,10 +19,10 @@ End Type
|
|||
'Function definitions - extend with fields as locals and implement apply as body
|
||||
Type Scope Extends Func Abstract
|
||||
Field env:Scope
|
||||
|
||||
|
||||
'Constructor - bind an environment to a procedure
|
||||
Function lambda:Scope(env:Scope) Abstract
|
||||
|
||||
|
||||
Method _init:Scope(_env:Scope) 'Helper to keep constructors small
|
||||
env = _env ; Return Self
|
||||
End Method
|
||||
|
|
@ -37,11 +37,11 @@ End Type
|
|||
'Y (outer)
|
||||
Type Y Extends Scope
|
||||
Field f:Func 'Parameter - gets closed over
|
||||
|
||||
|
||||
Function lambda:Scope(env:Scope) 'Necessary due to highly limited constructor syntax
|
||||
Return (New Y)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Func(args:Object[])
|
||||
f = Func(args[0])
|
||||
Local _r:Func = YInner1.lambda(Self)
|
||||
|
|
@ -52,11 +52,11 @@ End Type
|
|||
'First lambda within Y
|
||||
Type YInner1 Extends Scope
|
||||
Field r:Func 'Parameter - gets closed over
|
||||
|
||||
|
||||
Function lambda:Scope(env:Scope)
|
||||
Return (New YInner1)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Func(args:Object[])
|
||||
r = Func(args[0])
|
||||
Return Func(Y(env).f.apply([YInner2.lambda(Self)]))
|
||||
|
|
@ -66,11 +66,11 @@ End Type
|
|||
'Second lambda within Y
|
||||
Type YInner2 Extends Scope
|
||||
Field a:Object[] 'Parameter - not really needed, but good for clarity
|
||||
|
||||
|
||||
Function lambda:Scope(env:Scope)
|
||||
Return (New YInner2)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Object(args:Object[])
|
||||
a = args
|
||||
Local r:Func = YInner1(env).r
|
||||
|
|
@ -86,11 +86,11 @@ End Type
|
|||
|
||||
Type FacL1 Extends Scope
|
||||
Field f:Func 'Parameter - gets closed over
|
||||
|
||||
|
||||
Function lambda:Scope(env:Scope)
|
||||
Return (New FacL1)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Object(args:Object[])
|
||||
f = Func(args[0])
|
||||
Return FacL2.lambda(Self)
|
||||
|
|
@ -101,7 +101,7 @@ Type FacL2 Extends Scope
|
|||
Function lambda:Scope(env:Scope)
|
||||
Return (New FacL2)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Object(args:Object[])
|
||||
Local x:Int = Integer(args[0]).val
|
||||
If x <= 0 Then Return Integer.Make(1) ; Else Return Integer.Make(x * Integer(FacL1(env).f.apply([Integer.Make(x - 1)])).val)
|
||||
|
|
@ -116,11 +116,11 @@ End Type
|
|||
|
||||
Type FibL1 Extends Scope
|
||||
Field f:Func 'Parameter - gets closed over
|
||||
|
||||
|
||||
Function lambda:Scope(env:Scope)
|
||||
Return (New FibL1)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Object(args:Object[])
|
||||
f = Func(args[0])
|
||||
Return FibL2.lambda(Self)
|
||||
|
|
@ -131,7 +131,7 @@ Type FibL2 Extends Scope
|
|||
Function lambda:Scope(env:Scope)
|
||||
Return (New FibL2)._init(env)
|
||||
End Function
|
||||
|
||||
|
||||
Method apply:Object(args:Object[])
|
||||
Local x:Int = Integer(args[0]).val
|
||||
If x < 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue