example: Use the "call-with-*" procedures to manage resources.
authorDavid Thompson <dthompson2@worcester.edu>
Mon, 14 Dec 2015 17:09:48 +0000 (12:09 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Mon, 14 Dec 2015 17:09:48 +0000 (12:09 -0500)
examples/hello.scm

index 1f98669..d45c804 100644 (file)
              (sdl2 surface)
              (sdl2 video))
 
+(define (draw ren)
+  (let* ((surface (load-bmp "hello.bmp"))
+         (texture (surface->texture ren surface)))
+    (clear-renderer ren)
+    (render-copy ren texture)
+    (present-renderer ren)
+    (sleep 2)))
+
 (sdl-init)
 
-(define window (make-window))
-(define ren (make-renderer window))
-(define surface (load-bmp "hello.bmp"))
-(define texture (surface->texture ren surface))
+(call-with-window (make-window)
+  (lambda (window)
+    (call-with-renderer (make-renderer window) draw)))
 
-(clear-renderer ren)
-(render-copy ren texture)
-(present-renderer ren)
-(sleep 2)
-(close-window! window)
-(delete-renderer! ren)
 (sdl-quit)