Just as an example, here's how indexOf in J works:

           'ABCDEFGHIJKLMNABC' i. 'ADKz' 
        0 3 10 17

A few notes:

        -  The "universe of all things" (i.e. the source) is on the left, 
           the target is on the right

        -  You can look up multiple things simultaneously (go arrays!), 
           and you get one index per item looked up

        -  The indexes are valid nonnegative integer indexes into the 
           universe.  Note that 'z' was not found, so 17 was returned.
           If you tried to use 17 to pull data out of the universe, 
           you'd get an index (out of bounds) error.

        -  The universe can have repeated items.  The result will the
           lowest possible (for the highest possible, using i: instead
           of i.)

        -  The verb i. is generic.  It will work on characters, numbers,
           boxes, and higher-order arrays (so you can look up rows in a
           tables, tables in a cube, etc)

-Dan


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of R.E. Boss
Sent: Thursday, August 18, 2011 6:59 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] indexOf for arrays

For primitives, check the Vocabulary
http://www.jsoftware.com/help/dictionary/vocabul.htm
Actually, always check the Vocabulary (first).


R.E. Boss


> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens Gregory Nisbet
> Verzonden: donderdag 18 augustus 2011 9:29
> Aan: [email protected]
> Onderwerp: [Jprogramming] indexOf for arrays
> 
> I'm new to J and am curious about the existence of a primitive with
> functionality similar to indexOf in Java. I've checked the dictionary,
Learning J,
> and J for C programmers and haven't been able to locate the primitive that
> does this. Thus, I figure I should ask the community.
> 
> Much obliged,
> Gregory Nisbet
> ----------------------------------------------------------------------
> 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

Reply via email to