String interpolation (included): Difference between revisions

Content added Content deleted
(Added Quackery.)
(→‎{{header|Quackery}}: simplified, improved)
Line 1,739: Line 1,739:
'''Not The Task'''
'''Not The Task'''


<code>interpolate$</code> replaces every instance of a specified character in a string with a specified string. Note that the specified string should not include the specified character as this will cause <code>interpolate$</code> to loop indefinitely.
<code>interpolate$</code> replaces every instance of a specified character in a string with a specified string.


<syntaxhighlight lang="Quackery"> [ temp put
<syntaxhighlight lang="Quackery"> [ stack ] is int.chr
[ stack ] is int.str
swap

[ 2dup find
[ int.str put
tuck over found while
int.chr put
over pluck drop
swap split
[] swap witheach
temp share
[ dup int.chr share = if
swap join join
[ drop int.str share ]
again ]
join ]
nip nip temp release ] is interpolate$ ( $ n $ --> $ )
int.str release
int.chr release ] is interpolate$ ( $ n $ --> $ )


$ "Mary had a lamb." char X $ "little" interpolate$ echo$ cr
$ "Mary had a lamb." char X $ "little" interpolate$ echo$ cr