Last active
May 5, 2020 22:35
-
-
Save sgobotta/143bb2adabe862d2fad9972dc3d33740 to your computer and use it in GitHub Desktop.
Gists for the FeatureLearn Erlang course (1.9)
This file contains 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, | |
trbl/1, | |
sum/3 | |
]). | |
mult(X,Y) -> | |
X*Y. | |
double(X) -> | |
mult(2,X). | |
area(A,B,C) -> | |
S = sum(A,B,C)/2, | |
math:sqrt(S*(S-A)*(S-B)*(S-C)). | |
square(X) -> | |
mult(X,X). | |
trbl(X) -> | |
mult(3,X). | |
sum(X,Y,Z) -> | |
X+Y+Z. |
This file contains 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, | |
area/3, | |
sum/3 | |
]). | |
-export([ | |
hypotenuse/2, | |
area/2, | |
perimeter/2 | |
]). | |
% given two sides of a tractangle triangle returns the size of the hypotenuse | |
hypotenuse(X,Y) -> | |
math:sqrt(square(X) + square(Y)). | |
% given two sides of a triangle rectangle returns the area | |
area(X,Y) -> | |
H = hypotenuse(X,Y), | |
area(X,Y,H). | |
% given two sides of a tractangle triangle returns the perimeter | |
perimeter(X,Y) -> | |
H = hypotenuse(X,Y), | |
sum(X,Y,H). | |
Ah, sí… podemos hablar en porteño si te cabe, eh? Por mí, todo bien :P
Aaaajáa. A la tarde voy a estar chequeando los mensajes de esa fase sección cuando remote los ejercicios. Esta bastante entretenido! 🎉
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's a generic practice. Check it out: http://erlang.org/doc/apps/edoc/chapter.html
About importing functions with similar names… I believe that the compiler will tell you that the function is redefined (you should try and see…). But I wrote a long comment on FutureLearn stating why I think it's not wise to use
-import
. Basically, it makes code harder to understand and debug. Not super noticeable in small modules, but definitely hideous in large ones.