As part of this problem, I've been looking for a nice J phrase to remove all the letters in word from another repeat, without ignoring repeats. That is removing THERE from SEVENTEEN for example should result in SVNEEN. This means set difference can't be used. My current solution is labored: <"0@[ (<^:3@i. { [) ::[~&.>/@, <@].
Yes I'd guess so. Let me add a couple intermediate steps to clarify. Although I think I may have found another approach (still seeing if it leads to less code though...)
So in the general pattern, all the items on the left (in this case, the individual letters) are what we're reducing, and the item on the right is the result. J's right to left evaluation naturally produces the reduction, so that the "reduction" operation is just a consequence of the "Insert" adverb /
{ is probably the single most complicated verb in J, and that box within a box pattern is how you achieve "complement of". Nuvoc has better examples than the dictionary for that, if you're ever curious to explore more: code.jsoftware.com/wiki/Vocabulary/curlylf#dyadic
Also, Dan Bron's essay on its history and motivation and differences from APL's [] indexing operator is required reading.
@ngn exactly, that's try catch. and it will return [ which is the left arg, but since we're using ~ to modify the whole thing the left arg is the right arg visually, ie, the result on the right :)
my real question is if there's a completely different high-level approach that's more suited to "array thinking." reductions are really rather procedural things... but i still haven't found any other approach that works here.
@ngn Indeed there is /. -- I fiddled with that a bit but didn't find anything better going that route. Which ofc doesn't mean there isn't something better that route...
@Jonah {}⌸A groups the elements of A and applies the {} to each group - ⍺ is the element, ⍵ is the list of indices where it occurs. the result from ⌸ is mixed
@dzaima that's shorter than mine and looks more promising
The significant chars there could be golfed down a little, but that's basically the J translation. Intersect is J is built up from other primitives: e. # [
This approach def improves on my original. Thanks again.