String interpolation (included): Difference between revisions

Content added Content deleted
(Add SenseTalk implementation)
Line 1,768:
<pre>
Mary had a little lamb
</pre>
 
=={{header|SenseTalk}}==
SenseTalk does string interpolation through the <code>merge</code> function, which can evaluate any sort of embedded expression, including entire sections of code like conditionals or repeat loops. For convenience, the merge function can be invoked by simply using a <code>!</code> before a string literal (this is needed because string literals are actually literal in SenseTalk -- there are no characters with hidden meaning by default).
<lang sensetalk>put "little" into x
 
put "Mary had a [[x]] lamb." -- this is a literal string
put !"Mary had a [[x]] lamb." -- this is an interpolated string
put
put !"[[repeat with n=2 to 6]]Mary had [[n]] [[x]] lambs.[[return]][[end repeat]]"
put !"Mary had [[repeat with n=2 to 6]][[n]] [[x]] [[end repeat]]lambs."
</lang>
{{out}}
<pre>
Mary had a [[x]] lamb.
Mary had a little lamb.
 
Mary had 2 little lambs.
Mary had 3 little lambs.
Mary had 4 little lambs.
Mary had 5 little lambs.
Mary had 6 little lambs.
 
Mary had 2 little 3 little 4 little 5 little 6 little lambs.
</pre>