Skip to content

Instantly share code, notes, and snippets.

View carl-eastlund's full-sized avatar

Carl Eastlund carl-eastlund

  • Northeastern University (alumnus)
  • New York, NY
View GitHub Profile
@carl-eastlund
carl-eastlund / complex-dsl.rkt
Created January 26, 2014 23:33
DSL expansion with variable splicing
#lang racket
(require (for-syntax racket syntax/parse racket/syntax syntax/id-table))
(begin-for-syntax
(define macro-table (make-free-id-table))
(define (expand-macro id stx)
(define transformer (syntax-local-value id))
@carl-eastlund
carl-eastlund / simple-dsl.rkt
Created January 26, 2014 01:47
Simple DSL expansion
#lang racket
(require (for-syntax racket syntax/parse racket/syntax syntax/id-table))
(begin-for-syntax
(define macro-table (make-free-id-table))
(define (expand-macro id stx)
(define transformer (syntax-local-value id))
@carl-eastlund
carl-eastlund / mras.rkt
Created September 7, 2013 03:53
Second half of Racket bug 14004
#lang at-exp racket
; For in source documentation:
(require racket/contract
scribble/srcdoc
(for-doc racket/base
scribble/manual))
(require rackunit)
(require plot)
@carl-eastlund
carl-eastlund / diff-e solver.rkt
Created September 7, 2013 03:53
First half of Racket bug 14004
#reader(lib"read.ss""wxme")WXME0108 ##
#|
This file uses the GRacket editor format.
Open this file in DrRacket version 5.3.1 or later to read it.
Most likely, it was created by saving a program in DrRacket,
and it probably contains a program with non-text elements
(such as images or comment boxes).
http://racket-lang.org/
@carl-eastlund
carl-eastlund / hash-potential-bug.rkt
Created September 2, 2013 20:12
Attempting to reproduce a hash-iterate-key bug using hash tables directly rather than sets.
#lang racket
(require math/number-theory)
(define limit 28123)
(define (is-abundant? n)
(> (- (apply + (divisors n)) n) n))
(define abundants
trait Trait {
fn method( &self );
}
struct Simple;
impl Trait for Simple {
@carl-eastlund
carl-eastlund / iter.rs
Created August 19, 2013 23:19
map over iterator
fn imap<A,B>( i : ~Iterator<A>, f : &fn(A)->B ) { i.map(f) }
fn main () {}
/*
iter.rs:1:50: 1:60 error: type `~std::iterator::Iterator<A>:Send` does not implement any method in scope named `map`
iter.rs:1 fn imap<A,B>( i : ~Iterator<A>, f : &fn(A)->B ) { i.map(f) }
^~~~~~~~~~
error: aborting due to previous error
*/
@carl-eastlund
carl-eastlund / clone.rs
Created August 19, 2013 05:16
derived cloning, expanded
priv use std::prelude::*;
priv extern mod std;
/* This version works: */
// Box{ unbox : b.unbox.clone() }
/* This version doesn't: */
@carl-eastlund
carl-eastlund / clone.rs
Last active December 21, 2015 06:39
derived cloning
fn main (){}
#[deriving(Clone)]
struct Box<T>{unbox:@T}
fn op<T>( b : Box<T> ) -> Box<T> {
/* This version works: */
// Box{ unbox : b.unbox.clone() }
@carl-eastlund
carl-eastlund / impl.rs
Last active December 21, 2015 06:38
traits and implementations
trait Thing<T> {
fn ignore(self) -> ();
}
impl<T> Thing<T> for () {
fn ignore(self) -> () { self }
}
fn main () {