Skip to content

Commit

Permalink
matche.rkt
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelballantyne committed Jan 16, 2015
1 parent 2fbdae6 commit a628cb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 9 additions & 0 deletions matche.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#lang racket
(require "mk.rkt")
(require (for-syntax racket/syntax))

(provide matche lambdae defmatche)

(define-for-syntax memp memf)

(include "matche.scm")
9 changes: 6 additions & 3 deletions matche.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
;
; https://github.com/calvis/cKanren/blob/dev/cKanren/matche.rkt#L54

; Note that this definition is available at syntax phase in chez and vicare due to implicit
; phasing, but not in Racket (which uses explicit phasing). Racket already has a version available
; by default though, so that's fine. This definition isn't just isn't used in Racket.
(define syntax->list
(lambda (e)
(syntax-case e ()
[() '()]
[(x . r) (cons #'x (syntax->list #'r))])))
[(x . r) (cons #'x (syntax->list #'r))])))

(define-syntax defmatche
(lambda (stx)
Expand Down Expand Up @@ -83,8 +86,8 @@
[else (loop pat)])]
[else (loop pat)])))
(unless
(andmap (lambda (y) (= (length (syntax->list #'(v ...))) (length y)))
(syntax->list #'([pat ...] ...)))
(andmap (lambda (y) (= (length (syntax->datum #'(v ...))) (length y)))
(syntax->datum #'([pat ...] ...)))
(error 'matche "pattern wrong length blah"))
(with-syntax ([(([pat^ ...] (c ...) (x ...)) ...)
(map (lambda (y) (parse-pattern #'(v ...) y))
Expand Down

0 comments on commit a628cb7

Please sign in to comment.