Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created May 3, 2013 20:20
Show Gist options
  • Save dyoo/5513685 to your computer and use it in GitHub Desktop.
Save dyoo/5513685 to your computer and use it in GitHub Desktop.
An example of the synchronous channels in Racket
#lang racket
;; A translation of http://tour.golang.org/#63 in Racket
(define (sum elts c)
(channel-put c (for/sum ([e elts]) e)))
(define (main)
(define a (list 7 2 8 -9 4 0))
(define c (make-channel))
(thread (lambda () (sum (take a (quotient (length a) 2)) c)))
(thread (lambda () (sum (drop a (quotient (length a) 2)) c)))
(define-values (x y) (values (channel-get c) (channel-get c)))
(displayln x)
(displayln y)
(displayln (+ x y)))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment