Re: Last Element Reference
- Posted by jbrown105 at speedymail.org Sep 21, 2003
- 481 views
On Sun, Sep 21, 2003 at 07:15:20AM +1000, Derek Parnell wrote: <snip> > -- Build list. > for i = 1 to length(s) do > rid = routine_id(funcA(s[i])) > if rid > length(ridlist) then > ridlist &= repeat(-1, rid - length(ridlist)) > end if > ridlist[rid] = DefaultValues > end for > > . . . then later in program > > rid = routine_id(funcA(x)) > ridlist[rid] = UpdatedValues > . . . > > Okay, so here we have a program that stores some parameter values that are > indexed via the Routine_ID that they apply to. This works fine until we supply > the funcA() routine an unknown routine name. In that case it returns a -1. Now if > negative indexing were allowed, this would update the LAST parameter set rather > than causing an exception. Yes, its a bug and poor programming practice, but it > might take awhile to detect and to find. > > Although this is contrived, it is a realistic scenario. > > A similar situation could be set up for file handles returned by open() as > that uses -1 to signal an error too. In OE, we could do with negative_subscript_warning So then a warning would be generated whenever a negative subscript was encountered. We could be even more agressive and add a "warn_on_negative_subscript_use()" builtin which would make the interpreter flag a warning IMMEDIATELY when the negative subscript is used as opposed to at the end of the program. Also a "with negative_subscript_error_compat" to make it an error to use negative subscripts. This would be just another compat option with all the others we've already discussed in OE (and would of course be coverted by the ubqiuatous "with compat"). Naturally, none of this has a chance of making it to RDS Eu (would perhaps be too much of a headache to manage the compatibility issues for them perhaps?) but its still worth discussing, even if it only benifits OE> jbrown > > -- > Derek > > > Ok, so here is a piece of code that is supposed to do something with a element > of a sequence, but we don't know where abouts that portion starts until run time. > > > > TOPICA - Start your own email discussion group. FREE! > -- "Is there peace in heaven, or is that merely an illusion?" - Someone