1 / 13

Understanding Heaps in Scheme: Managing Procedure Call States

In Scheme, while procedure calls are typically managed using a stack, heaps provide a powerful alternative for saving procedure states. This allows for more flexible memory management, particularly in recursive function calls and complex data structures. This guide explores the mechanics of heaps in Scheme, detailing how they can be utilized to store procedure states effectively and enhance the control flow of programs. Understanding heaps opens up new possibilities for optimizing performance and functionality in Scheme programming.

jessie
Télécharger la présentation

Understanding Heaps in Scheme: Managing Procedure Call States

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Heaps in Scheme

  2. Heaps in Scheme Normally, procedure calls are saved on a stack

  3. Heaps in Scheme Normally, procedure calls are saved on a stack f (n) { int x = 1; g(x); f:x=1

  4. 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

  5. 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

  6. 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

  7. 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); }

  8. Heaps in Scheme But in Scheme a heap is used to save proc state

  9. Heaps in Scheme But in Scheme a heap is used to save proc state (f 1 (g f:1

  10. 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

  11. 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

  12. 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

  13. 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

More Related