Skip to content

Instantly share code, notes, and snippets.

View mflatt's full-sized avatar

Matthew Flatt mflatt

View GitHub Profile
#lang racket/base
(define (f a) '())
(define (f0 a b c x) '())
(define (f1 a b c x #:y [y 'y]) '())
(define (f2 a b c x #:y y) '())
(define (identity x) x)
(define-syntax-rule (time-it wrap ...)
#lang racket/base
(provide text-lines?
(rename-out [empty empty-text-lines])
;; 0 is the position before everything, and the position
;; after a newline is on the subsequent line
text-length ; t -> position at end
insert ; t position str -> t, detecting "\n"
@mflatt
mflatt / demo_armored.rkt
Last active November 1, 2021 17:39
Rhombus demo after armor transformation
#lang rhombus
import:«
rhombus/macro:« no_prefix»»;
use_static_dot;
// Some expressions
10 * (-3) + 2;
@mflatt
mflatt / test.rkt
Created July 24, 2021 15:31
Test for import from weaker code inspector
#lang racket
(let ()
(define work-dir (make-temporary-file "deputy-check-~a" 'directory))
(define m '(module m racket/base
(provide m)
(define (m) '(this is m))))
(define n '(module n racket/base
@mflatt
mflatt / fib_fast.msd
Created March 30, 2021 13:33
Fibonacci (the fast way) in MSDscript
_let pair = _fun (a) _fun (b)
_fun(sel)
_if sel _then a _else b
_in _let fst = _fun (p) p(_true)
_in _let snd = _fun (p) p(_false)
_in _let fib = _fun (fib)
_fun (x)
_if x == 0
_then pair(1)(1)
_else _if x == 1
@mflatt
mflatt / fib.msd
Created March 30, 2021 13:31
Fibonacci (the slow way) in MSDscript
_let fib = _fun (fib)
_fun (x)
_if x == 0
_then 1
_else _if x == 1
_then 1
_else fib(fib)(x + -2) + fib(fib)(x + -1)
_in fib(fib)(30)
#lang racket/base
(require ffi/unsafe
racket/class
ffi/unsafe/alloc
ffi/unsafe/try-atomic
ffi/unsafe/schedule
"utils.rkt"
"types.rkt"
"const.rkt"
"key.rkt"
@mflatt
mflatt / demo.lexpr
Last active September 28, 2019 16:40
let | x : 1
| y : 2
in :
(x + y)
define pi : 3.14
define fib(n) :
log_error("fib called")
cond | (n = 0) : 0
@mflatt
mflatt / gist:99f31749ad4d02af918714f7d845b895
Last active September 14, 2019 13:27
colons in place of arrows
let (x = 1,
y = 2):
x+y
// I'd be tempted to write it like this, though
let (x = 1,
y = 2)
: x+y
define pi = 3.14
@mflatt
mflatt / gist:f7313e1561210be56313903fd75c6607
Created July 28, 2019 14:22
statement trees based on binary operators
Designated "statement" grouping operators with precedence from
strongest to weakest:
, => = & | :
Examples, showing intended use followed by full parenthesization:
define : f(s) =
printf("hi ~a\n", s),
"hi"