Skip to content

Instantly share code, notes, and snippets.

@takikawa
takikawa / gist:3343507
Created August 13, 2012 19:35
Tail recursion & delim. control
#lang racket
(define (tailtest)
(let ([p (make-continuation-prompt-tag)])
(call-with-continuation-prompt
(λ ()
(call-with-composable-continuation
(λ (k)
(abort-current-continuation p (λ () (tailtest))))
p))
@takikawa
takikawa / gist:3343874
Created August 13, 2012 20:26
Tail recursion in the FYFF model
#lang racket
(require redex
redex/examples/delim-cont/grammar
redex/examples/delim-cont/meta
redex/examples/delim-cont/reduce)
;; nullary Z combinator
(define Z
(term (λ (f)
@takikawa
takikawa / gist:3422588
Created August 22, 2012 05:44
Persistent union-find
#lang racket
;; Persistent union-find from http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.79.8494
(define-signature persistent-array^
(init get set))
(define-signature union-find^
(create find union))
@takikawa
takikawa / gist:3429858
Created August 22, 2012 22:06
Profiling results
$ racket nqueens-racket-stream.rkt
Profiling results
-----------------
Total cpu time observed: 5292ms (out of 5412ms)
Number of samples taken: 95 (once every 56ms)
============================================================
Caller
Idx Total Self Name+src Local%
ms(pct) ms(pct) Callee
@takikawa
takikawa / gist:3549450
Created August 31, 2012 05:45
Continuation barriers?
#lang racket
(define f
(call-with-continuation-prompt
(lambda ()
(call/cc (lambda (k) k)))))
(call-with-continuation-prompt
(lambda ()
(call-with-continuation-barrier
@takikawa
takikawa / gist:3616831
Created September 4, 2012 05:13
Dynamic wind & call/cc
#lang racket
(define k1 #f)
(define k2 #f)
(call-with-continuation-prompt
(lambda ()
;; this dw will only run twice and not three for
;; the initial run, k1, and then k2
(dynamic-wind
@takikawa
takikawa / gist:3626051
Created September 4, 2012 20:25
thread default abort handler
#lang racket
(thread
(lambda ()
(displayln "hi")
(dynamic-wind
void
(lambda ()
(abort-current-continuation
(default-continuation-prompt-tag) 5))
@takikawa
takikawa / gist:3723651
Created September 14, 2012 18:13
define/match
#lang racket
;; added something like `where` clauses
(require (for-syntax syntax/parse
syntax/parse/experimental/template))
(provide define/match)
(begin-for-syntax
@takikawa
takikawa / gist:3763781
Created September 21, 2012 20:44
wcm nesting
#lang racket
(require redex
redex/examples/delim-cont/reduce
redex/examples/delim-cont/grammar)
(stepper :->
(term (<> () () (% 0
((λ (x)
(wcm ((5 5)) (x)))
@takikawa
takikawa / gist:3812284
Created October 1, 2012 14:56
monads with generics
;; using the idea from this blog post: http://www.clojure.net/2012/06/03/Monad-Protocols/
#lang racket
(require (for-syntax syntax/parse))
(module monad racket
(require racket/generic)
(define (vector-mapcat f v)