Here's a quick implementation:
template=:1 :0
assert. -. 0 e. }., I. '{}' =/ m NB. {} syntax check
assert. (,2) -: }.$y NB. need two cols: names; values
nams=. {."1 ,.y
vals=. {:"1 ,.y
subst=. vals {::~ nams i. <a
;(+/\@e.&'{}' <@({. subst@]^:('{'=[) }.)/. ]) m
)
Example use:
'{this} food' template ,:'this';'that'
that food
or, given
example=: 0 :0 template
Hello {name},
Nice to meet you.
{date}
)
This would also be an example:
example (;:'name date'),.'George';'today'
FYI,
--
Raul
On Mon, Feb 18, 2013 at 12:18 AM, June Kim (김창준) <[email protected]> wrote:
> Hello
>
> I am looking for a string template library in J. Is there something like
> what's following(it's in Python):
>
>>>> """
> ... Hello {name},
> ... Nice to meet you.
> ... {date}
> ... """.format(**dict(name="David", date="2013.2.18"))
> '\nHello David,\nNice to meet you.\n2013.2.18\n'
>>>> print _
>
> Hello David,
> Nice to meet you.
> 2013.2.18
>
>
> I think I can write a verb in J, but firstly I wanted to check if there is
> something out there already.
>
> June
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm