[erlang-bugs] Lists module funnies

Torbjorn Tornkvist tobbe@REDACTED
Mon Nov 12 09:54:03 CET 2007


While on the topic, wouldn't it be nice with arithmetic sequences a la
Haskell?

Example:

[2,3..10]  =>  [2,3,4,5,6,7,8,9,10]

[2,1.8..1]  => [2,1.8,1.6,1.4,1.2,1]

The semantics is thus something like:

[a,b..c] => d=b-a, [a,a+d,a+d*2,a+d*3,..etc...] until a+d*X > c

Cheers, Tobbe


John Hughes wrote:
> What's the next element in this sequence?
> 
> 1> lists:seq(1,3).
> [1,2,3]
> 2> lists:seq(1,2).
> [1,2]
> 3> lists:seq(1,1).
> [1]
> 4> lists:seq(1,0).
> 
> I expect [], but what I get is:
> 
> =ERROR REPORT==== 10-Nov-2007::12:11:21 ===
> Error in process <0.30.0> with exit value:
> {function_clause,[{lists,seq,[1,0]},{
> erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
> 
> ** exited: {function_clause,[{lists,seq,[1,0]},
>                              {erl_eval,do_apply,5},
>                              {shell,exprs,6},
>                              {shell,eval_loop,3}]} **
> 
> I've worked around this more times than I can remember, special-casing the
> zero case to avoid calling seq, and I'll bet that many callers of seq have
> to do the same thing. Any chance of changing this in the future? There can't
> be much code that would break... code that only works today *because* seq
> raises an exception.
> 
> John Hughes
> 
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs
> 




More information about the erlang-bugs mailing list