Skip to content

Instantly share code, notes, and snippets.

Already under `racket`, but move the implementation:
x mzlib/control => racket/control
x mzlib/date => racket/date
x mzlib/deflate => file/gzip
x mzlib/inflate => file/gunzip
x mzlib/port => racket/port
(more work since racket/port adds on to it)
x mzlib/process => racket/system
x mzlib/runtime-path => racket/runtime-path
(depends on private mzlib module)
@takikawa
takikawa / gist:3092722
Created July 11, 2012 19:36
scheme/unit vs. racket/unit
asumu@willamette:~/plt/racket-git-2$ racket -I racket/base
Welcome to Racket v5.3.0.13.
-> (require scheme/unit)
-> struct
; readline-input:2:0: struct: illegal use of signature form
in: struct [,bt for context]
-> struct/ctc
; readline-input:3:0: struct/ctc: illegal use of signature form
in: struct/ctc [,bt for context]
->
@takikawa
takikawa / gist:3165954
Created July 23, 2012 20:11
module->namespace & submod
#lang racket
(module foo racket
(provide x)
(define x 3))
(module->namespace '(submod "." foo))
@takikawa
takikawa / gist:3180554
Created July 26, 2012 06:21
lift a definition?
#lang racket
(module bar racket
(define-syntax (foo stx)
(syntax-case stx ()
[(_ x)
(begin (syntax-local-lift-module-end-declaration
#'(define/contract x integer? 5))
#'(void))]))
(foo x)
#lang racket
(define pt (make-continuation-prompt-tag))
(+ 5
(call-with-continuation-prompt
(lambda ()
(call-with-continuation-barrier
(lambda ()
(call/ec
@takikawa
takikawa / gist:3228331
Created August 1, 2012 16:18
$ from Okasaki's dissertation
#lang racket
(require (for-syntax syntax/parse))
(define-match-expander $
(λ (stx)
(syntax-parse stx
[(_ pat ...)
#'(app force pat ...)])))
@takikawa
takikawa / gist:3242280
Created August 2, 2012 23:56
call/cc vs. delim control speed
#lang racket
(define pt (make-continuation-prompt-tag))
(define (fact n)
(if (zero? n)
1
(* n (fact (sub1 n)))))
(time
#lang racket
;; splits the list into groups of n or less
;; nat (listof x) -> (listof (listof x))
(define (group n lst)
(let loop ([lst lst] [acc '()])
(if (null? lst)
(reverse acc)
(loop (drop-up-to lst n)
(cons (take-up-to lst n) acc)))))
@takikawa
takikawa / gist:3292447
Created August 8, 2012 05:32
Polymorphic contracts and generics
#lang racket
;; generics with parametric contracts
(module stack racket
(require racket/generic)
;; The following defines:
;; * gen:stack
;; * stack?