Skip to content

Instantly share code, notes, and snippets.

View danking's full-sized avatar

Dan King danking

View GitHub Profile
@danking
danking / gist:2408499
Created April 17, 2012 19:39
Hyperoperators
#lang racket
(provide (all-defined-out))
(define (hyper n)
(cond
;; [(= n 0) add1]
[(= n 1) +]
[(= n 2) *]
[else (lambda (base r)
(foldl (hyper (sub1 n))
@danking
danking / gist:1473268
Created December 13, 2011 18:38
Does this exist?
(for/while ([var init] ...)
stop-proc
body ...)
=>
(define (loop var ...)
(if (stop-proc var ...)
(values var ...)
(let-values (((var ...) (begin body ...)))
(loop var ...))))
(define (hyperize f id-e)
(define (f* b n)
(if (zero? n) id-e (f b (f* b (sub1 n)))))
f*)
;; modified Knuth Up-Arrow notation
(define (↑ n)
(cond ((zero? n) +)
((= n 1) (hyperize + 0))
(else (hyperize (↑ (sub1 n)) 1))))
(define (hyperize f id-e)
(define (f* b n)
(if (zero? n) id-e (f b (f* b (sub1 n)))))
f*)
-> ((hyperize + 0) 2 4)
8
-> ((hyperize + 0) 2 3)
6
-> ((hyperize + 0) 2 10)
(global-set-key (kbd "C-c m")
(lexical-let ((previous-buffer (current-buffer)))
(lambda ()
(interactive)
(if (string-match "\*Mingus.*" (buffer-name))
(switch-to-buffer previous-buffer)
(progn
(setq previous-buffer (current-buffer))
(mingus))))))
gist-list - Lists your gists in a new buffer. Use arrow keys
to browse, RET to open one in the other buffer.

gist-region - Copies Gist URL into the kill ring.
With a prefix argument, makes a private gist.
(define (datum-equal? x y)
(let-values (((x y) (if (and (syntax? x) (syntax? y))
(values (syntax->datum x) (syntax->datum y))
(values x y))))
(let-values (((x y) (if (and (struct? x) (struct? y))
(values (struct->vector x) (struct->vector y))
(values x y))))
(if (and (sequence? x) (sequence? y))
(for/and ([x-element x]
[y-element y])
@danking
danking / error.log
Created October 19, 2011 15:03
odd syntax-parse behavior
-*- mode: compilation; default-directory: "/home/danking/development/olin-coop/pda-to-pda-risc/" -*-
Compilation started at Wed Oct 19 11:01:54
racket parse-pda-macro.rkt
compile: bad syntax; literal data is not allowed, because no #%datum syntax transformer is bound in: #(struct:goto #<syntax:/home/danking/development/olin-coop/pda-to-pda-risc/parse-pda-macro.rkt:23:29 (A)> #<syntax:/home/danking/development/olin-coop/pda-to-pda-risc/parse-pda-macro.rkt:23:33 bar>)
=== context ===
standard-module-name-resolver
Grammar
0 $accept: foo $end
1 foo: foo A
2 | A
Terminals, with rules where they appear