Erlang again!

Jilani Khaldi jilani@REDACTED
Thu Jul 22 13:28:07 CEST 2010


Hi All,
after a long time, here I am programming in Erlang again...
I have 2 lists:
L1=[1,2,3,4,5], L2=[1.1,2.2,3.3,4.4,5.5]
and I want to have a third list which is the difference of them:
L3=[
L2[1] - L1[1],
L2[2] - L1[2],
L2[3] - L1[3],
L2[4] - L1[4],
L2[5] - L1[5]
]
The result should be
L3=[0.1,0.2,0.3,0.4,0.5]

I have tried:

sub(L2,L1) -> [X2-X1||X1<-L1,X2<-L2].

but the result is so different from what I have excpected (the error due 
to floats calculation is not important).

[0.10000000000000009,1.2000000000000002,2.3,
  3.4000000000000004,4.5,-0.8999999999999999,
  0.20000000000000018,1.2999999999999998,2.4000000000000004,
  3.5,-1.9,-0.7999999999999998,0.2999999999999998,
  1.4000000000000004,2.5,-2.9,-1.7999999999999998,
  -0.7000000000000002,0.40000000000000036,1.5,-3.9,-2.8,
  -1.7000000000000002,-0.5999999999999996,0.5]

Any hint?
Thanks!

-- 
Jilani KHALDI
---------------------
http://www.iiiaugusta.com



More information about the erlang-questions mailing list