The only hacky part is that you have included a list inside your verb.
If you just wanted indices:
findI =. (I.leaf @:<@:E.)"0 1
('a';'b';'q') findI ('a';'b';'z';'c';'a';'q')
┌───┬─┬─┐
│0 4│1│5│
└───┴─┴─┘
if that seems noisy to you, consider:
('a';'b';'q') (I.)"0 1 ('a';'b';'z';'c';'a';'q')
0 1 1 1 0 1
1 0 1 1 1 1
1 1 1 1 1 0
E. is basically -.@:I, here. if you haven't used it before.
----- Original Message -----
Is there a better way to find indices of a subset within a greater list?
This is my hacky solution
find=.('a';'b';'q')
list=.('a';'b';'z';'c';'a';'q')
] (; > L:0 (3 : '(<y) ([: I. =) list' ) each find) { list
┌─┬─┬─┬─┐
│a│a│b│q│
└─┴─┴─┴─┘
find xxx list
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm