(defn generate-name []
(case (rand-int 3)
0 "agastopia"
1 "bibble"
2 "cabotage"))
(defn generate-instruction []
(case (rand-int 7)
0 "System.out.println();"
1 (str "System.out.println(" (generate-name) ");")
2 (str "if (" (generate-name) ") { " "return;" " }")
3 (str "if (" (generate-name) ") " (generate-instruction-list 3))
4 (str "while (" (generate-name) ") { " (generate-instruction-list 3) " }")
5 (str (generate-name) " = " "false;")
6 (str (generate-name) " = " "true;")))
(defn generate-instruction-list [length]
(loop [i length
out ""]
(if (zero? i)
out
(recur (dec i) (str out " " (generate-instruction))))))
(defn generate-java-function []
(str "void" " " (generate-name) "()" " { " (generate-instruction) " }"))
When we run the program:
(generate-java-function)
We can the following code (formatted with an IDE):
void bibble() {
while (agastopia) {
if (agastopia) if (bibble) {
return;
}
if (cabotage) System.out.println();
System.out.println();
cabotage = true;
if (agastopia) bibble = true;
bibble = false;
while (agastopia) {
System.out.println(cabotage);
System.out.println(agastopia);
if (agastopia) if (bibble) while (bibble) {
if (cabotage) if (cabotage) {
return;
}
System.out.println(cabotage);
System.out.println();
if (cabotage) if (cabotage) System.out.println();
while (agastopia) {
agastopia = false;
cabotage = true;
agastopia = true;
}
System.out.println(bibble);
cabotage = true;
while (bibble) {
System.out.println();
System.out.println();
if (cabotage) bibble = true;
System.out.println();
System.out.println();
}
if (bibble) {
return;
}
}
bibble = false;
while (agastopia) {
while (agastopia) {
bibble = true;
System.out.println();
System.out.println(bibble);
}
cabotage = true;
if (bibble) if (agastopia) System.out.println(bibble);
System.out.println(agastopia);
System.out.println(bibble);
System.out.println(agastopia);
while (bibble) {
System.out.println(bibble);
System.out.println(agastopia);
bibble = false;
}
}
System.out.println(cabotage);
if (bibble) if (cabotage) cabotage = true;
bibble = true;
while (bibble) {
if (cabotage) {
return;
}
System.out.println();
if (bibble) {
return;
}
}
if (agastopia) System.out.println();
agastopia = false;
cabotage = false;
if (agastopia) {
return;
}
}
if (agastopia) if (cabotage) System.out.println();
System.out.println(agastopia);
cabotage = false;
if (cabotage) {
return;
}
if (agastopia) if (bibble) {
return;
}
agastopia = false;
cabotage = false;
if (cabotage) {
return;
}
}
}