[erlang-questions] syntax errror on :

Roelof Wobben r.wobben@REDACTED
Sat Aug 8 17:22:45 CEST 2015


Hmm, still some stupid faults,

When I do R and then 2 I see this output:

What is the length of the rectangle? 2

** exception error: no match of right hand side value "2\n" in function 
geom51:get_dimension/1 (geom51.erl, line 69)

When I do R and then 2.0 I see this :

What is the length of the rectangle?  2.0
** exception error: no case clause matching 2.0
      in function  geom51:get_dimension/1 (geom51.erl, line 65)


What is the length of the rectangle? 2.0

** exception error: no case clause matching 2.0 in function 
geom51:get_dimension/1 (geom51.erl, line 65)

Which is wierd the string:to_integer schould do the trick.


Roelof

Op 8-8-2015 om 13:07 schreef Loïc Hoguin:

> You forgot the dot at the end of the very last function.
>
> On 08/08/2015 01:03 PM, Roelof Wobben wrote:
>> Hello,
>>
>> I try to find a solution for this etude :
>> http://chimera.labs.oreilly.com/books/1234000000726/ch05.html#CH05-ET01
>>
>> So far I have this :
>>
>> %% @author Roelof Wobben <r.wobben@REDACTED>
>> %% @doc Function to calculate the area of a rectangle
>> %% @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(geom51).
>>
>> -export([area/0]).
>>
>> %% @doc ask the user for which shape the area
>> %% must be calculated.
>> %% Choices are :
>> %% c or a C for a circle
>> %% e or a E for a ellipse
>> %% t or a T for a triangle
>>
>> -spec(area() -> char() ).
>>
>> area() ->
>>      io:format("Which shape must the area be calculated?~n"),
>>      io:format(" R. Rectangle ~n"),
>>      io:format(" T. Triangle~n"),
>>      io:format(" E. Ellipse~n"),
>>      Answer = io:get_line("Your choice?  "),
>>
>>      Value = hd(Answer),
>>      char_to_shape(Value).
>>
>> %% @doc convert the choice to a Shape and send the
>> %5 data to the dimension function
>> %% when the choice is a  :
>> %% r or a R then the shape will be a rectangle
>> %% t or a T then the shape will be a triangle
>> %% e or a E then the shape will be a ellipse
>>
>> -spec(char_to_shape(char() ) -> atom() ).
>>
>> char_to_shape(Char) ->
>>      case Char of
>>          $R -> get_dimension(rectangle);
>>          $T -> triangle;
>>          $E -> ellipse;
>>          $r -> rectangle;
>>          $t -> triangle;
>>          $e -> ellipse;
>>          _Else -> "Wrong Shape"
>>      end.
>>
>> -spec(get_dimension( atom() ) -> number() ) .
>>
>> %% @doc Calculates the area of a shape, given the
>> %% shape and two of the dimensions. Returns the product
>> %% of its arguments for a rectangle, one half the
>> %% product of the arguments for a triangle, and
>> %% math:pi times the product of the arguments for
>> %% an ellipse.
>>
>> get_dimension(Shape)->
>>      case Shape of
>>          rectangle ->
>>              Answer1 = io:get_line("What is the length of the
>> rectangle?  "),
>>              {Test, _} = string:to_float(Answer1),
>>                       case Test of
>>                           error -> Test2 = string:to_integer(Answer1),
>>                           case  Test2 of
>>                               error -> io:write("the input schould be a
>> number");
>>                               _Else -> Test2 = Test
>>                           end
>>                       end
>>      end
>>
>>
>> but now I see these error message :
>>
>> geom51.erl:72: syntax error before:
>> geom51.erl:42: function get_dimension/1 undefined
>> geom51.erl:51: spec for undefined function geom51:get_dimension/1
>>
>> geom51.erl:72: syntax error before:
>> geom51.erl:42: function get_dimension/1 undefined
>> geom51.erl:51: spec for undefined function geom51:get_dimension/1
>>
>> anyone who knows how to solve this one ?
>>
>> Roelof
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> ---
>> Dit e-mailbericht is gecontroleerd op virussen met Avast 
>> antivirussoftware.
>> https://www.avast.com/antivirus
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>


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




More information about the erlang-questions mailing list