procgen  Artifact [85a6f672ec]

Artifact 85a6f672eca3f2915fc64365799d07fcb8fa8b7da144abc6435eb60199692406:


(define-macro (rule . body)
  (define (make-cases ct body acc)
    (if (eq? body '()) acc
      (make-cases (+ ct 1) (cdr body)
		(cons (list (list ct) (cons 'string-append (car body))) acc))))
  (list 'define (car body)
	(cons 'case (cons (list 'random-integer (length (cdr body)))
	  (make-cases 0 (cdr body) '()) ))))

(define (pick ar)
  (vector-ref ar (random-integer (vector-length ar))))

(define-macro (one-of . body)
	(define (make-cases ct body acc) ; accumulator func
	; this could probably be done much more cleanly through
	; judicious use of fold or whatever it's called but my
	; brain is too broken
		(if (eq? body '()) ; then
			acc 
		; else
			(make-cases (+ 1 ct) (cdr body) ; recurse!
				(cons `((,ct) ,(car body)) acc)))) ; the rule

	`(case (random-integer ,(length body)) ; final output
		,@(make-cases 0 body '()))
)
(random-source-randomize! default-random-source)