From 8dd2abd8d4b1624effc7b41081309775501d7ca9 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Mon, 28 Aug 2017 11:27:54 -0700 Subject: [PATCH] planetarium (make-tellurion): Name thread; return the object(!). --- src/planetarium/tellurion.scm | 61 +++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/planetarium/tellurion.scm b/src/planetarium/tellurion.scm index a8beb442e..2441b9a18 100644 --- a/src/planetarium/tellurion.scm +++ b/src/planetarium/tellurion.scm @@ -22,33 +22,40 @@ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# (define (make-tellurion) - (let ((queue (make-thread-queue))) - (define (queue! command . args) - (thread-queue/queue! queue (cons command args)) - unspecific) - (detach-thread (create-thread #f (lambda () (run-tellurion queue)))) - (lambda (keyword . args) - (cond ((eq? keyword 'TURN-TO) - (let ((lat (->flonum (car args))) - (long (->flonum (cadr args)))) - (if (or (< lat -90) (< 90 lat)) - (error "Invalid latitude:" lat)) - (if (or (< long -180) (< 180 long)) - (error "Invalid longitude:" long)) - (queue! 'turn-to lat long))) - ((eq? keyword 'TIME-TO) - (queue! 'time-to (->time (car args)))) - ((eq? keyword 'HOUR-TO) - (let ((hour (car args))) - (guarantee integer? hour 'hour-to) - (if (or (< hour 0) (< 23 hour)) - (error "Invalid hour:" hour)) - (queue! 'hour-to hour))) - ((eq? keyword 'STOP) - (queue! queue 'stop)) - ((eq? keyword 'GO) - (queue! queue 'go)) - (else (error "unknown command:" keyword args)))))) + + (define queue (make-thread-queue)) + + (define (queue! command . args) + (thread-queue/queue! queue (cons command args)) + unspecific) + + (define (tellurion command . args) + (cond ((eq? command 'TURN-TO) + (let ((lat (->flonum (car args))) + (long (->flonum (cadr args)))) + (if (or (< lat -90) (< 90 lat)) + (error "Invalid latitude:" lat)) + (if (or (< long -180) (< 180 long)) + (error "Invalid longitude:" long)) + (queue! 'turn-to lat long))) + ((eq? command 'TIME-TO) + (queue! 'time-to (->time (car args)))) + ((eq? command 'HOUR-TO) + (let ((hour (car args))) + (guarantee integer? hour 'hour-to) + (if (or (< hour 0) (< 23 hour)) + (error "Invalid hour:" hour)) + (queue! 'hour-to hour))) + ((eq? command 'STOP) + (queue! queue 'stop)) + ((eq? command 'GO) + (queue! queue 'go)) + (else (error "unknown command:" command args)))) + + (detach-thread (create-thread #f + (lambda () (run-tellurion queue)) + tellurion)) + tellurion) (define (->time object) (cond ((eq? object 'current) -- 2.25.1