String interpolation (included): Difference between revisions

Content added Content deleted
Line 632: Line 632:
Mary had a little lamb
Mary had a little lamb


⍝⍝⍝ Or, for a more general version which interpolates multiple positional arguments...
⍝⍝⍝ Or, for a more general version which interpolates multiple positional arguments and can
⍝⍝⍝ handle both string and numeric types...


∇r ← s sInterp sv
∇r ← s sInterp sv
Line 639: Line 640:
⍝ 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] ← ⊃¨sv
s[('_'=s)/⍳⍴s] ← ⊃¨(⍕¨sv)
r ← ∊s
r ← ∊s
'Mary had a _ lamb, its fleece was _ as _.' sInterp 'little' 'black' 'night'
'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 _ lamb, its fleece was _ as _.' sInterp 'little' 'large' 42
Mary had a little lamb, its fleece was large as 42.
</lang>
</lang>