in_range()
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> Jun 11, 1999
- 406 views
Here's a suggested addition to MISC.E - a function that returns TRUE if an index is in the range of a sequence: in_range( index, sequence ) Now, if you're like me, you're probably thinking that this is too trivial to warrant a new function - just write: if index > length( s ) then ... bad index which is exactly what I have all over my code. But the test lets negative numbers slip by, which is a Bad Thing. The new function does the test correctly, and it's clear what the intent is: if not in_range( index, s ) then ... bad index I'm suggesting that it be added to MISC.E because it's such a common test, and it would produce safer code as a result. -- David Cuny