Skip to content

Instantly share code, notes, and snippets.

@takikawa
takikawa / gist:5050164
Created February 27, 2013 18:16
A hack to make struct access more terse
#lang racket
(require (for-syntax syntax/parse racket/syntax))
(define-values (prop:indexable indexable? indexable-accessor)
(make-struct-type-property 'indexable))
(define-syntax (% stx)
(syntax-parse stx
[(_ thing index)
@takikawa
takikawa / gist:5088103
Last active December 14, 2015 12:39
Drawing from SVG into a Racket bitmap% object
#lang racket
;; Run in DrRacket to see the SVG logo
(require ffi/unsafe
ffi/unsafe/define
racket/draw
racket/draw/unsafe/cairo)
;; you'll probably need to adjust this line a bit
@takikawa
takikawa / gist:5112262
Created March 7, 2013 22:04
Mutating the type?
$ racket -I typed/racket
Welcome to Racket v5.3.3.7.
-> (: g (All (a ...) (a ... a -> Void)))
-> (define (g . rst) (void))
-> g
- : (All (a ...) (a ... a -> Void))
#<procedure:g>
-> (: h (All (b ...) (b ... b -> Void)))
-> (define h g)
-> g
@takikawa
takikawa / gist:5136708
Created March 11, 2013 18:58
More TR thread & contract issues
#lang racket
(module a racket
(define f (λ () (displayln ((thread-receive) 'foo))))
(provide f))
(module b typed/racket
(require/typed (submod ".." a)
[f (-> Void)])
(define t (thread f))
#lang racket/gui
(define (iterations a z i)
(define z′ (+ (* z z) a))
(if (or (= i 255) (> (magnitude z′) 2))
i
(iterations a z′ (add1 i))))
(define (iter->color i)
(if (= i 255)
(;; random ID
0 187
;; QR Opcode AA TC RD RA Z RCODE
;; 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
129 128
;; QDCOUNT
0 1
;; ANSCOUNT
0 1
;; NSCOUNT
#lang racket
(define-syntax (go stx)
(local-expand #'(begin (define x 3)
x)
'top-level
null))
(go)
#lang r6rs
(library (irregex)
(export irregex string->irregex sre->irregex string->sre
maybe-string->sre irregex? irregex-match-data?
irregex-new-matches irregex-reset-matches! irregex-search
irregex-search/matches irregex-match
irregex-search/chunked irregex-match/chunked
make-irregex-chunker irregex-match-substring
irregex-match-subchunk ;irregex-match-start-source
#lang rackjure
(~> (list 1 2 3)
((lambda (xs) (map add1 xs)))
((curry map add1))
displayln)
#lang typed/racket
;; from Wikipedia
(struct: (A B) :<: ([left : A] [right : B])
#:transparent)
(struct: Epsilon ())
(define-type (Nested A)
(U (:<: A (Nested (Listof A))) Epsilon))