Mad Libs: Difference between revisions
Content added Content deleted
Line 1,753: | Line 1,753: | ||
Phydeaux went for a walk in the park. She |
Phydeaux went for a walk in the park. She |
||
found a flea. Phydeaux decided to take it home.</pre> |
found a flea. Phydeaux decided to take it home.</pre> |
||
=={{header|Phix}}== |
|||
Set mlfile to the name of a suitable file, if you have one, otherwise it uses the default story. |
|||
<lang Phix>string mlfile = "", -- eg story.txt |
|||
mltxt = iff(length(mlfile)?join(read_lines(mlfile),"\n"):""" |
|||
<name> went for a walk in the park. <he or she> |
|||
found a <noun>. <name> decided to take it home. |
|||
""") |
|||
sequence strings = {}, replacements = {} |
|||
integer startpos, endpos=1 |
|||
while 1 do |
|||
startpos = find('<',mltxt,endpos) |
|||
if startpos=0 then exit end if |
|||
endpos = find('>',mltxt,startpos) |
|||
if endpos=0 then ?"missing >" abort(0) end if |
|||
string s = mltxt[startpos..endpos] |
|||
if not find(s,strings) then |
|||
strings = append(strings,s) |
|||
replacements = append(replacements,prompt_string(sprintf("Enter replacement for %s:",{s}))) |
|||
end if |
|||
end while |
|||
puts(1,substitute_all(mltxt,strings,replacements))</lang> |
|||
{{out}} |
|||
<pre> |
|||
Enter replacement for <name>:Pete |
|||
Enter replacement for <he or she>:He |
|||
Enter replacement for <noun>:Rosetta Code Task |
|||
Pete went for a walk in the park. He |
|||
found a Rosetta Code Task. Pete decided to take it home. |
|||
</pre> |
|||
=={{header|Pike}}== |
=={{header|Pike}}== |