2017-10-03 4 views
2

は考えてみましょう:特定のインデックスで囲み、リストの内容に動詞を適用

(,&' world' adjust 1) xs 

を生成します:

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

は、私が adjustよう 暗黙組み合わせを求めます

私は他のアプローチにも適しています。またはこの問題。

答えて

2

私は、接続詞ではなく動詞の引数を使用して結果を作成する別の方法を採用しました。私は引数を比較的調整可能に保つことができ、構造を変更することなく操作するのが簡単です。これは、選択されるボックスが左の引数であり、ボックスのリストが左の引数であり、追加される接尾辞が動詞に埋め込まれているダイアディック動詞を作成することによってこれを行います。

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

完全にプリミティブな暗黙のバージョンは、このように見えます。

0 (] ,each ('';' there') {~ (= [email protected]#)) xs 
+--------+-----+---+ 
|hi there|hello|foo| 
+--------+-----+---+ 
関連する問題