That convenience would also obtain (in J) if the 'not found' result were _1; and then the 'not found' entry would be known in advance and we wouldn't have to calculate it.
Henry Rich On 4/23/2012 5:28 PM, Devon McCormick wrote: > The convenience of index returning one more than the maximum is that > it allows you to put your null (or other default) value at the end of > your lookup vector, e.g. > > (Target,a:){~Source getIndex Target > +-+---+-++ > |a|bcd|e|| > +-+---+-++ > > or maybe you want > > (Source,a:){~Source i. Target > +-+-+---++ > |e|a|bcd|| > +-+-+---++ > > The last item is an empty vector because it's not found and that's the > extra item we put at the end. > > On Mon, Apr 23, 2012 at 7:35 AM, Henry Rich<henryhr...@nc.rr.com> wrote: >> Source =. 'a';'bcd';'e';'g' >> Target =. 'e';'a';'bcd';'f' >> getIndex =: i.~ NB. not e. >> shouldReturn =. 1 2 0 4 NB. 'not found' for i. is #x >> assert (Source getIndex Target)-:shouldReturn NB. -: not = >> >> Henry Rich >> >> On 4/23/2012 7:13 AM, Joe Bohart wrote: >>> Hi J'ers, >>> >>> I'm trying to write a verb that will >>> match the items in Source with Target >>> and return the index of items in Target >>> such that they are in the same order as >>> Source with nulls (or the J way of handling nulls) >>> if no match is found. >>> >>> This is what i have (and it's wrong): >>> >>> Source =. 'a';'bcd';'e';'g' >>> Target =. 'e';'a';'bcd';'f' >>> getIndex =: e. >>> shouldReturn =. 1 2 0 null >>> assert (Source getIndex Target)=shouldReturn >>> >>> In the forums I've found solution candidates,but >>> haven't been able to apply them and am a bit lost with: >>> I.@:E. and ;: >>> >>> The concept of expressing null or missing data in J I haven't >>> found much info on. Where can i find more information on nulls. >>> >>> Much Thanks -Joe >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm