Created
May 5, 2020 14:57
-
-
Save gomesalexandre/ff5e0c278a4b2642f47a1574be011045 to your computer and use it in GitHub Desktop.
FutureLearn Erlang - My first erlang program
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([add/2, double/1, mult/2, area/3, treble/1, square/1]). | |
add(A,B) -> | |
A + B. | |
mult(X,Y) -> | |
X * Y. | |
double(X) -> | |
mult(2, X). | |
treble(X) -> | |
mult(3, X). | |
area(A,B,C) -> | |
S = (A + B + C) / 2, | |
math:sqrt(S*(S-A)*(S-B)*(S-C)). | |
square(X) -> | |
mult(X,X). | |
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, add/2, mult/2]). | |
-export([hypothenus/2, area_from_sides/2, perimeter_from_sides/2]). | |
hypothenus(A,B) -> | |
square(A) + square(B). | |
area_from_sides(A,B) -> | |
mult(A,B) / 2. | |
perimeter_from_sides(A,B) -> | |
add(A,B) + (math:sqrt(hypothenus(A,B))). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah… but you can't easily copy&paste code in a console to test it and debug it… which is something that, I promise you, you'll be doing a lot.