Advertisement
Guest User

Untitled

a guest
Sep 30th, 2013
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.21 KB | None | 0 0
  1. #lang racket
  2.  
  3. (module lambda-matcher racket
  4.  
  5. (require (for-syntax syntax/parse  unstable/syntax racket/match))
  6. (match '((a b) ( c))
  7.     [(list (list  x y ...) z ...) (list x y x z)])
  8. (define (lambda-matcher x)
  9.   (match x
  10.     [(list (list  x y ...) z ...) (list (list x y) (list x z))]))
  11. (lambda-matcher  '((a b) ( c)))
  12. (lambda-matcher (lambda-matcher '((a b) ( c))))
  13. (define (lambda-matcher2 x)
  14.   (match x [(list (list  x y ...) z ...) (list (list x y) (list x z))]
  15.                [(list (list w (list x) ...) (list y (list (list z)) ...)) (list (list w (list x y))(list w (list y z)))]))  
  16. ;(lambda-matcher2 (lambda-matcher2 '((a b) ( c))))
  17. (lambda-matcher2 '((a (b)) (a ((c)))))
  18. (lambda-matcher (lambda-matcher2 (lambda-matcher  '((a b) (c)))))
  19.  
  20. (define-syntax (lambda-matcher-syntax stx)
  21.   (syntax-parse stx
  22.    [((~literal match) x
  23.       [((~literal list) ((~literal list) a b  (~literal ___)) c (~literal ___))
  24.        ((~literal list) ((~literal list) d e) ((~literal list) f g))])
  25.     (match (syntax->datum #'x)
  26.       [(list (list a b ___) c  ___)
  27.        (list (list (syntax->datum #'d) (syntax->datum #'e)) (list (syntax->datum #'f) (syntax->datum #'g)))])]))
  28. (lambda-matcher-syntax '((a b) c))
  29.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement