[erlang-questions] removing an element from a list

Ivan Uemlianin ivan@REDACTED
Tue May 3 11:27:56 CEST 2011


Thanks!

I think I might switch to the longhand version for readability (not to 
mention I've been subtracting all this time when I should have been 
deleting).

Ivan


On 03/05/2011 10:15, Mazen Harake wrote:
> They are equally "good".
>
> A -- [q] says "remove all occurrences found in the right list from the 
> left list". This is sugar syntax for lists:subtract/2. A -- [q,w] 
> would produce [e,r,t,y].
> lists:delete(q, A) says remote element q from list A (note: only one 
> element).
>
> The simple answer is: They are almost the same. if you only want to 
> remove 1 element the list then use delete, if you want to remove 
> several then use subtract.
>
> note: both functions only remove the first occurrence of the element, 
> E.g. [a,a,b,c] -- [a] will result in [a,b,c] and _not_ [b, c], same 
> behaviour for delete.
>
> /M
>
> On 3 May 2011 11:04, Ivan Uemlianin <ivan@REDACTED 
> <mailto:ivan@REDACTED>> wrote:
>
>     Dear All
>
>     It seems there are two ways to remove an element from a list:
>
>       1> A = [q,w,e,r,t,y].
>       [q,w,e,r,t,y]
>       2> A -- [q].
>       [w,e,r,t,y]
>       3> lists:delete(q, A).
>       [w,e,r,t,y]
>       4>
>
>
>     Which is better, and why, or is TMTOWTDI?  (I'm sure the answer
>     won't be as simple as the question:).
>
>     With thanks and best wishes
>
>     Ivan
>
>     -- 
>     ============================================================
>     Ivan A. Uemlianin
>     Speech Technology Research and Development
>
>     ivan@REDACTED <mailto:ivan@REDACTED>
>     www.llaisdy.com <http://www.llaisdy.com>
>     llaisdy.wordpress.com <http://llaisdy.wordpress.com>
>     www.linkedin.com/in/ivanuemlianin
>     <http://www.linkedin.com/in/ivanuemlianin>
>
>        "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
>                         (Schiller, Beethoven)
>     ============================================================
>
>     _______________________________________________
>     erlang-questions mailing list
>     erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development

                     ivan@REDACTED
                      www.llaisdy.com
                          llaisdy.wordpress.com
                      www.linkedin.com/in/ivanuemlianin

     "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
                      (Schiller, Beethoven)
============================================================




More information about the erlang-questions mailing list