Erlang Mailing Lists

Author Message

<  Erlang questions mailing list  ~  Getting the position of a list item

rvirding
Posted: Thu Dec 03, 2009 2:48 pm Reply with quote
User Joined: 30 Aug 2006 Posts: 452 Location: Stockholm, Sweden
2009/12/3 Garrett Smith <g@rre.tt>

> On Wed, Dec 2, 2009 at 7:23 PM, Ngoc Dao <ngocdaothanh@gmail.com> wrote:
> >> string:str(List, [Element]).
> >
> > What a surprise! Thank you.
>
> A good example of "most astonishment" Smile
>

Unfortunately they have added som type checking in string otherwise you
could do string:chr(List,Element). Sad

Robert


Post received from mailinglist
View user's profile Send private message Visit poster's website MSN Messenger
Guest
Posted: Thu Dec 03, 2009 3:49 pm Reply with quote
Guest
2009/12/2, Tim Fletcher <twoggle@gmail.com>:
>> Hmm, I fail to come up with a good usage scenario for wanting this. What
>> are
>> you needing the position of an item in a list for?
>
> FWIW, here's something i wrote recently:
>
> base32_decode(Char) ->
> list_index(Char, base32_alphabet()).
>
> base32_alphabet() ->
> "0123456789bcdefghjkmnpqrstuvwxyz".

I usually see code like this implemented like this:

base32_decode2(Char) when Char>=$0, Char=<$9 ->
Char-47;

base32_decode2(Char) when Char>=$b, Char=<$h ->
Char-87;

base32_decode2(Char) when Char>=$j, Char=<$k ->
Char-88;

base32_decode2(Char) when Char>=$m, Char=<$n ->
Char-89;

base32_decode2(Char) when Char>=$p, Char=<$z ->
Char-90.

It (ab)uses the fact that we're latin-1 (effectively ASCII) charset.
The other kind of code I usually see for this kind of task contains
one function clause for each possible inputs. I don't know, but I
think both approaches are faster than traversing the list with
string:str/2. Probably binaries could be used instead of lists to
speed up indexing.

________________________________________________________________
erlang-questions mailing list. See http://www.erlang.org/faq.html
erlang-questions (at) erlang.org

Post received from mailinglist
Guest
Posted: Thu Dec 03, 2009 9:51 pm Reply with quote
Guest
> I usually see code like this implemented like this:
>
> base32_decode2(Char) when Char>=$0, Char=<$9 ->
>
wuji
Posted: Thu Sep 13, 2012 8:10 am Reply with quote
User Joined: 10 Aug 2012 Posts: 654
even by some very close family members, though."That was bad because they they cheap authentic air jordans they loved me and I loved them," she said. "And they didn't
me in the house."She said that wanting to be accepted for who who cheap jordan shoes who she is drove her to come out on television that year
Jerry Falwell, Pat Robertson and other members of the evangelical community who who cheap designer *beep* who said they were disappointed. Some called her "Ellen Degenerate.""You know Ellen
such a good person," her mother said. "Now, I don't want to to cheap polo shirts to get weepy, I don't, but she's so good that she shouldn't
all this directed at her."Today Betty DeGeneres fights for gay rights. She She [h1]designer replica *beep*[/h1] She is devoted and always tolerant.Bill Clinton Boosts President Obama - So
George W. Bush for Mitt Romney?2 Prior Presidents Take Dramatically Different Approaches Approaches cheap Ralph Lauren Polo Approaches to 2012 CampaignBy JOEL SIEGELMay 4, 2012 — He was once
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 2 of 2
Goto page Previous  1, 2
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum