Last active
August 29, 2015 14:12
-
-
Save subh007/3d1acff2001c4073efc1 to your computer and use it in GitHub Desktop.
erl notes
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
variables begin with an uppercase letter. | |
you can assign a value to a variable exactly once | |
The = operator (not the variables) has the role of comparing values and complaining if they're different. If they're the same, it returns the value: | |
If you're testing in the shell and save the wrong value to a variable, it is possible to 'erase' that variable by using the function f(Variable).. If you wish to clear all variable names, do f().. | |
Erlang won't care about floats and integers in arithmetic, but will do so when comparing them | |
6> 5 =:= 5. | |
true | |
7> 1 =:= 0. | |
false | |
8> 1 =/= 0. | |
true | |
9> 5 =:= 5.0. | |
false | |
10> 5 == 5.0. | |
true | |
11> 5 /= 5.0. | |
false | |
he correct ordering of each element in a comparison is the following: | |
number < atom < reference < fun < port < pid < tuple < list < bit string | |
tuple {v1,v2,v3, ...} | |
Erlang will print lists of numbers as numbers only when at least one of them could not also represent a letter! There is no such thing as a real string in Erlang! | |
1> [2*N || N <- [1,2,3,4]]. | |
[2,4,6,8] | |
2> [X || X <- [1,2,3,4,5,6,7,8,9,10], X rem 2 =:= 0]. | |
[2,4,6,8,10] | |
NewList = [Expression || Pattern <- List, Condition1, Condition2, ... ConditionN] | |
NewList = [Expression || GeneratorExp1, GeneratorExp2, ..., GeneratorExpN, Condition1, Condition2, ... ConditionM]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment