Joe,
This (or something similar) might be sufficient depending on what you are
really trying to accomplish:
ApplyTemplate=. [ ;@:({:: ::[L:0 _) ,@:]
('Hello ';0;' world! ';0) ApplyTemplate (<'abc')
Hello abc world! abc
('Hello ';0;' world! ';1) ApplyTemplate (;:'abc de')
Hello abc world! de
On Thu, Jan 7, 2016 at 11:16 AM, Raul Miller <[email protected]> wrote:
> On Thu, Jan 7, 2016 at 9:49 AM, Joe Bogner <[email protected]> wrote:
> > I think the concept of applyTemplate is useful because joining strings
> > can be tedious when J evaluates them as a train (] , ' foo') -- no
> > noun allowed in the right tine! and that can get trippy with longer
> > strings:
> >
> > ('Dear', ] , ' - Hello!') 'abc' -- nope!
> >
> > ('Dear ', ] @ ,&' - Hello!') 'abc' -- typically a trial and error and
> > not as easily red
> >
> > ('Dear ';0;' - Hello!') applyTemplate ('abc';'')
> > Dear abc - Hello!
>
> That particular issue can be resolved using an appropriate bit of
> nothing to anchor the train.
>
> mt1=:''"_
> ('Dear ', ] , ' - Hello!',mt1) 'abc'
> Dear abc - Hello!
>
> The 1 in the name refers to the rank of the empty value it supplies.
> In some cases you would want a rank 2 value.
>
> And of course, the consequence is that you can use J's trains as
> "templates" containing verbs. Whether or not that's appropriate will
> depend on what you are doing - there still might be contexts where
> boxed index/string combos are the right answer. But in a lot of the
> cases something simpler will do. (This seems to be the case so very
> often, though there can also be good reasons to use other
> approaches...).
>
> FYI,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm