Skip to content

Instantly share code, notes, and snippets.

@florence
florence / silly.rkt
Created February 14, 2014 06:13
logic is silly
#lang racket
(require redex)
(current-cache-all? #t)
(define-language L
(e x t f (e ∧ e) (e ∨ e) (¬ e) (e → e))
(x variable-not-otherwise-mentioned))
(define-extended-language LC L
#lang at-exp slideshow
(require slideshow/code racket/draw)
(define (red t)
(color "darkmagenta" t))
(define (green t)
(color "olive" t))
(define (blue t)
(color "royalblue" t))
(define (color c t)
#lang racket
(define ns (make-base-namespace))
(namespace-attach-module (current-namespace) ''#%builtin ns)
(define args (contract (vectorof string?) (vector "a") 'pos 'neg))
(parameterize ([current-namespace ns])
(define current-args
(namespace-variable-value 'current-command-line-arguments ns))
(parameterize ([current-args args])
#lang typed/racket
(require pict3d)
(: aprox-mandel : (Natural -> (Dir -> Dir)))
(define ((aprox-mandel n) c)
(define Z (mandel c))
(let loop : Dir ([n : Natural n] [z_n : Dir zero-dir])
(if (zero? n)
(Z z_n)
(define-expander-type ppict-ext)
(begin-for-syntax
(define-syntax-class ppict-body
#:datum-literals (splice)
#:attributes ((flatten 1))
(pattern (splice a:ppict-body ...)
#:attr (flatten 1)
(syntax->list #'(a.flatten ... ...)))
(pattern a
@florence
florence / soumyeahdood.rkt
Last active December 24, 2015 01:29
The parse function takes in a string. space, tabs, and newlines are ignored.
#lang racket
(require parser-tools/lex
(prefix-in : parser-tools/lex-sre))
(define-lex-trans ::?
(lambda (stx)
(syntax-case stx ()
[(_ v b)
#'(:: v (:? " ") b)])))
#lang racket
(require redex)
(define-language SKI
(e ::= S K I (e e) natural +))
(define R
(reduction-relation
SKI
(--> (((S e_1) e_2) e_3)
((e_1 e_3) (e_2 e_3)))
(--> ((K e_1) e_2) e_1)
@florence
florence / image-enum.rkt
Last active December 5, 2016 04:01
An enumeration of all bitmaps
#lang racket
(require data/enumerate)
(require data/enumerate/lib)
(require racket/draw)
(require pict)
;; adjust byte size to shrink the range of colors
(define byte-size 256)
(define byte/e (below/e byte-size))
(define (byte->actual x)
#lang scribble/doc
Okay, we've made a package and up loaded. But you know what would be lovely?.
Docs! This tutorial is going to start assuming you have a blank file and now clue where to start. By
the end we will have written the documentation for this line-of-best-fit library <show>.
This is racket land, so of course we have a language for documentation! #lang scribble/doc
@(require scribble/manual
import java.lang.reflect.*;
import sun.misc.Unsafe;
public class Print {
static Unsafe u = getUnsafe();
public static void main(String... args) {
try {
long addr = u.staticFieldOffset(System.class.getDeclaredField("err")) +4;