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

Serge Aleynikov <>
Thu Nov 27 01:05:47 CET 2008


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("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]dave.smith.to@[2]gmail.com>
>>>
>>>    2008/11/26 Mazen Harake <[3]>
>>>
>>>      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. http://dave.smith.to/
>>>    2. http://gmail.com/
>>>    3. mailto:
>>> _______________________________________________
>>> erlang-questions mailing list
>>> 
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>> -- 
>> Michael McDaniel
>> Portland, Oregon, USA
>> http://autosys.us
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list