# HG changeset patch # User Mike Pavone # Date 1376036234 25200 # Node ID 0ccebdbc3e804517f622d2f9c8202094c614bab9 # Parent 3f0172ceab81d9d73e1e8ce5e54d438963f1f132 Add support for generating programs that contain fold. Make the desired program size a command line argument. diff -r 3f0172ceab81 -r 0ccebdbc3e80 src/bv.tp --- a/src/bv.tp Fri Aug 09 00:47:29 2013 -0700 +++ b/src/bv.tp Fri Aug 09 01:17:14 2013 -0700 @@ -116,7 +116,7 @@ fold:with:startingAt <- :toFold :fun :startAcc { #{ string <- { - "(fold " . (string: toFold) . " " . (string: startAcc) . "(lambda (val acc) " . (string: fun) . "))" + "(fold " . (string: toFold) . " " . (string: startAcc) . " (lambda (val acc) " . (string: fun) . "))" } eval <- { _acc <- (eval: startAcc) @@ -162,7 +162,7 @@ allOfSize:inFold? <- :n :infold? { if: n = 1 { res <- #[one zero input] - if: infold? { + if: infold? = 2 { res append: acc res append: val } @@ -213,6 +213,28 @@ } numLeft <- numLeft + 1 } + if: n > 4 && infold? = 0 { + numSeq <- 1 + limitSeq <- n - 3 + while: { numSeq < limitSeq } do: { + numFun <- 1 + limitFun <- n - (2 + numSeq) + while: { numFun < limitFun } do: { + numStart <- n - (2 + numSeq + numFun) + choicesStart <- (allOfSize: numStart inFold?: 1) + choicesFun <- (allOfSize: numFun inFold?: 2) + foreach: (allOfSize: numSeq inFold?: 1) :idx seqExp { + foreach: choicesFun :idx funExp { + foreach: choicesStart :idx startExp { + res append: (fold: seqExp with: funExp startingAt: startExp) + } + } + } + numFun <- numFun + 1 + } + numSeq <- numSeq + 1 + } + } } } res @@ -220,7 +242,7 @@ } allOfSize <- :n { - allOfSize: (n - 1) inFold?: false + allOfSize: (n - 1) inFold?: 0 } } } @@ -235,13 +257,20 @@ } } - main <- { + main <- :args { test: (program gentestprog) test: (program exampleprog) - prog <- program - foreach: (prog allOfSize: 5) :idx tree { - prog root! tree - test: prog + size <- 3 + if: (args length) > 1 { + size <- int32: (args get: 1) } + if: size >= 2 { + prog <- program + foreach: (prog allOfSize: size) :idx tree { + prog root! tree + test: prog + } + } + 0 } }