Anonymous user
Mad Libs: Difference between revisions
m
→{{header|REXX}}: removed some dead code, changed comments, indentation, added a section for the '''CHANGESTR""" bif. -- ~~~~
Walterpachl (talk | contribs) m (→{{header|REXX}}: typos (mostly)) |
m (→{{header|REXX}}: removed some dead code, changed comments, indentation, added a section for the '''CHANGESTR""" bif. -- ~~~~) |
||
Line 590:
=={{header|REXX}}==
<lang rexx>/*REXX program to prompt user for template substitutions within a story.*/
parse arg iFID . /*allow
if iFID=='' then iFID="MAD_LIBS.TXT"
do recs=1 while lines(iFID)\==0
@.recs=linein(iFID); @=@ @.recs
if @.recs='' then leave
end /*recs*/
recs=recs-1 /*adjust for
do
parse var @ '<' ? '>'
if ?='' then leave /*if no
if !.? then iterate /*already asked? Keep scanning.*/
!.?=1 /*
#=#+1 /*bump the template counter
old.# = '<'?">"; new.# =
end /*
say; say copies('═',79)
do m=1 for recs /*display the text, line for line*/
do n=1 for # /*perform substitutions in
@.m = changestr(old.n, @.m, new.n)
end /*n*/
say @.m /*display (new) substituted text.*/
end /*m*/
say copies('═',79) /*display a final (output) fence.
/*stick a fork in it, we're done.*/</lang>
'''output''' when using the default input fileID
<pre style="overflow:scroll">
Mary
she
little lamb
Line 639:
═══════════════════════════════════════════════════════════════════════════════
</pre>
Some older REXXes don't have the '''changestr''' bif, so here is a version:
<lang rexx>/*──────────────────────────────────CHANGESTR subroutine────────────────*/
changestr: procedure; parse arg o,h,n; r=; w=length(o); if w==0 then return n||h
do forever; parse var h y (o) _ +(w) h; if _=='' then return r||y; r=r||y||n; end</lang>
=={{header|Ruby}}==
|