[erlang-questions] Versioned variable names

Paul Mineiro paul-trapexit@REDACTED
Tue Jun 9 17:48:24 CEST 2009


I like the foldl way:

------
lists:foldl (fun (Fun, Acc) -> Fun (Acc) end,
             M0,
             [ fun (X) -> re:replace (X, "_", "-", [ { return, list }, global ]) end,
               fun to_upper/1,
               fun (X) -> re:replace (X, "RX0", "RX0", [ { return, list }, global ]) end,
               fun (X) -> case re:run (X, "-", [ { capture, none } ]) of
                                     nomatch ->
                                          insert_hyphen (X);
                                     match ->
                                          X
                                 end
               end ]).
------

Cheers,

-- p


On Tue, 9 Jun 2009, Attila Rajmund Nohl wrote:

> Hello!
>
> I think there wasn't any grumbling this month about the immutable
> local variables in Erlang, so here's real world code I've found just
> today:
>
>     % Take away underscore and replace with hyphen
>     MO1 = re:replace(MO, "_", "-", [{return, list}, global]),
>     MO2 = toupper(MO1),
>     % Replace zeros
>     MO3 = re:replace(MO2, "RX0", "RXO", [{return, list}, global]),
>     % Insert hyphen if missing
>     MO5 = case re:run(MO3, "-", [{capture, none}]) of
> 	      nomatch ->
> 		  insert_hyphen(MO3);
> 	      match ->
> 		  MO3
> 	  end,
>
> I think it's fairly clumsy to use MOx (MO for managed object) in the
> code. MO4 was removed during the regexp->re refactoring step. How to
> eliminate the versioned variable names? The
> MOAfterUnderscoresWereReplaced, UpperCaseMO, MOAfterRX0WasReplaced,
> etc. variablenames are really ugly. It used to use regexp, so at that
> point it wasn't possible to easily nest the whole into one call, but
> that would be still ugly. So any other ideas?
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>

Well for these men if they succeed; well also, though not so well, if
they fail, given only that they have nobly ventured, and have put forth
all their heart and strength.

        -- Theodore Roosevelt


More information about the erlang-questions mailing list