[erlang-questions] [correction] Re: Additions to lists module

Michael McDaniel erlangy@REDACTED
Thu Nov 27 07:43:57 CET 2008


 Thanks, Serge, for reminding me of lists:splitwith/2 - I had looked at
 it once and did not pursue using it but am again playing with it.

~Michael

On Wed, Nov 26, 2008 at 10:22:40PM -0500, Dave Smith wrote:
>    Yes, exactly. not only is splitwith/2 simpler, it only requires the
>    list to be traversed once.
> 
>    2008/11/26 Serge Aleynikov <[1]saleyn@REDACTED>
> 
>      Actually for this problem lists:splitwith/2 would do a better job.
> 
>    Michael McDaniel wrote:
>    > On Wed, Nov 26, 2008 at 03:52:15PM -0800, Michael McDaniel wrote:
>    >>  Everyone works on different kinds of problems and has their
>    solutions.
>    >>  One immediate use I thought of follows.
>    >>
>    >>  Note that html_tokenise is from Joe Armstrong's www_tools-1.0 on
>    trapexit.
>    >>
>    >>
>    >>  {ok, H} = http:request("[2]http://somewebsite.com") ,
>    >>  Ht      = html_tokenise:string2toks( element(3, H) ) ,
>    >>  Pos     = list_position:pos( Hal, {tagStart,"title"} ) ,
>    >>
>    >>  {_, Title} = lists:nth( Pos+1, Hal ).
>    > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    >
>    >       Pos     = list_position:pos( Ht, {tagStart,"title"} ) ,
>    >    {_, Title} = lists:nth( Pos+1, Ht ).
>    >
>    >
>    >  of course, should be Ht for these
>    >
>    > ~M
>    >
>    >
>    >>  Likely there are other interesting items on a page for which I
>    >>  would have interest.
>    >>
>    >>
>    >> ~Michael
>    >>
>    >>
>    >>
>    >> On Wed, Nov 26, 2008 at 06:31:11PM -0500, Dave Smith wrote:
>    >>>    But I do agree with you on the pos function. I don't think I
>    would uses
>    >>>    it. Presumably one would want to do something with the position
>    after
>    >>>    retrieving it, and this would probably mean using it in a
>    function that
>    >>>    traverses a list a second time.
>    >>>    It would be more appropriate in a module like array.
>    >>>
>    >>>    2008/11/26 Dave Smith <[1][3]dave.smith.to@[2][4]gmail.com>
>    >>>
>    >>>    2008/11/26 Mazen Harake
>    <[3][5]mazen.harake@REDACTED>
>    >>>
>    >>>      What is the idea behind pos?
>    >>>      Curious because I have never been in a situation where I need
>    to
>    >>>      know
>    >>>      the actual position of an element since I always assume that
>    the
>    >>>      order
>    >>>      in a list is always undefined. Perhaps I missed something...
>    do you
>    >>>      have
>    >>>      a practical example?
>    >>>      /M
>    >>>
>    >>>      I'm not following. Lists are ordered and in many cases order
>    is
>    >>>      meaningful.  Otherwise you would never have reason to reverse
>    a
>    >>>      list.
>    >>>      There are many functions in the lists module where the result
>    is
>    >>>      dependant on the lists order, and there is precedence for
>    functions
>    >>>      like foldlwhile; examples (takewhile/2, dropwhile/2,
>    splitwith/2)
>    >>>
>    >>> References
>    >>>
>    >>>    1. [6]http://dave.smith.to/
>    >>>    2. [7]http://gmail.com/
>    >>>    3. mailto:[8]mazen.harake@REDACTED
>    >>> _______________________________________________
>    >>> erlang-questions mailing list
>    >>> [9]erlang-questions@REDACTED
>    >>> [10]http://www.erlang.org/mailman/listinfo/erlang-questions
>    >> --
>    >> Michael McDaniel
>    >> Portland, Oregon, USA
>    >> [11]http://autosys.us
>    >>
>    >> _______________________________________________
>    >> erlang-questions mailing list
>    >> [12]erlang-questions@REDACTED
>    >> [13]http://www.erlang.org/mailman/listinfo/erlang-questions
>    > _______________________________________________
>    > erlang-questions mailing list
>    > [14]erlang-questions@REDACTED
>    > [15]http://www.erlang.org/mailman/listinfo/erlang-questions
>    >
>    _______________________________________________
>    erlang-questions mailing list
>    [16]erlang-questions@REDACTED
>    [17]http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> References
> 
>    1. mailto:saleyn@REDACTED
>    2. http://somewebsite.com/
>    3. http://dave.smith.to/
>    4. http://gmail.com/
>    5. mailto:mazen.harake@REDACTED
>    6. http://dave.smith.to/
>    7. http://gmail.com/
>    8. mailto:mazen.harake@REDACTED
>    9. mailto:erlang-questions@REDACTED
>   10. http://www.erlang.org/mailman/listinfo/erlang-questions
>   11. http://autosys.us/
>   12. mailto:erlang-questions@REDACTED
>   13. http://www.erlang.org/mailman/listinfo/erlang-questions
>   14. mailto:erlang-questions@REDACTED
>   15. http://www.erlang.org/mailman/listinfo/erlang-questions
>   16. mailto:erlang-questions@REDACTED
>   17. http://www.erlang.org/mailman/listinfo/erlang-questions

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us




More information about the erlang-questions mailing list