A DSP task in Erlang ?

Massimo Cesaro <>
Tue Jan 20 16:59:49 CET 2004


That was my first approach, actually.
But how can I support multiple lists ?
Sometimes I'll deal with 2 or 3 lists, sometimes with 6 or 8.

And does this have impacts on the garbage collection times, since the
function is not tail recursive ?

Thanks,
Massimo

On Tue, 2004-01-20 at 17:00, Fredrik Linder wrote:
> what about an ordinary function (or fun)?
> 
> sum([A|B],[C|D]) -> [A+C | sum(B,D)];
> sum([], []) -> [].
> 
> > -----Original Message-----
> > From: 
> > [mailto:]On Behalf Of Massimo Cesaro
> > Sent: den 20 januari 2004 16:14
> > To: Erlang mailing list
> > Subject: A DSP task in Erlang ?
> > 
> > 
> > Hi,
> > I'm trying to simulate a DSP operation in Erlang, but I have
> > difficulties in figuring out the best way to write it.
> > My aim is to be able to sum the contents of several lists, e.g.:
> > if A = [1,2,3], and B = [1,2,3] and C = [1,2,3], I'd like to 
> > findaa fast
> > end efficient way to get a resulting list summing the 
> > elements such as D
> > = [3, 6, 9], i.e. the first element of the result is the sum of the
> > first element of the lists, etc.
> > I checked with list comprehension, but I found that they are useful to
> > write generators rather than adders:
> > 
> > Erlang (BEAM) emulator version 5.2 [source] [hipe]
> > 
> > Eshell V5.2  (abort with ^G)
> > 1> A = [1,2,3].
> > [1,2,3]
> > 2> B=[1,2,3].
> > [1,2,3]
> > 3> C=[1,2,3].
> > [1,2,3]
> > 4> [X+Y+Z || X <- A, Y <- B, Z <- C].
> > [3,4,5,4,5,6,5,6,7,4,5,6,5,6,7,6,7,8,5,6,7,6,7,8,7,8,9]
> > 5>
> > 
> > clearly not what I need.
> > 
> > The "best way" I'm looking for is something that could be 
> > used in a soft
> > real time system. Given a fixed input length of lists, I'd 
> > like to have
> > a predictable and constant time of execution of the function.
> > Anybody have suggestions on this ?
> > Regards,
> > Massimo
> > 
> > 
> > 
> > 
> > 





More information about the erlang-questions mailing list