130 likes | 249 Views
Heaps in Scheme. Heaps in Scheme. Normally, procedure calls are saved on a stack. Heaps in Scheme. Normally, procedure calls are saved on a stack. f (n) { int x = 1; g(x);. f:x=1. Heaps in Scheme. Normally, procedure calls are saved on a stack. g(n) { int x = 2; h(x);.
E N D
Heaps in Scheme Normally, procedure calls are saved on a stack
Heaps in Scheme Normally, procedure calls are saved on a stack f (n) { int x = 1; g(x); f:x=1
Heaps in Scheme Normally, procedure calls are saved on a stack g(n) { int x = 2; h(x); f (n) { int x = 1; g(x); g:x=2 f:x=1
Heaps in Scheme Normally, procedure calls are saved on a stack g(n) { int x = 2; h(x); h(n) { int x = 3; } f (n) { int x = 1; g(x); g:x=2 f:x=1
Heaps in Scheme Normally, procedure calls are saved on a stack g(n) { int x = 2; h(x); } h(n) { int x = 3; } f (n) { int x = 1; g(x); f:x=1
Heaps in Scheme Normally, procedure calls are saved on a stack g(n) { int x = 2; h(x); } h(n) { int x = 3; } f (n) { int x = 1; g(x); }
Heaps in Scheme But in Scheme a heap is used to save proc state
Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g f:1
Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g 2 (h (set! c (call/cc (lambda (k) k)) c g:2 f:1
Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g 2 (h (set! c (call/cc (lambda (k) k))) c g:2 f:1
Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g 2 (h (set! c (call/cc (lambda (k) k))))) (g 3 (h ... c g:3 g:2 f:1
Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g 2 (h (set! c (call/cc (lambda (k) k))))) (g 3 (h ... c To return to a previous point in time: (c 4) Has the effect of returning from the set! with value 4 g:3 g:2 f:1