From: Hideo B. <ba...@im...> - 2003-04-14 04:10:54
|
Hello list, At Sun, 13 Apr 2003 19:04:17 -0700, Blair Zajac wrote: > > Nicolas Cannasse wrote: > > > > If (-1) make some sense, I'm not so sure about (-2) and (-3) :-) > > So I would prefer an explicit get_last x that is perhaps less confusing to > > code readers. > > I have no problem with the -1, -2, -3, etc usage and find is very > understandable. I haven't heard any complaints from Perl users on > this usage. I can imagine why Perl users wouldn't complain about this, but as an OCaml user, I think I will :-). I can see that there would be no problem if the index is written explicitly as -1, -2, -3, etc. However, I don't like the idea because it essentially overrides (to some extent) the very useful array bounds checking that OCaml provides, and could `hide' bugs when variables are used as the index. Maybe it's just me, but I often (er, at least sometimes?) find myself writing code like: let index = x - y + i in do something with (Array.get array index) where x, y and i move around in a complex way, and the problem is that I sometimes forget to do +1 somewhere, and end up getting a negative value as index (but is found easily since it raises an exception!). So I would very much like to have the function which doesn't allow negative indices to be kept (preferably leaving the name as [get], so as not to confuse users of standard arrays). If we must have a [get] with negative indices, it should be a different function. What do you think? Regards, -- Hideo Bannai <ba...@im...> |