Created
May 4, 2020 07:28
-
-
Save sushant12/0181de4c13a8563f99050bd65a7cdcb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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 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 :)
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
Great solution, I would just recommend you not to use
-import
and just use fully-qualified names for functions likefirst:square/1
.