[erlang-questions] lists:seq/[2,3] bug?

David Mercer dmercer@REDACTED
Thu Sep 18 17:07:32 CEST 2008


Zvi wrote:
> 2. I'm all about common sence, and behaviour we expect must be consistent
> with similar constructs in other languages from Basic to Matlab.
> Python's   "range([start,] stop [,step]) -> list of integers"  construct
> is
> not a good example, b/c "stop" isn't included (which is counter-intuitive)
> and it's also defined only on integers. See example at the end of the
> message.

I can't speak for Python, but I disagree that it is counterintuitive.  I
often expect ranges to include the lower bound but exclude the upper bound.
Granted, these are typically continuous ranges, such as dates: e.g., if I
want to query a database for all transaction for the week of September 1, I
specify the range from September 1 to September 1+7.  Since the range
excludes the upper bound, September 8, I have a correct specification.

If anything, I find including the upper bound counterintuitive.  Take any
arbitrary values of start, stop, and step: does the sequence include the
stop or not?  You can't know because it does when (stop - start) mod step ==
0, but otherwise it does not.  I'd say, to be consistent, we should exclude
the stop, but that probably really would break some people's code...

Cheers,

David




More information about the erlang-questions mailing list