[erlang-questions] prettypr and spec

Roberto Ostinelli roberto@REDACTED
Tue Sep 25 06:00:00 CEST 2012


I have this code:

%%%%%%%%%%%%%%%%%%%%%%%%
-module(mymodule).
-export([hello/0, goodbye/0, greetings/1]).

-spec hello() -> string().
hello() ->
greetings("hello").

-spec goodbye() -> string().
goodbye() ->
greetings("goodbye").

-spec greetings(Text::string()) -> string().
greetings(Text) ->
lists:flatten(io_lib:format("~s sublimerl", [Text])).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

simple_test() ->
?assertEqual("hey sublimerl", greetings("hey")).

greetings_test_() ->
[?_assertEqual("hey sublimerl", greetings("hey"))].

-endif.
%%%%%%%%%%%%%%%%%%%%%%%%


when i convert it using this:


%%%%%%%%%%%%%%%%%%%%%%%%
Formatted = case epp_dodger:parse_file(FilePath) of
{ok, Forms} ->
case lists:keymember(error, 1, Forms) of
false ->
erl_prettypr:format(erl_recomment:recomment_forms(Forms,
erl_comment_scan:file(FilePath)));
true ->
""
end;
{error, _} ->
""
end
%%%%%%%%%%%%%%%%%%%%%%%%


I get:

%%%%%%%%%%%%%%%%%%%%%%%%
-module(mymodule).

-export([hello/0, goodbye/0, greetings/1]).

-spec({{hello, 0},
       [{type, 4, 'fun',
 [{type, 4, product, []}, {type, 4, string, []}]}]}).

hello() -> greetings("hello").

-spec({{goodbye, 0},
       [{type, 8, 'fun',
 [{type, 8, product, []}, {type, 8, string, []}]}]}).

goodbye() -> greetings("goodbye").

-spec({{greetings, 1},
       [{type, 12, 'fun',
 [{type, 12, product,
   [{ann_type, 12,
     [{var, 12, 'Text'}, {type, 12, string, []}]}]},
  {type, 12, string, []}]}]}).

greetings(Text) ->
    lists:flatten(io_lib:format("~s sublimerl", [Text])).

-ifdef(TEST).

-include_lib("eunit/include/eunit.hrl").

simple_test() ->
    ?assertEqual("hey sublimerl", (greetings("hey"))).

greetings_test_() ->
    [?_assertEqual("hey sublimerl", (greetings("hey")))].

-endif.
%%%%%%%%%%%%%%%%%%%%%%%%


What happens to spec? What is the best way to use an erlang auto-formatter?

Any input welcome.

r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120924/6cc7fda1/attachment.htm>


More information about the erlang-questions mailing list