On Wed, Mar 25, 2009 at 7:34 AM, Steven Taylor <[email protected]> wrote:
> 3 i. (i. 5) index is useful. I wondered where the convention came from of
> having not found equal the # count of items (since all valid indexes are
> zero to n-1) came from?
I think it's because this way if y is not found in x, (y i. x) { x
would surely raise an exception. If not found was signaled by -1, you
would silently get the wrong event. However, if you do not want an
exception but a default element, you can just append that to the list
and then indexing gives that, eg. (y i. x) { x , z gives z if y is not
found. So the length is the only value that works both when you want
an error and when you want to substitute a default.
Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm