Jump to content

Mad Libs: Difference between revisions

mNo edit summary
Line 2,277:
foreach i unique w [replace/all x i ask join i ": "] alert x
</lang>
=={{header|Red}}==
While the REBOL GUI version above also works in Red with minor changes, here is a text-only version.
<lang Red>phrase: ask "Enter phrase, leave line empty to terminate:^/"
while [not empty? line: input] [append phrase rejoin ["^/" line]]
words: parse phrase [collect [any [to "<" copy b thru ">" keep (b)]]]
foreach w unique words [replace/all phrase w ask rejoin [w ": "]]
print phrase</lang>
{{out}}
Remarkably (with Red 0.6.4 for Windows built 5-Aug-2020/18:58:49+02:00), replacements made in original phrase are dynamically reflected in the display of the phrase entered. Hence first stage of execution yields:
<pre>Enter phrase, leave line empty to terminate:
<name> went for a walk in the park. <he or she> found a <noun>. <name> decided to take it home.
 
<name>: </pre>
...and final output is (so that the last instruction "print phrase" could be omitted):
<pre>Enter phrase, leave line empty to terminate:
As I had nothing to do, I went for a walk in the park. I found a funny task on http://rosettacode.org. As I had nothing to do, I decided to take it home.
 
<name>: As I had nothing to do, I
<he or she>: I
<noun>: funny task on http://rosettacode.org
As I had nothing to do, I went for a walk in the park. I found a funny task on http://rosettacode.org. As I had nothing to do, I decided to take it home.
</pre>
 
=={{header|REXX}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.