Skip to content

Instantly share code, notes, and snippets.

@keenbug
Created April 12, 2012 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keenbug/2371678 to your computer and use it in GitHub Desktop.
Save keenbug/2371678 to your computer and use it in GitHub Desktop.
simple (ice-9 occam-channel) echo example in guile
(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