changeset 9:0ccebdbc3e80

Add support for generating programs that contain fold. Make the desired program size a command line argument.
author Mike Pavone <pavone@retrodev.com>
date Fri, 09 Aug 2013 01:17:14 -0700
parents 3f0172ceab81
children 8e1d9b0aca1f
files src/bv.tp
diffstat 1 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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
 	}
 }