Skip to content

Instantly share code, notes, and snippets.

@samth
Created November 20, 2011 16:58
Show Gist options
  • Save samth/1380486 to your computer and use it in GitHub Desktop.
Save samth/1380486 to your computer and use it in GitHub Desktop.
Pattern-matching defintion
#lang racket
(require syntax/parse/define)
(define-simple-macro (def (f0:id p0 ...) rhs0:expr (~seq (f:id p ...) rhs:expr) ...)
(define f0 (match-lambda** [(p0 ...) rhs0] [(p ...) rhs] ...)))
(def (fact 0) 1 (fact 1) 1 (fact n) (* n (fact (- n 1))))
(fact 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment