Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2012 21:01
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 anonymous/4090877 to your computer and use it in GitHub Desktop.
Save anonymous/4090877 to your computer and use it in GitHub Desktop.
#lang racket
(provide daddy-brings-worms
momma-sits)
(module nest racket
(provide eggs chicks lay-egg hatch)
(define eggs 0)
(define chicks 0)
(define (hatch)
(if (> eggs 0)
(begin
(set! eggs (sub1 eggs))
(set! chicks (add1 chicks)))
(void)))
(define (lay-egg)
(set! eggs (add1 eggs))))
(module birds racket
(provide
daddy-brings-worms
momma-sits)
(require
(for-syntax syntax/parse)
(for-meta 1 (submod ".." nest)))
(define-syntax (daddy-brings-worms stx)
(syntax-parse stx
[(_)
(lay-egg)
(with-syntax ((nest-state (cons eggs chicks)))
#''nest-state)]))
(define-syntax (momma-sits stx)
(syntax-parse stx
[(_)
(hatch)
(with-syntax ((nest-state (cons eggs chicks)))
#''nest-state)]))
)
(require (submod "." birds))
(define the-nest
(begin
(daddy-brings-worms)
(momma-sits)
(daddy-brings-worms)))
the-nest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment