Skip to content

Instantly share code, notes, and snippets.

View deeglaze's full-sized avatar

Dionna Amalie Glaze deeglaze

View GitHub Profile
@deeglaze
deeglaze / annulus.rkt
Created September 20, 2013 20:05
A library-grade annulus drawing function.
#lang racket
(require racket/draw pict)
(define (nonneg-real? x) (and (real? x) (>= x 0)))
(define style/c
(one-of/c 'transparent 'solid 'xor 'hilite
'dot 'long-dash 'short-dash 'dot-dash
'xor-dot 'xor-long-dash 'xor-short-dash
'xor-dot-dash))
(define (within-width-and-height w h)
(make-contract #:name (format "within width and height ~a ~a" w h)
@deeglaze
deeglaze / bug-but-not.rkt
Created September 2, 2013 23:48
A small presentation of the generics scoping weirdness, but doesn't exhibit the bug.
#lang racket/load
(module A racket
(provide gen:foo (rename-out [*a a]))
(define *a #t)
(define a #f)
(define-syntax gen:foo (list #'a)))
(module B racket
(require 'A) (provide ga)
(define-syntax (bar stx)
@deeglaze
deeglaze / exercise7.rkt
Created May 16, 2013 19:41
Do the scientific 7 minute workout... with Racket!
#lang racket
(provide main)
(require (planet clements/rsound) 2htdp/universe 2htdp/image)
;; Helpful app to implement the exercise plan in
;; http://well.blogs.nytimes.com/2013/05/09/the-scientific-7-minute-workout/
(define exercises '("Jumping jacks"
"Wall sit"
"Push ups"
@deeglaze
deeglaze / toy-wide.rkt
Last active December 16, 2015 22:08
Widened version of buggy PDCFA
#lang racket
(require redex)
(define-language L
[e x (e e) lam (let ([x e]) e)]
[lam (λf (x) e)]
[λf λ lambda]
[x variable-not-otherwise-mentioned]
;; Machine
[ρ (side-condition (name ρ any) (hash? (term ρ)))]
@deeglaze
deeglaze / toyPDCFA.rkt
Created May 2, 2013 17:59
Simple but buggy PDCFA
#lang racket
(require redex)
(define-language L
[e x (e e) lam (let ([x e]) e)]
[lam (λf (x) e)]
[λf λ lambda]
[x variable-not-otherwise-mentioned]
;; Machine
[ρ (side-condition (name ρ any) (hash? (term ρ)))]
@deeglaze
deeglaze / count-bits.rkt
Created November 27, 2012 14:55
Count 1s in fixnums
#lang racket
(require racket/unsafe/ops
(for-syntax racket/fixnum racket/vector))
(provide fxcount)
;; Count set bits for 30 bit number in 5 steps.
;; for 62 bit number in 6.
(define-for-syntax lut
#(#x2AAAAAAA
#x0CCCCCCC
@deeglaze
deeglaze / raco-doc.el
Created October 24, 2012 15:54
Hotkeys for quick racket documentation lookup. Requires paredit.
(setq raco-location "raco")
(require 'paredit)
(setq raco-doc-history nil)
(defun call-raco-doc (text)
(shell-command (concat raco-location " doc -- '" text "' &")))
(defun get-current-word ()
(paredit-handle-sexp-errors
(save-excursion
@deeglaze
deeglaze / betterdsr.rkt
Created October 15, 2012 16:32
A better define-syntax-rule
(require (for-syntax syntax/parse))
; syntax classes, syntax-parse patterns and unquote-syntax in your define-syntax-rule!
(define-syntax (define-syntax-rule* stx)
(syntax-parse stx
[(_ (name patterns ...) body ...)
(syntax/loc stx
(define-syntax (name syn)
(syntax-parse syn
[(_ patterns ...)
(quasisyntax/loc syn (begin body ...))])))]))
@deeglaze
deeglaze / compare.rkt
Created October 4, 2012 22:51
Performance discrepancies with macro generalization
#lang racket/load
(module tweaks racket
(require (for-syntax syntax/parse))
(provide <- for/union for*/union for*/set
appl fix do join extend get-cont lookup-env lookup P parse
compile widen push
join-stores s->c c->s
(struct-out ev^)
(struct-out co^)
@deeglaze
deeglaze / compile-0cfa.rkt
Created October 4, 2012 17:24 — forked from dvanhorn/compile-0cfa.rkt
Compilation for 0CFA with lazy dereferencing
#lang racket
(require racket/trace
(for-syntax syntax/parse))
;; 0CFA in the AAM style on some hairy Church numeral churning
;; Soundness, but at what cost?
(define <- (case-lambda))
(begin-for-syntax