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

Bob Ippolito bob@REDACTED
Thu Sep 18 16:44:18 CEST 2008


On Thu, Sep 18, 2008 at 3:21 AM, Zvi <exta7@REDACTED> wrote:
>
> Richard,
>
> 1. if you already dealing with it, can you also extend it to floats too?
> I.e. if step is float, then the resulting list must be floats too.
>
> -spec(seq/1 ::
>         (integer()) -> [integer()]).  % is. lists:seq(Max)  ==
> lists:seq(1,Max) == lists:seq(1,Max,1)
>
> -spec(seq/2 ::
>         (integer(),integer()) -> [integer()]).
> -spec(seq/2 ::
>         (integer(), float()) -> [integer()]).
> -spec(seq/3 ::
>         (integer(),integer(),integer()) -> [integer()]).
>
> -spec(seq/2 ::
>         (float(),integer()) -> [float()]).
>
> number = float() | integer()
>
> -spec(seq/3 ::
>         (number(),number(),float()) -> [float()]).
>
>
> 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.

The reason for this of course is that in almost all cases range is
done with one argument, just the stop, and when you call range(10) you
expect a list of length 10, not 11. The reason why it doesn't include
the end point is because start=0 by default which makes sense because
the index of the first element of a list is 0 in Python.

-bob



More information about the erlang-questions mailing list