将动词应用于特定索引处的盒装列表的内容

时间:2017-10-03 14:51:01

标签: j

考虑:

   [xs=. 'hi';'hello';'foo'
┌──┬─────┬───┐
│hi│hello│foo│
└──┴─────┴───┘

我寻找默认连词adjust,以便:

(,&' world' adjust 1) xs

产生

┌──┬───────────┬───┐
│hi│hello world│foo│
└──┴───────────┴───┘

如果他们更适合这个问题,我也会接受其他方法。

1 个答案:

答案 0 :(得分:2)

我确实采用了一种不同的方法,用动词而不是连词来创建结果。我能够保持参数相对可调,以便在不改变结构的情况下易于操作。我这样做是通过创建一个二元动词,其中要选择的方框是左参数,方框列表是左参数,要添加的后缀嵌入动词中。

   suffix=.''&;
   1 (] ,each (suffix ' world') {~ (= i.@#)) xs
+--+-----------+---+
|hi|hello world|foo|
+--+-----------+---+
   2 (] ,each (suffix 'die') {~ (= i.@#)) xs
+--+-----+------+
|hi|hello|foodie|
+--+-----+------+
   0 (] ,each (suffix ' there') {~ (= i.@#)) xs
+--------+-----+---+
|hi there|hello|foo|
+--------+-----+---+

完全原始的默会版本可能如下所示。

   0 (] ,each ('';' there') {~ (= i.@#)) xs
+--------+-----+---+
|hi there|hello|foo|
+--------+-----+---+