[erlang-bugs] Lists module funnies

Zvi <>
Sun Nov 11 11:53:40 CET 2007


This is what I get in Matlab:

>> 1:0

ans =

   Empty matrix: 1-by-0

Anyway, I missing some Matlab-like syntactic sugar, this will be especially
usefull in list comprehensions:

>> 1:10

ans =

     1     2     3     4     5     6     7     8     9    10

>> 10:-1:1

ans =

    10     9     8     7     6     5     4     3     2     1

>> 0:0.1:1

ans =

         0    0.1000    0.2000    0.3000    0.4000    0.5000    0.6000   
0.7000    0.8000    0.9000    1.0000


Since ":" has special meaning in Erlang, as separator between module and
function names, we can use "..", this is similar to range in Pascal/Ada.
This might be implented as operator  erlang:'..'/2 or erlang:'..'/3 

From..To  == lists:seq(From,To)
   or   
From..Step..To == lists:seq(From,To,Step)

except, that lists:seq doesn't support floats.
Then calculating Multiplication table will look like this:

Table = [{N,M,N*M} || N<-1..10, M<-1..10].

Can this be implemented in R12 ?

Thanks in advance
Zvi



John Hughes-7 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
> 
> http://www.erlang.org/mailman/listinfo/erlang-bugs
> 
> 

-- 
View this message in context: http://www.nabble.com/Lists-module-funnies-tf4782240.html#a13690246
Sent from the Erlang Bugs mailing list archive at Nabble.com.




More information about the erlang-bugs mailing list