Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
#lang racket
(define hangul-data-file "src/racket-unihan/Unihan_Readings.txt")
(define-values (_ r) (call-with-input-file hangul-data-file
(lambda (in)
(for/lists (lines) ([l (in-lines in)]
#:unless (eq? '#\# (string-ref l 0))
#:break (= (length lines) 30))
l))))
(module+ test
(require rackunit check-sexp-equal)
(define (ts type tok)
(token-struct type tok #f #f #f #f #f))
(define (pt val from to)
(position-token val (position from #f #f) (position to #f #f)))
(define (drain-lexer input)
(define ip (open-input-string input))
(module+ test
(require rackunit)
(let ([ip (open-input-string "2 + 3")])
(define (ts type tok)
(token-struct type tok #f #f #f #f #f))
(define (pt val from to)
(position-token val (position from #f #f) (position to #f #f)))
(define (check-lex1 type tok a b)
@samth
samth / core.cljs
Last active December 23, 2015 13:59 — forked from swannodette/core.cljs
breaking parametricity
(ns typed-play.core
(:require-macros [cljs.core.typed :as t])
(:require [cljs.core.typed :as t]))
(t/ann my-identity (All [x] (Fn [x -> x])))
(defn my-identity [x]
(if (number? x)
(do (prn x) x)
x))
#lang typed/racket
(: fir-filter ((Listof (List Nonnegative-Fixnum Real)) -> Any))
(define (fir-filter params)
(match params
[`((,#{delays : (List Nonnegative-Fixnum)} ,amplitudes) ...)
(+ 1 (apply max delays))]
[other (error 'ouch)]))
@samth
samth / dave.js
Last active December 16, 2015 17:59 — forked from dherman/dave.js
export default f(1, 2, 3); // anonymous export
export let foo = 5; // named declaration export
export foo // named export of existing identifier
export foo, bar; // named export of multiple existing identifiers
export foo as f; // named aliasing export
export foo as f, bar; // you get the idea
import default glob from "glob"; // anonymous import
import sync from "glob"; // named import
import sync as s from "glob"; // named aliasing import
// A.js
import y from "B";
console.log("a");
export var x;
// B.js
import z from "C";
console.log("b");
export var y;
@samth
samth / ideagen.rkt
Last active December 14, 2015 02:49 — forked from jorendorff/ideagen.py
Talk ideas in Racket
#lang at-exp racket
;; Generate lovely ideas for talks
;; Ported from Jason Orendorff's python code:
;; https://gist.github.com/jorendorff/4659406
(require math)
(define productions
#hash(["tech" . ("HTML5"
#lang racket
(define (find-duplicates elts)
(define ht (make-hash))
(for/list ([x elts]
#:when (hash-update! ht x add1 0)
#:when (= 2 (hash-ref ht x)))
x))
(find-duplicates '(1 2 2 3 1 4 5 4 4 4))
@samth
samth / test
Created December 3, 2012 22:21 — forked from takikawa/test
. Type Checker: untyped identifier apply-contract imported from module <private/base.rkt> in: #%module-begin
. Type Checker: untyped identifier coerce-contract imported from module <private/guts.rkt> in: #%module-begin
. Type Checker: untyped identifier flat-named-contract imported from module <racket/contract> in: #%module-begin
. Type Checker: untyped identifier build-source-location imported from module <syntax/srcloc> in: #%module-begin
. Type Checker: Summary: 4 errors encountered in:
#%module-begin
#%module-begin
#%module-begin
#%module-begin