Improving Erlang!

Gilberio Carmenates García co7eb@REDACTED
Wed Dec 1 18:34:55 CET 2010


Hi all!

 

Things like this could be nice in Erlang

 

start(Type, Args)->

ChkArg = fun(Arg)->

case lists:keyfind(Arg, 1, StartArgs) of

{Arg, true}->

true;

_->

false

end

end,

                if

                               ChkArg(install)->

                                               ?MODULE:install();

                               ChkArg(debug)->

                                               appmon:start();

                               true->

                                               %% Starts the application.

 
evo_debug_module:print([{debug, true}], "~n~nApplication: \"~p\" is
starting...~n", [?MODULE]),

 
evo_debug_module:print([{debug, true}], "~nType: ~p   StartArgs: ~p~n",
[Type, StartArgs]),

                                               R =
evo_main_supervisor:start_link(StartArgs),

 
evo_debug_module:print([{debug, true}], "~nApplication: \"~p\" is ready.~n",
[?MODULE]),

                                               R

                end.

 

But that is impossible since the ‘if’ clause only work with guards, so since
we can not define our own guards that and many other limitations can come
up.

 

Other nice example of the Erlang limitations could be

 

get(Name)->

MatchHead = #t_char{name='$1', _='_'},

                Guard = {'user_define_compare/2', '$1', Name},       %%
instead of {'==', '$1', Name}

                Result = '$_',

                mnesia:dirty_select(t_char,[{MatchHead, [Guard],
[Result]}]).

 

Or

 


 when are_approximately_equals(Name, Name2) ->
             %% if I want to
Search a name in a list, that I don’t know exactly what name is
 could be in
the list Iván Carmenates García and I search by Ivan Garcia
 if the names
are in the database then using just mnesia:select/3 or match I can do that
in just almost one step, since I used my own user defined compare that
validates the approximately match between the real full name and the part of
the name I introduced.

  

 

 

Regards,

 

 

Ivan.



=======================================================================
Este mensaje ha sido enviado mediante el servicio de correo electrónico que ofrece la Federación de Radioaficionados de Cuba a sus miembros para respaldar el cumplimiento de los objetivos de la organización y su política informativa. La persona que envía este correo asume el compromiso de  usar el servicio a tales fines y cumplir con las regulaciones establecidas.


More information about the erlang-questions mailing list