Skip to content

Instantly share code, notes, and snippets.

@sushant12
Created May 4, 2020 07:28
Show Gist options
  • Save sushant12/0181de4c13a8563f99050bd65a7cdcb3 to your computer and use it in GitHub Desktop.
Save sushant12/0181de4c13a8563f99050bd65a7cdcb3 to your computer and use it in GitHub Desktop.
-module(first).
-export([double/1,mult/2,area/3,square/1,trebel/1]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
area(A,B,C) ->
S = (A+B+C)/2,
math:sqrt(S*(S-A)*(S-B)*(S-C)).
square(Num) ->
mult(Num, Num).
trebel(Num) ->
mult(3,Num).
-module(second).
-import('first', [square/1, mult/2]).
-export([area/2, hypotenuse/2, perimeter/2]).
hypotenuse(A, B) ->
math:sqrt(square(A) + square(B)).
area(A,B) ->
mult(A,B) / 2.
perimeter(A,B) ->
A + B + hypotenuse(A, B).
@elbrujohalcon
Copy link

Great solution, I would just recommend you not to use -import and just use fully-qualified names for functions like first:square/1.

@sushant12
Copy link
Author

sushant12 commented May 5, 2020

@elbrujohalcon I used import because I wanted to do it differently but you are absolutely right. Calling the square/1 function makes it look like the function is defined in the same module. Appending the module name with the function name makes it so clear :)

@Liferenko
Copy link

Liferenko commented May 6, 2020

Wow! @elbrujohalcon and @sushant12, thank you for leaving these comments. I'm here to find how to use import from one module to another one. But now it really sounds more logic and clean to use filename:module() syntax instead of -import('blah', [blah/1]).
Nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment