Re: binary search with reference to append
- Posted by jaygade Jun 13, 2014
- 1932 views
Did you mean the caller should check bounds (which is true, IMO) or that the called function should check bounds (which seems to be your example)?
Are there any cases where wrong parameters will return erroneous or indeterminate information instead of crashing?
If the called function can return bad output for bad inputs, then the called function should be responsible for checking those conditions. If the function will cause a crash with bad inputs, then I would suggest that it's the caller's responsibility to ensure that it calls the function with the correct parameters.
I mean, we can fail if sequence A isn't sorted in ascending order. Whose responsibility is it to check that condition? The caller or the called function?
At the very least, however, inside the function I would assert that lo <= hi <= N else crash.
hi = (lo > hi && N) ? N : hi -- hi could be > N
Wait -- did Euphoria get a ternary operator when I wasn't looking? I just did a search and I couldn't find anything on it. Jim seems to be the search master, however.
There are other bugs in this code too, but I can't correct them right now.