evaluating call-by-need on the control stack · evaluating call-by-need on the control stack...
TRANSCRIPT
![Page 1: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/1.jpg)
Evaluating Call-by-need on the Control Stack
Stephen Chang, David Van Horn, Matthias Felleisen
Northeastern University
1
![Page 2: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/2.jpg)
Lazy Abstract Machines
Sharing implemented with:heap
2
![Page 3: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/3.jpg)
Lazy Abstract Machines
Sharing implemented with:heap
stack operations(alternative approach)
3
![Page 4: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/4.jpg)
Lazy Abstract Machines
Sharing implemented with:heap
stack operations(alternative approach)
[Garcia et al. 2009]
4
![Page 5: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/5.jpg)
Our Paper
• New way to resolve variable references in the stack
5
![Page 6: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/6.jpg)
Our Paper
• New way to resolve variable references in the stack
• Reorganize stack structure to allow indexing
6
![Page 7: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/7.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
7
![Page 8: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/8.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
8
![Page 9: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/9.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
9
![Page 10: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/10.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
10
![Page 11: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/11.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M | (λx.E[x]) E
11
![Page 12: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/12.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M[ ] | E M[ ] | E M[ ] | E M | (λx.E) M | (λx.E[x]) E
12
![Page 13: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/13.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M(λx.E) M(λx.E) M(λx.E) M | (λx.E[x]) E
13
![Page 14: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/14.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M | (λx.E[x]) E(λx.E[x]) E(λx.E[x]) E(λx.E[x]) E
14
![Page 15: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/15.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M | (λx.E[x]) E
deref (β alternative):
(λx.E[x]) V (λx.E[VVVV]) V
15
![Page 16: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/16.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M | (λx.E[x]) E
deref (β alternative):
(λx.E[x]) V (λx.E[VVVV]) V
• One-at-a-time substitution (only when needed)
16
![Page 17: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/17.jpg)
Call-by-need λ-Calculus
[Ariola et al. 1995][Ariola and Felleisen 1997]
• Delay evaluation of argument until needed
• Evaluate each argument only once
M = x | M M | λx.M
E = [ ] | E M | (λx.E) M | (λx.E[x]) E
deref (β alternative):
(λx.E[x]) V (λx.E[VVVV]) V
• One-at-a-time substitution (only when needed)
• Argument not removed (may need it again)
17
![Page 18: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/18.jpg)
An Initial Abstract Machine
18
![Page 19: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/19.jpg)
An Initial Abstract Machine
Standard Reduction = abstract machine
E[M] SR E[N]
if M N
19
![Page 20: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/20.jpg)
An Initial Abstract Machine
Standard Reduction = abstract machine
E[M] SR E[N]
if M N
• Re-partition into E and M after every reduction
20
![Page 21: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/21.jpg)
CK Machine
[Felleisen 1986]
(For by-value λ calculus)
• Separate program into two registers:
CCCC = Current subterm being evaluated
KKKK = Continuation (equiv. to eval. context)
21
![Page 22: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/22.jpg)
CK Machine
[Felleisen 1986]
(For by-value λ calculus)
• Separate program into two registers:
CCCC = Current subterm being evaluated
KKKK = Continuation (equiv. to eval. context)
Don't need to re-partition program after every reduction
22
![Page 23: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/23.jpg)
CK Machine
[Felleisen 1986]
(For by-value λ calculus)
• Separate program into two registers:
CCCC = Current subterm being evaluated
KKKK = Continuation (equiv. to eval. context)
Don't need to re-partition program after every reduction
[Garcia et al. 2009]: lazy CK machine
23
![Page 24: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/24.jpg)
Evaluation Contexts (E) vs Continuations (K)
[ ] ~ mt
E[[ ] M] ~ (arg M K)E ~ K
E[(λx.[ ]) M] ~ (bind x M K)E ~ K
E[(λx.E'[x]) [ ]] ~ (op x K' K)K' ~ E', K ~ E
24
![Page 25: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/25.jpg)
Evaluation Contexts (E) vs Continuations (K)
[ ] ~ mt[ ] ~ mt[ ] ~ mt[ ] ~ mt
E[[ ] M] ~ (arg M K)E ~ K
E[(λx.[ ]) M] ~ (bind x M K)E ~ K
E[(λx.E'[x]) [ ]] ~ (op x K' K)K' ~ E', K ~ E
25
![Page 26: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/26.jpg)
Evaluation Contexts (E) vs Continuations (K)
[ ] ~ mt
E[[ ] M] ~ (arg M K)E[[ ] M] ~ (arg M K)E[[ ] M] ~ (arg M K)E[[ ] M] ~ (arg M K)E ~ K
E[(λx.[ ]) M] ~ (bind x M K)E ~ K
E[(λx.E'[x]) [ ]] ~ (op x K' K)K' ~ E', K ~ E
26
![Page 27: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/27.jpg)
Evaluation Contexts (E) vs Continuations (K)
[ ] ~ mt
E[[ ] M] ~ (arg M K)E ~ K
E[(λx.[ ]) M] ~ (bind x M K)E[(λx.[ ]) M] ~ (bind x M K)E[(λx.[ ]) M] ~ (bind x M K)E[(λx.[ ]) M] ~ (bind x M K)E ~ K
E[(λx.E'[x]) [ ]] ~ (op x K' K)K' ~ E', K ~ E
27
![Page 28: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/28.jpg)
Evaluation Contexts (E) vs Continuations (K)
[ ] ~ mt
E[[ ] M] ~ (arg M K)E ~ K
E[(λx.[ ]) M] ~ (bind x M K)E ~ K
E[(λx.E'[x]) [ ]] ~ (op x K' K)E[(λx.E'[x]) [ ]] ~ (op x K' K)E[(λx.E'[x]) [ ]] ~ (op x K' K)E[(λx.E'[x]) [ ]] ~ (op x K' K)K' ~ E', K ~ E
28
![Page 29: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/29.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
29
![Page 30: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/30.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
30
![Page 31: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/31.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5KKKK = mt
31
![Page 32: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/32.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4)KKKK = (arg M5) mt
32
![Page 33: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/33.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λy.(λz.(y M)) M0 M1 M2) M3 M4KKKK = (bind x M5) mt
33
![Page 34: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/34.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λy.(λz.(y M)) M0 M1 M2) M3KKKK = (arg M4) (bind x M5) mt
34
![Page 35: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/35.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λy.(λz.(y M)) M0 M1 M2)KKKK = (arg M3) (arg M4) (bind x M5) mt
35
![Page 36: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/36.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λz.(y M)) M0 M1 M2KKKK = (bind y M3) (arg M4) (bind x M5) mt
36
![Page 37: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/37.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λz.(y M)) M0 M1KKKK = (arg M2) (bind y M3) (arg M4) (bind x M5) mt
37
![Page 38: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/38.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λz.(y M)) M0KKKK = (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
38
![Page 39: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/39.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (λz.(y M))KKKK = (arg M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
39
![Page 40: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/40.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = (y M)KKKK = (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
40
![Page 41: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/41.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
41
![Page 42: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/42.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M)(arg M)(arg M)(arg M) (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
42
![Page 43: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/43.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0)(bind z M0)(bind z M0)(bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
43
![Page 44: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/44.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1)(arg M1)(arg M1)(arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
44
![Page 45: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/45.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2)(arg M2)(arg M2)(arg M2) (bind y M3) (arg M4) (bind x M5) mt
45
![Page 46: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/46.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5) mt
46
![Page 47: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/47.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5) mt
47
![Page 48: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/48.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5) mt
48
![Page 49: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/49.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5) mt
49
![Page 50: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/50.jpg)
Example (Garcia Machine)
(λx.(λy.(λz.(y M)) M0 M1 M2) M3 M4) M5
CCCC = yKKKK = (arg M) (bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5) mt
• Linear search to find argument
50
![Page 51: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/51.jpg)
CK+ Machine: Stack Structure
• Reorganize stack to be stack of stacks
bind continuations on top
51
![Page 52: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/52.jpg)
CK+ Machine: Stack Structure
• Reorganize stack to be stack of stacks
bind continuations on top
(arg M) (bind z M0) (arg M1) (arg M2) (bind y M3) (arg M4) (bind x M5) mt
52
![Page 53: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/53.jpg)
CK+ Machine: Stack Structure
• Reorganize stack to be stack of stacks
bind continuations on top
(arg M) (bind z M0)(bind z M0)(bind z M0)(bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5)(bind x M5)(bind x M5)(bind x M5) mt
53
![Page 54: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/54.jpg)
CK+ Machine: Stack Structure
• Reorganize stack to be stack of stacks
bind continuations on top
(arg M) (bind z M0)(bind z M0)(bind z M0)(bind z M0) (arg M1) (arg M2) (bind y M3)(bind y M3)(bind y M3)(bind y M3) (arg M4) (bind x M5)(bind x M5)(bind x M5)(bind x M5) mt
(arg M)
mt
(bind M0)(bind M0)(bind M0)(bind M0)
(arg M1)
(arg M2)
mt
(bind M3)(bind M3)(bind M3)(bind M3)
(arg M4)
mt
(bind M5)(bind M5)(bind M5)(bind M5)
mt
54
![Page 55: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/55.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
55
![Page 56: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/56.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.M
56
![Page 57: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/57.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
57
![Page 58: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/58.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
K = mt | (arg M K) | (bind x M K) | (op x K K)
58
![Page 59: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/59.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
K = mt | (arg M K) | (bind x M K) | (op x K K)K = mt | (arg M K) | (bind M K) | (op K K)
59
![Page 60: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/60.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
K = mt | (arg M K) | (bind x M K) | (op x K K)K = mt | (arg M K) | (bind M K) | (op K K)
λx.(x λy.(x y))
60
![Page 61: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/61.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
K = mt | (arg M K) | (bind x M K) | (op x K K)K = mt | (arg M K) | (bind M K) | (op K K)
λx.(x λy.(x y))λ.(0 λ.(1 0))
61
![Page 62: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/62.jpg)
CK+ Machine: Lexical Addresses
• Replace variables with lexical addresses
[De Bruijn 1972]
M = x | M M | λx.MM = n | M M | λ.M
K = mt | (arg M K) | (bind x M K) | (op x K K)K = mt | (arg M K) | (bind M K) | (op K K)
λx.(x λy.(x y))λ.(0 λ.(1 0))
62
![Page 63: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/63.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
63
![Page 64: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/64.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
64
![Page 65: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/65.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5KKKK = mt
65
![Page 66: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/66.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4)KKKK = (arg M5)
mt
66
![Page 67: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/67.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(λ.(1 M)) M0 M1 M2) M3 M4KKKK = mt (bind M5)
mt
67
![Page 68: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/68.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(λ.(1 M)) M0 M1 M2) M3KKKK = (arg M4)
mt
(bind M5)
mt
68
![Page 69: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/69.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(λ.(1 M)) M0 M1 M2)KKKK = (arg M3)
(arg M4)
mt
(bind M5)
mt
69
![Page 70: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/70.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(1 M)) M0 M1 M2KKKK = mt (bind M3)
(arg M4)
mt
(bind M5)
mt
70
![Page 71: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/71.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(1 M)) M0 M1KKKK = (arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
71
![Page 72: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/72.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(1 M)) M0KKKK = (arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
72
![Page 73: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/73.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (λ.(1 M))KKKK = (arg M0)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
73
![Page 74: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/74.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = (1 M)KKKK = mt (bind M0)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
74
![Page 75: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/75.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = 1KKKK = (arg M)
mt
(bind M0)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
75
![Page 76: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/76.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = 1KKKK = (arg M)
mt
(bind M0)
(arg M1)
(arg M2)
mt0
(bind M3)
(arg M4)
mt1
(bind M5)
mt2
76
![Page 77: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/77.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = 1KKKK = (arg M)
mt
(bind M0)
(arg M1)
(arg M2)
mt0
(bind M3)
(arg M4)
mt1
(bind M5)
mt2
77
![Page 78: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/78.jpg)
CK+ Machine: Example
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5
CCCC = 1KKKK = (arg M)
mt
(bind M0)
(arg M1)
(arg M2)
mt0
(bind M3)
(arg M4)
mt1
(bind M5)
mt2
• Direct index instead of search
78
![Page 79: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/79.jpg)
Stack Compaction
79
![Page 80: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/80.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
80
![Page 81: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/81.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
81
![Page 82: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/82.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
mt
(bind M0)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
82
![Page 83: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/83.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
mt
(bind M0)(bind M0)(bind M0)(bind M0)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
83
![Page 84: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/84.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)
mt
84
![Page 85: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/85.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
(arg M1)
(arg M2)
mt
(bind M3)(bind M3)(bind M3)(bind M3)
(arg M4)
mt
(bind M5)
mt
85
![Page 86: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/86.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
(bind M5)(bind M5)(bind M5)(bind M5)
mt
86
![Page 87: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/87.jpg)
Stack Compaction
((λx.M) N) Mwhere x ∉ FV(M)
(λ.(λ.(λ.(1 M)) M0 M1 M2) M3 M4) M5where
No variables reference M0 or M5
CCCC = 1
KKKK = (arg M)
(arg M1)
(arg M2)
mt
(bind M3)
(arg M4)
mt
87
![Page 88: Evaluating Call-by-need on the Control Stack · Evaluating Call-by-need on the Control Stack Stephen Chang, David Van Horn, Matthias Felleisen Northeastern University 1. Lazy Abstract](https://reader033.vdocument.in/reader033/viewer/2022041915/5e69503e10056566d704c702/html5/thumbnails/88.jpg)
Thanks!
88