insertbefore=:{{
'a b'=. y
(x{.b),a,x}.b
}}
insertafter=: {{ (x+1) insertbefore y }}
2 insertafter "1 [ 10;"1 n
0 1 2 10 3 4
5 6 7 10 8 9
FYI,
--
Raul
On Tue, Jan 19, 2021 at 11:51 AM Skip Cave <[email protected]> wrote:
>
> How does one design a verb that inserts specific elements into a vector or
> matrix?
>
> For example, an "insertafter" verb would take one left argument, which is
> the index of the array that the element is to be inserted after. The right
> argument would be two boxed nouns. The first boxed noun is the set to be
> inserted. The second boxed noun is the destination of the insertion.
>
> 2 insertafter 10;1 2 3 4 5
>
> 1 2 3 10 4 5
> 2 insertafter 10 11;1 2 3 4 5
> 1 2 3 10 11 4 5
>
> Also may need insertbefore:
> 2 insertbefore 10;1 2 3 4 5
>
> 1 2 10 3 4 5
> 2 insertbefore 10 11;1 2 3 4 5
> 1 2 10 11 3 4 5
>
> Higher ranks?
>
> ]n=.2 5$i.10
>
> 0 1 2 3 4
>
> 5 6 7 8 9
>
> 2 insertafter "1 [ 10;n
>
> 0 1 2 10 3 4
>
> 5 6 7 10 8 9
>
>
> What would the code for insertbefore verb look like?
>
>
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm