Skip to content

Instantly share code, notes, and snippets.

@takikawa
takikawa / gist:3885002
Created October 13, 2012 15:29
Generics example from RacketCon 2012
#lang racket
;; Example code from RacketCon 2012
(require racket/generic)
;; simple set interface
(define-generics set
(set-add elem set)
(set-contains? elem set)
@takikawa
takikawa / gist:3995200
Created November 1, 2012 17:29
Generics blog example
#lang racket
;; Examples from the Racket blog post on generics
(require racket/generic
rackunit
srfi/41)
(provide gen:queue
queue/c
@takikawa
takikawa / gist:4003510
Created November 2, 2012 18:46
Typed prompt & abort
#lang typed/racket
(: pt (Prompt-Tag String (Integer -> Integer)))
(define pt (make-continuation-prompt-tag))
(call-with-continuation-prompt
(λ () (string-append "foo" (abort-current-continuation pt 5)))
pt
(λ: ([x : Integer]) x))
@takikawa
takikawa / the error
Created November 5, 2012 19:36
require/typed from submodule
#lang typed/racket
(module foo racket
(define x 3)
(provide x))
(require/typed (submod "." foo) [x Integer])
#lang typed/racket
;; the generated contract for this is
;;
;; (define-values:102 (generated-contract4:103)
;; (#%app:104
;; continuation-mark-key/c/proc:105
;; (#%app:106 flat-named-contract 'Integer exact-integer?)))
;;
;; which looks correct, but it's not getting wrapped on export
@takikawa
takikawa / bench.rkt
Created November 9, 2012 15:52 — forked from greghendershott/bench.rkt
Why is a simple contract so much slower than a check?
#lang racket
(define (f/raw x)
#t)
(define (f/checked x)
(unless (exact-nonnegative-integer? x)
(error 'f/checked "blah blah"))
#t)
@takikawa
takikawa / gist:4070126
Created November 14, 2012 03:42
Kool aid
#lang racket
;; kool-aid.rkt
(require slideshow/pict racket/draw)
(define (kool-aid)
(dc (λ (dc dx dy)
(define old-pen (send dc get-pen))
(define old-brush (send dc get-brush))
@takikawa
takikawa / gist:4090648
Created November 16, 2012 20:32
Coroutines
#lang racket
;; asymmetric full coroutines from "Revisiting Coroutines"
(provide (contract-out
[create (-> procedure? coroutine?)]
[resume (->* (coroutine?) () #:rest (listof any/c) any)]
[yield (-> any/c any)]
[status (-> coroutine? (or/c 'running 'done 'suspended))]))
#lang racket
(require (for-syntax syntax/parse
syntax/parse/experimental/template
racket/syntax
racket/list))
;; A syntax class to recognize function arguments:
(begin-for-syntax
(define-splicing-syntax-class argspec