From 6ffd6456c4b892ff7a8ea63cc5cb17f7d6907765 Mon Sep 17 00:00:00 2001 From: Doug Coleman <doug.coleman@gmail.com> Date: Wed, 5 Dec 2007 09:42:08 -0600 Subject: [PATCH] Add some code to build up all possible quotations with random-tester --- extra/random-tester/utils/utils.factor | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extra/random-tester/utils/utils.factor b/extra/random-tester/utils/utils.factor index ef3d66ad2d..91aefabe6f 100644 --- a/extra/random-tester/utils/utils.factor +++ b/extra/random-tester/utils/utils.factor @@ -1,5 +1,5 @@ USING: arrays assocs combinators.lib continuations kernel -math math.functions namespaces quotations random sequences +math math.functions memoize namespaces quotations random sequences sequences.private shuffle ; IN: random-tester.utils @@ -93,3 +93,13 @@ C: <p-list> p-list >r make-p-list r> (each-permutation) ; +MEMO: builder-permutations ( n -- seq ) + { compose curry } swap permutations + [ >quotation ] map ; foldable + +: all-quot-permutations ( seq -- newseq ) + dup length 1- builder-permutations + swap [ 1quotation ] map dup length permutations + [ swap [ >r seq>stack r> call ] curry* map ] curry* map ; + +! clear { map sq 10 } all-quot-permutations [ [ [ [ [ call ] keep datastack length 2 = [ . .s nl ] when ] catch ] in-thread drop ] each ] each