Mad Libs: Difference between revisions

Content added Content deleted
(Fixed Mathematica)
(→‎{{header|Tcl}}: Added zkl)
Line 1,720: Line 1,720:
----------------------------------------------------------------------
----------------------------------------------------------------------
</pre>
</pre>

=={{header|zkl}}==
<lang zkl>story,line,re:=Data(),"",RegExp("(<[^>]+>)");
do{ line=ask("Story: "); story.write(line,"\n") }while(line);
while(re.search(story,True)){
z,ml,N:=re.matched,z[1],z[0][1]; // z=( (0,6),"<name>" )
s:=ask("Text to replace ",ml," with: ");
while(Void!=(n:=story.find(ml))){ story[n,N]=s } // replace all <names>s
}
println("-----------------");
story.text.print();</lang>
{{out}}
<pre>
Story: <name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.

Story: Story: Text to replace <name> with: Susan
Text to replace <he or she> with: she
Text to replace <noun> with: rock
-----------------
Susan went for a walk in the park. she
found a rock. Susan decided to take it home.

</pre>
The "Story: Story:" was because I pasted the story causing i/o to get out of sync.