Jump to content

Mad Libs: Difference between revisions

Added Wren
(Added Wren)
Line 2,810:
...
qux>></pre>
 
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-pattern}}
{{libheader|Wren-seq}}
<lang ecmascript>import "io" for Stdin, Stdout
import "/pattern" for Pattern
import "/seq" for Lst
 
System.print("Please enter a multi-line story template terminated by a blank line:\n")
Stdout.flush()
var story = ""
while (true) {
var line = Stdin.readLine()
if (line.isEmpty) break
story = story + line + "\n" // preserve line breaks
}
// identify blanks
var p = Pattern.new("<+0^>>")
var blanks = Lst.distinct(p.findAll(story).map { |m| m.text }.toList)
System.print("Please enter your replacements for the following 'blanks' in the story:")
for (blank in blanks) {
System.write(" %(blank[1..-2]) : ")
Stdout.flush()
var repl = Stdin.readLine()
story = story.replace(blank, repl)
}
System.print("\n%(story)")</lang>
 
{{out}}
<pre>
Please enter a multi-line story template terminated by a blank line:
 
<name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.
 
Please enter your replacements for the following 'blanks' in the story:
name : Archimedes
he or she : He
noun : bath-tub
 
Archimedes went for a walk in the park. He
found a bath-tub. Archimedes decided to take it home.
</pre>
 
=={{header|zkl}}==
9,487

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.