String interpolation (included): Difference between revisions
Content added Content deleted
m (→{{header|APL}}) |
m (→{{header|APL}}) |
||
Line 628: | Line 628: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
<lang apl> |
<lang apl> |
||
s ← 'Mary had a |
s ← 'Mary had a ∆ lamb' ⋄ s[s⍳'∆'] ← ⊂'little' ⋄ s ← ∊s |
||
s |
s |
||
Mary had a little lamb |
Mary had a little lamb |
||
Line 637: | Line 637: | ||
∇r ← s sInterp sv |
∇r ← s sInterp sv |
||
⍝⍝ Interpolate items in sv into s (string field substitution) |
⍝⍝ Interpolate items in sv into s (string field substitution) |
||
⍝ s: string - format string, ' |
⍝ s: string - format string, '∆' used for interpolation points |
||
⍝ sv: vector - vector of items to interpolate into s |
⍝ sv: vector - vector of items to interpolate into s |
||
⍝ r: interpolated string |
⍝ r: interpolated string |
||
s[(' |
s[('∆'=s)/⍳⍴s] ← ⊃¨(⍕¨sv) |
||
r ← ∊s |
r ← ∊s |
||
∇ |
∇ |
||
'Mary had a |
'Mary had a ∆ lamb, its fleece was ∆ as ∆.' sInterp 'little' 'black' 'night' |
||
Mary had a little lamb, its fleece was black as night. |
Mary had a little lamb, its fleece was black as night. |
||
'Mary had a |
'Mary had a ∆ lamb, its fleece was ∆ as ∆.' sInterp 'little' 'large' 42 |
||
Mary had a little lamb, its fleece was large as 42. |
Mary had a little lamb, its fleece was large as 42. |
||
</lang> |
</lang> |