[erlang-questions] dialyzer output help

Roelof Wobben r.wobben@REDACTED
Mon Aug 10 14:00:08 CEST 2015


Hello,

I try to document this function which I found on another topic.

%% @author Roelof Wobben <r.wobben@REDACTED>
%% @doc Function to calculate the area of a rectangle, a ellipse or a 
triangle
%% @reference from <a href= 
"http://shop.oreilly.com/product/0636920025818.do" >Introducing Erlang</a>,
%% O'Reilly Media, Inc., 2012.
%% @copyright 2012 by R.Wobben
%% @version 0.1

-module(ask_area).

-export([area/0]).

-spec(area() -> 'ok' | 'error').

%% @doc a function which looks if the function collect_data
%% outputs a number which resambles the area of the shape the
%% user has choosen with the dimensions which the user has entered
%% if the user entered a wrong shape or not a number on the dimension
%% part , there will be a right error message to tell what went wrong

area() ->
     try collect_data() of
         Area -> io:format("The area is ~p~n", [Area])
     catch
         error:Err -> io:format("~s~n", [error_msg(Err)])
     end.

-spec(collect_data() -> number() ).

%% doc Function which controls the programm.
%% First the shape is asked on the user.
%% After that if a valid shape is entered the dimensions
%% are asked , and if they are valid the area is being calculated.

collect_data() ->
     Shape = shape_from_user(),
     {X, Y} = dimensions_from_user(Shape),
     geom:area(Shape, X, Y).



-spec (shape_from_user() -> 'ellipse' | 'rectangle' | 'triangle' ) .

%%doc Here the right prompt is made so the user
%% can choose the shape they want.

shape_from_user() ->
     Prompt = "R)ectangle, T)riangle, or E)llipse > ",
     char_to_shape(prompt_user(Prompt)).

-spec (prompt_user(string()) -> string()).

%% doc Here the prompt is displayed and send to
%% the strip function so the newline is stripped.

prompt_user(Prompt) ->
     strip_lf(io:get_line(Prompt)).

-spec (strip_lf (string()) -> string() ).

%%doc Here the newline is stripped from the userinput.

strip_lf(Str) ->
     string:strip(Str, right, $\n).



char_to_shape("R") -> rectangle;
char_to_shape("r") -> rectangle;
char_to_shape("T") -> triangle;
char_to_shape("t") -> triangle;
char_to_shape("E") -> ellipse;
char_to_shape("e") -> ellipse;
char_to_shape(_)   -> error(bad_shape).

dimensions_from_user(rectangle) ->
     numbers_from_user("width", "height");
dimensions_from_user(triangle) ->
     numbers_from_user("base", "height");
dimensions_from_user(ellipse) ->
     numbers_from_user("major axis", "minor axis").

numbers_from_user(XPrompt, YPrompt) ->
     X = number_from_user(XPrompt),
     Y = number_from_user(YPrompt),
     {X, Y}.

number_from_user(Name) ->
     Prompt = ["Enter ", Name, " > "],
     to_positive_number(prompt_user(Prompt)).

to_positive_number(Prompt) ->
     positive_number(to_number(Prompt)).

positive_number(N) when N > 0 -> N;
positive_number(_) -> error(bad_number).

to_number(Str) ->
     try_number([fun list_to_float/1, fun list_to_integer/1], Str).

try_number([Method|Rest], Arg) ->
     try
         Method(Arg)
     catch
         error:badarg -> try_number(Rest, Arg)
     end;
try_number([], _Arg) ->
     error(bad_number).

error_msg(bad_shape)  -> "Please enter a valid shape";
error_msg(bad_number) -> "Please enter a positive number".


but as soon as I run dialyzer I see this output :

Checking whether the PLT /home/nitrous/.dialyzer_plt is up-to-date... yes
Proceeding with analysis...
ask_area.erl:34: Function collect_data/0 has no local return
ask_area.erl:75: Function dimensions_from_user/1 has no local return
ask_area.erl:82: Function numbers_from_user/2 has no local return
ask_area.erl:87: Function number_from_user/1 has no local return
ask_area.erl:89: The call 
ask_area:prompt_user(Prompt::[[1..255,...],...]) breaks the contract 
(string()) -> string()
ask_area.erl:91: Function to_positive_number/1 will never be called
ask_area.erl:94: Function positive_number/1 will never be called
ask_area.erl:97: Function to_number/1 will never be called
ask_area.erl:100: Function try_number/2 will never be called
  done in 0m0.51s done (warnings were emitted)

hecking whether the PLT /home/nitrous/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
ask_area.erl:34: Function collect_data/0 has no local return
ask_area.erl:75: Function dimensions_from_user/1 has no local return
ask_area.erl:82: Function numbers_from_user/2 has no local return
ask_area.erl:87: Function number_from_user/1 has no local return
ask_area.erl:89: The call ask_area:prompt_user(Prompt::[[1..255,...],...]) breaks the contract (string()) -> string()
ask_area.erl:91: Function to_positive_number/1 will never be called
ask_area.erl:94: Function positive_number/1 will never be called
ask_area.erl:97: Function to_number/1 will never be called
ask_area.erl:100: Function try_number/2 will never be called
Unknown functions:
   geom:area/3
  done in 0m0.51s
done (warnings were emitted)



Can someone explain what these messages mean.
This is the first time I use dialyzer and this confuses me.

Roelof


---
Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware.
https://www.avast.com/antivirus




More information about the erlang-questions mailing list