45
46
47
48
49
50
51
52
53
54
55
56
|
; generates a function that picks and applies one of the
; patterns passed to it. inner patterns can be expanded
; with the inner macro (@)
(define-macro (rule . body)
(let ([decl (car body)]
[patterns (cdr body)])
`(define ,decl
(define-macro (@ . tree) (@rewrite-patterns tree))
,(@rewrite-patterns patterns))))
(define (pick ar)
(vector-ref ar (pseudo-random-integer (vector-length ar))))
|
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
; generates a function that picks and applies one of the
; patterns passed to it. inner patterns can be expanded
; with the inner macro (@)
(define-macro (rule . body)
(let ([decl (car body)]
[patterns (cdr body)])
`(define ,decl
(define-macro (@ . tree) (@rewrite-patterns tree)) ;choice point
(define-macro (: . tree) (@rewrite-patterns (cons (list "") tree))) ;optional choice
(define-macro (? . tree) (@rewrite-patterns (cons (list "") (list tree)))) ;optional - TODO: rewrite
,(@rewrite-patterns patterns))))
; generate simple word-banks
(define-macro (bank . body)
(let ([decl (car body)]
[patterns (cdr body)])
`(define (,decl)
(one-of ,@patterns))))
(define (pick ar)
(vector-ref ar (pseudo-random-integer (vector-length ar))))
|