Skip to content

Instantly share code, notes, and snippets.

View iitalics's full-sized avatar

Milo iitalics

  • Somerville, MA
View GitHub Profile
@iitalics
iitalics / typing-syntax-classes.rkt
Created April 3, 2017 15:11
General syntax classes for types (base type, type constructor, binding type)
(define-syntax-class base-type
#:attributes (name internal-name)
(pattern ((~literal #%plain-app) internal-name:id)
#:with (_ ... name) (syntax-property this-syntax 'orig)))
(define-syntax-class ctor-type
#:attributes (name internal-name [arg 1])
(pattern ((~literal #%plain-app) internal-name:id
((~literal #%plain-lambda) ()
((~literal #%expression) . _)
arg ...))
@iitalics
iitalics / labeled-functions.rkt
Last active May 22, 2017 22:29
Issue with current implementation of make-variable-like-transformer
#lang racket
(require (for-syntax syntax/parse
syntax/transformer))
(provide #%module-begin
#%top-interaction
#%datum
(rename-out [my-app #%app]
[my-+ +]
[my-expr #%expression]))
#lang turnstile
;; this is a silly language that allows the literal #t to be an Int.
;; you can decide lexically which expressions obey this property using (true=>int <expression>)
;; this is a test that the turnstile syntax works, because I don't yet have a "serious" language
;; to test the behavior with
(provide #%datum #%top-interaction true=>int
(type-out Int Bool))
(define-base-type Int)
(define-base-type Bool)
@iitalics
iitalics / garbage-macro.rkt
Created August 8, 2017 21:01
Generates macro with absurd number of syntax/parse patterns
#lang racket/base
(require (for-syntax racket
racket/syntax
(only-in racket/function curryr)
syntax/parse
syntax/stx))
(provide (all-from-out racket/base))
(begin-for-syntax
; tweak these parameters to change resulting macro size
@iitalics
iitalics / example.rkt
Created August 8, 2017 21:02
Applies macro from "garbage-macro.rkt"
#lang s-exp "garbage-macro.rkt"
(new-let ([s "hello, world"])
(displayln s))
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
void gen_int_test(const char* reader,
void* ptr,
size_t bits,
int64_t expected)
{
@iitalics
iitalics / recursive-pattern.rkt
Last active May 10, 2021 16:17
Recursive pattern expander for Racket
#lang racket
(require (for-syntax syntax/parse)
(for-meta 2 racket syntax/parse syntax/stx racket/syntax))
(begin-for-syntax
(begin-for-syntax
;; attr+arity ::= id
;; | [id arity]
;;
@iitalics
iitalics / pattern-matching-redex.rkt
Created January 6, 2018 22:28
Pattern matching a lazy language with Redex
#lang racket/base
(require redex)
(define-language L
[x ::= variable-not-otherwise-mentioned]
[c ::= number null] ; atoms
[e ::= c (cons e e) x (roll [x] e) (+ e e)] ; expression
[v ::= c (cons e e)] ; WHNF values
[e\v ::= (roll [x] e) (+ e e)] ; non-value expressions (thunks?)
@iitalics
iitalics / glorious-haskill-redex.rkt
Last active January 7, 2018 00:42
More sophisticated lazy language with pattern matching & eval interleaved
#lang racket/base
(require redex)
(define-language Haskill
[x ::= variable-not-otherwise-mentioned]
[ctor ::= cons null A B C #t #f]
; expressions
[e ::=
x
@iitalics
iitalics / queue.rkt
Created August 23, 2018 04:26
Functional Queues ala Okasaki in Racket
#lang racket/base
(provide
queue? ;; any -> boolean
queue ;; any ... -> queue
empty-queue ;; queue
queue-empty? ;; queue -> boolean
queue-count ;; queue -> nonnegative-integer
queue-first ;; queue -> any
queue-rest ;; queue -> queue
queue-add ;; queue any -> queue