From: Christopher Allan Webber Date: Fri, 20 Nov 2015 16:43:26 +0000 (-0600) Subject: better variable names for the run procedures X-Git-Tag: v0.1.0~134 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=140ab5bad794069833dc046a4a988cc6e6c22d1a;p=8sync.git better variable names for the run procedures --- diff --git a/loopy.scm b/loopy.scm index c78197a..7b43ba6 100644 --- a/loopy.scm +++ b/loopy.scm @@ -37,7 +37,7 @@ make-run-request run-request? run-request-proc run-request-when - run wrap run-wrap run-wrap-at + run-it wrap run run-at delay %current-agenda start-agenda agenda-run-once)) @@ -319,24 +319,37 @@ Will produce (0 . 0) instead of a negative number, if needed." ;;; Request to run stuff ;;; ==================== -(define-record-type +(define-immutable-record-type (make-run-request proc when) run-request? (proc run-request-proc) (when run-request-when)) -(define* (run proc #:optional when) +(define* (run-it proc #:optional when) + "Make a request to run PROC (possibly at WHEN)" (make-run-request proc when)) (define-syntax-rule (wrap body ...) + "Wrap contents in a procedure" (lambda () body ...)) -(define-syntax-rule (run-wrap body ...) - (run (wrap body ...))) +(define-syntax-rule (run body ...) + "Run everything in BODY but wrap in a convenient procedure" + (make-run-request (wrap body ...) #f)) -(define-syntax-rule (run-wrap-at body ... when) - (run (wrap body ...) when)) +(define-syntax-rule (run-at body ... when) + "Run BODY at WHEN" + (make-run-request (wrap body ...) when)) + +(define-syntax-rule (run-delay body ... delay-time) + (make-run-request (wrap body ...) (tdelta delay-time))) + +(define (delay run-request delay-time) + "Delay a RUN-REQUEST by DELAY-TIME" + (set-field run-request + (run-request-when) + (tdelta delay-time))) ;;; Execution of agenda, and current agenda diff --git a/tests.scm b/tests.scm index 0843fb4..0853876 100644 --- a/tests.scm +++ b/tests.scm @@ -175,25 +175,25 @@ (test-assert (procedure? wrapped)) (test-equal (wrapped) 3)) -(let ((run-two-squared (run (lambda () (* 2 2))))) +(let ((run-two-squared (run-it (lambda () (* 2 2))))) (test-assert (run-request? run-two-squared)) (test-assert (procedure? (run-request-proc run-two-squared))) (test-equal ((run-request-proc run-two-squared)) 4) (test-eq (run-request-when run-two-squared) #f)) -(let ((run-two-squared (run (lambda () (* 2 2)) '(88 . 0)))) +(let ((run-two-squared (run-it (lambda () (* 2 2)) '(88 . 0)))) (test-assert (run-request? run-two-squared)) (test-assert (procedure? (run-request-proc run-two-squared))) (test-equal ((run-request-proc run-two-squared)) 4) (test-equal (run-request-when run-two-squared) '(88 . 0))) -(let ((run-two-squared (run-wrap (* 2 2)))) +(let ((run-two-squared (run (* 2 2)))) (test-assert (run-request? run-two-squared)) (test-assert (procedure? (run-request-proc run-two-squared))) (test-equal ((run-request-proc run-two-squared)) 4) (test-eq (run-request-when run-two-squared) #f)) -(let ((run-two-squared (run-wrap-at (* 2 2) '(88 . 0)))) +(let ((run-two-squared (run-at (* 2 2) '(88 . 0)))) (test-assert (run-request? run-two-squared)) (test-assert (procedure? (run-request-proc run-two-squared))) (test-equal ((run-request-proc run-two-squared)) 4) @@ -226,7 +226,7 @@ (define (run-dummy) (speaker "I bet I can make you say you're a dummy!\n") - (run dummy-func)) + (run-it dummy-func)) (let ((q (make-q))) (set! speaker (speak-it)) ; reset the speaker