1. 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
2. Re: in_range()
- Posted by Michael Nelson <mike-nelson-ODAAT at WORLDNET.ATT.NET> Jun 11, 1999
- 383 views
- Last edited Jun 12, 1999
------=_NextPart_000_002E_01BEB44E.0575AF40 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I like David's idea for this function, but think that Gabriel's type = idea has merit also. If the latter approach is used, how about: global type index_value(sequence x) --x[1] is the index, x[2] is the = sequence return x[1]>0 and x[1]<length(x[2]) end type --Mike Nelson ------=_NextPart_000_002E_01BEB44E.0575AF40 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT color=3D#000000 size=3D2>I like David's idea for this = function, but think=20 that Gabriel's type idea has merit also. If the latter approach is = used,=20 how about:</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>global type index_value(sequence = x) --x[1]=20 is the index, x[2] is the sequence</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2> return x[1]>0 = and=20 x[1]<length(x[2])</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2>end type</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>--Mike = ------=_NextPart_000_002E_01BEB44E.0575AF40--