optimization ?
Ingela Anderton
ingela@REDACTED
Tue Apr 22 11:05:12 CEST 2003
Bengt Kleberg wrote:
>
> > Date: Tue, 22 Apr 2003 01:09:11 -0500
> > From: Chris Pressey <cpressey@REDACTED>
> > Subject: Re: optimization ?
> ...deleted
> > expensive compared to a simple cons. You might want to try [T|Acc]...
> >
> > > end;
> > > Other ->
> > > dirs(Top, Tail, Acc)
> > > end;
> > >
> > > dirs(_Top, [], Ack) -> Ack.
> >
> > ...then lists:flatten/1 the result here before you return it, if you
>
> are you sure?
> i tried this (but might have made a mistake) and the result i got was 1
> single (long) string.
> the original result, a list of strings, is much more readable.
>From the efficency guide:
When you have a deep list of depth 1 you can flatten it using append/1
[...]
NOTE: If your deep list is a list of strings you will not get the wanted result using flatten. Remember that strings are lists. See example below:
> lists:append([["foo"], ["bar"]]).
["foo","bar"]
> lists:flatten([["foo"], ["bar"]]).
"foobar"
--
/m.v.h Ingela
//The highway of life is always under construction. //
|\ _,,,--,,_ ,)
/,`.-'`' -, ;-;;'
|,4- ) )-,_ ) /\
'---''(_/--' (_/-'
Ericsson AB - OTP team
Cellular/Mobile: +46 70 636 78 68
More information about the erlang-questions
mailing list