Created
April 12, 2012 23:08
-
-
Save keenbug/2371678 to your computer and use it in GitHub Desktop.
simple (ice-9 occam-channel) echo example in guile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-module (channels) | |
#:use-module (ice-9 occam-channel) | |
#:export (start-echo)) | |
;;; use like this: | |
;;; > (define c (start-echo)) | |
;;; > (! c 'test) | |
;;; > (? c) | |
;;; $1 = (echo test) | |
;;; > (! c '(some more "input data")) | |
;;; > (? c) | |
;;; $2 = (echo (some more "input data")) | |
(define (start-echo) | |
(let ((chan (make-channel))) | |
(call-with-new-thread | |
(lambda () | |
(let loop () | |
(let ((in (? chan))) | |
(case in | |
((quit) #f) | |
(else | |
(! chan (list 'echo in)) | |
(loop))))))) | |
chan)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment