June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
18
Task/Mad-Libs/Julia/mad-libs.julia
Normal file
18
Task/Mad-Libs/Julia/mad-libs.julia
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function madlibs(template)
|
||||
println("The story template is:\n", template)
|
||||
fields = Set(getfield.(collect(eachmatch(r"<[^>]+>", template)), :match))
|
||||
print("\nInput a comma-separated list of words to replace the following items:",
|
||||
join(fields, ", "), "\n -> ")
|
||||
values = split(readline(STDIN), ",")
|
||||
for (m, v) in zip(fields, values)
|
||||
template = replace(template, m, v)
|
||||
end
|
||||
println("\nThe story becomes:\n", template)
|
||||
end
|
||||
|
||||
const template = """
|
||||
<name> went for a walk in the park. <he or she>
|
||||
found a <noun>. <name> decided to take it home.
|
||||
"""
|
||||
|
||||
madlibs(template)
|
||||
Loading…
Add table
Add a link
Reference in a new issue