;;;;; ;;;;; Random ;;;;; (define \$rands (lambda [\$s \$e] {(pure-rand s e) @(rands s e)})) (define \$pure-rand (lambda [\$s \$e] (io (rand s e)))) (define \$randomize (lambda [\$xs] (letrec {[\$randomize' (lambda [\$xs \$n] (if (eq? n 0) {} (let* {[\$r (pure-rand 1 n)] [\$x (nth r xs)]} {x @(randomize' (delete-first x xs) (- n 1))})))]} (randomize' xs (length xs))))) (define \$R.between (lambda [\$s \$e] (randomize (between s e)))) (define \$R.multiset (lambda [\$a] (matcher {[ [] {[{} {[]}] [_ {}]}] [ [a (R.multiset a)] {[\$tgt (map (lambda [\$i] (match tgt (list a) {[(loop \$j [1 (- i 1)] ) [x {@(map (lambda [\$j] xa_j) (between 1 (- i 1))) @ts}]]})) (R.between 1 (length tgt)))]}] [\$ [something] {[\$tgt {tgt}]}] }))) (define \$R.uncons (lambda [\$xs] (car (match-all xs (R.multiset something) [ [x rs]])))) (define \$R.car (lambda [\$xs] (car (match-all xs (R.multiset something) [ x])))) (define \$R.cdr (lambda [\$xs] (car (match-all xs (R.multiset something) [ rs])))) (define \$sample R.car) (define \$R.set (lambda [\$a] (matcher {[ [] {[{} {[]}] [_ {}]}] [ [a (R.multiset a)] {[\$tgt (map (lambda [\$i] (match tgt (list a) {[(loop \$j [1 (- i 1)] ) [x tgt]]})) (R.between 1 (length tgt)))]}] [\$ [something] {[\$tgt {tgt}]}] })))