I know I've built something kind of like this before, but I couldn't
find it, so...
Here's a quicky little mechanism to support interpolation in strings in J:
interp_fmt=:3 :0
}:;<@(LF,~dtb)"1]1 1}._1 _1}.":<y
)
interp=:3 :0
starts=. I. '(:' E. y
ends=. I. ':)' E. y
assert. starts -:&# ends
assert. (-: /:~) ,starts,.ends
befores=. ~. (starts (+ i.)&.> 2+ends-starts) {&.> <y
afters=. interp_fmt@do@}.@}.@}:@}:&.> befores
rplc&(befores,.afters) y
)
Example use:
interp 'Example: (: i.3 3 :) ...'
Example: 0 1 2
3 4 5
6 7 8 ...
(though usually, I'd be using this with a 0 :0 delimited string, and
usually the executed expressions would be name references.)
Anyways, ... just in case anyone else has some need for some
simplistic text manipulation... this might be slightly useful.
FYI,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm