On Tue, Jan 13, 2009 at 1:20 PM, Viktor Cerovski
<[email protected]> wrote:
> The challenge now is to enhance ins0 so that it takes as argument not only
> fill position, but also fill element, using the technique of higher-order
> functions described so far.
In another language, adverbs and conjunctions might be called
compile time operations. They take action during the parsing of
a sentence, and that is where they are useful.
Here's a verb which works somewhat like ins0 (one difference is that
it takes its argument at run time). This is a somewhat complex
expression because I wanted it to work for arbitrarily dimensioned
arrays -- not just for matrices. But there might be simpler ways to
accomplish this:
insv=: [:>[: 1 0&|:@#&.>/ 1 ; <@] ,~ ((1 j. (= i.))&.> $)
Here is a version which uses an arbitrary fill number:
insf=: {:@[ + }:@[ insv ] - {:@[
Example use:
2 3 9 insf >:i.5 5
This relies on some properties of numbers, so arguments which
are not in that kind of domain will need to be mapped in
(and back out) for this to be used on them.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm