Skip to content

Instantly share code, notes, and snippets.

@SaitoAtsushi
Forked from tana/pattern.scm
Created July 29, 2010 15:12
Show Gist options
  • Save SaitoAtsushi/498372 to your computer and use it in GitHub Desktop.
Save SaitoAtsushi/498372 to your computer and use it in GitHub Desktop.
(use util.match)
(define-syntax %def
(syntax-rules (->)
((_ (a ...) (b ...) -> x r ...)
(%def (a ... ((b ...) x)) () r ...))
((_ (a ...) (b ...) x r ...)
(%def (a ...) (b ... x) r ...))
((_ (a ...) ())
(match-lambda* a ...))
((_ (a ...) (b ...))
(match-lambda* a ... (else b ...)))))
(define-syntax def
(syntax-rules ()
((_ n x ...)
(define n
(%def () () x ...)))))
(def fact
0 -> 1
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