[erlang-questions] Versioned variable names

David Mercer <>
Tue Jun 9 21:58:57 CEST 2009


How about using list comprehensions to reassign variables?  E.g.:

	MO = hd([MO || MO <- [re:replace(MO, "_", "-", [{return, list},
global])],
				   MO <- [toupper(MO)],
				   % Replace zeros
				   MO <- [re:replace(MO, "RX0", "RXO",
[{return, list}, global])],
				   % Insert hyphen if missing
				   MO <- [case re:run(MO, "-", [{capture,
none}]) of
							 nomatch ->
insert_hyphen(MO);
							 match -> MO
						 end]),
> -----Original Message-----
> From:  [mailto:] On
> Behalf Of Attila Rajmund Nohl
> Sent: Tuesday, June 09, 2009 10:13 AM
> To: erlang-questions
> Subject: [erlang-questions] Versioned variable names
> 
> 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



More information about the erlang-questions mailing list