# These two functions are to be used in "grammar scripts"
proc define {name content} {
proc $name {} [list expand $content]
}
proc defchoice {name choices} {
proc $name {} [list choice $name $choices]
}
# Helper functions
proc expand str {subst $str}
proc choice {name choices} {
set idx [expr int(floor(rand()*[llength $choices]))]
return [expand [lindex $choices $idx]]
}
# Demo "grammar script" -- translated exam.pb from the dada engine distribution -- "generates intimidating but bogus exam questions"
proc exam {} {
defchoice question {
[question-2]
[question-2]
{[question-2] Be sure to refer to [issue] in your answer.}
{[question-2] Include [evidence-type].}}
defchoice question-2 {
{Compute the [something-of ] of [something].}
{Are [plural] [classification]? Discuss.}
{Is [singular] [classification]? Discuss.}
{Express [something] in [express-in-what].}
{Show that the [something-of ] of [something] is [result].}}
defchoice issue {{[theorem-source]'s Theorem} {[theory-type] theory}
"Plutonium Atom Totality" {the [ordinal] law of [law-of-this]}}
defchoice theorem-source {Godel Wibbel Abian Turing Euler Fermat Bell}
defchoice theory-type {game set match interstice information ring group graph}
defchoice law-of-this {thermodynamics "conservation of matter" gravity}
defchoice express-in-what {"canonical form" "normal form" {the [tag] domain}}
defchoice something-of {[something-of-2] {[adjective] [something-of-2]}
{[tag]-[something-of-2]}}
defchoice adjective {canonical minimal maximal inverse}
defchoice something-of-2 {closure determinant matrix path correlation}
define plural {[adjective] [plural-2]}
defchoice plural-2 {trees matrices}
define singular {[adjective] [singular-2]}
defchoice singular-2 {search factorisation}
defchoice result {number "{ }" infinity uncomputable "the null set"}
defchoice evidence-type {flowcharts "Feynman diagrams" "Venn diagrams"}
defchoice something {[number] [set-of-numbers]}
define set-of-numbers {{ [numbers] }}
defchoice numbers {{[number][numbers]} [number]}
defchoice number {{[digit][number]} [digit]}
defchoice digit {0 1 2 3 4 5 6 7 8 9}
define classification {[tag]-complete}
defchoice tag {[greek-letter] [roman-letter] {[roman-letter] [roman-letter]}}
defchoice roman-letter {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
defchoice greek-letter {alpha beta gamma delta epsilon lambda sigma theta phi rho omega}
defchoice ordinal {first second third fourth fifth}
return [question]
}
# Run demo code
catch { console show }
puts [exam]# Example outputs:
- Are minimal matrices S Z-complete? Discuss. Include Venn diagrams.
- Show that the canonical determinant of 1 is infinity.
- Is minimal factorisation phi-complete? Discuss. Be sure to refer to Plutonium Atom Totality in your answer.
- Express { 8775460 } in the K I domain.

