]> git.jsancho.org Git - gacela.git/blobdiff - src/utils.scm
Meshes located at video module and new game loop procedure returning game elements
[gacela.git] / src / utils.scm
index 33b245ff153c300affe7f2819d5968a9135a690f..ed09712d9a990531d9e9daecdc81e1131596aed1 100644 (file)
 (define-module (gacela utils)
   #:export (use-cache-with
            arguments-calling
-           arguments-apply))
+           arguments-apply
+           bound?
+           names-arguments
+           make-producer))
 
 
 ;;; Cache for procedures
            (optional-arguments-apply args values)
            (keyword-arguments-apply args values)
            (rest-arguments-apply args values))))
+
+(define (names-arguments args)
+  (map (lambda (x) (if (list? x) (car x) x))
+       (filter (lambda (x) (not (keyword? x)))
+              (pair-to-list args))))
+
+
+;;; Continuations and coroutines
+
+(define (make-producer body)
+  (define resume #f)
+  (lambda (real-send)
+    (define send-to real-send)
+    (define (send value-to-send)
+      (set! send-to
+           (call/cc
+            (lambda (k)
+              (set! resume k)
+              (send-to value-to-send)))))
+    (if resume
+        (resume real-send)
+        (body send))))
+
+
+;;; Miscellaneous
+
+(define (pair-to-list pair)
+  (cond ((null? pair) '())
+       ((not (pair? pair)) (list pair))
+       (else (cons (car pair) (pair-to-list (cdr pair))))))