Erlang Flashcards
Erlang vs Clojure
Like:
-Erlang is a functional language like Clojure
-no type declarations
Unlike:
-It is not a direct mapping of the LISP language
How is it similar to Java?
-Runs on top of a virtual machine(BEAM)
-Can support other languages that run on its VM
What are the 2 ways Erlang can be run?
1.An interactive command line shell called Eshell
2.By compiling the code and running it directly with erl.
Erlang uses several separators to differ expressions from each other. What are they?
1.Commas: used between function arguments and between expression in function body.
2.Semi-colons: used between alternate forms or arities if a function.
3.Period: used to terminate a complete expression
What are the 3 simple types?
Integers
Floating point values
Strings: surrounded by double quotes
*No boolean
What are the 4 main composite data structures?
Tuple
List
Record
Map
Describe tuples
-Written using curly braces with elements separated by commas
-No labels associated with a tuple
-“atom” is used as the first element of a type (begins w lowercase letter)
How does Erlang use pattern matching ?
– Comments in Erlang use the % character
– Erlang uses pattern matching to map the fields of P (right hand side or RHS) to the elements on the left hand side (LHS)
– An error (no match of right hand side) will be generated if the match is not valid.
– Finally, we can use an underscore “_” when we do not need to save a particular field.
Describe lists
-Written with square brackets with each element separated by commas
-Lists can contain any other types/structures and can be of arbitrary length. SAME AS LISP
-Erlang considers lists to consist of a Head and a Tail (he head is the first element, the tail is everything else)
Describe records
-Written with curly brackets
-They’re like tuples but we can associate labels with values.
-Different than other types because they have an actual declaration.
-Define only ONCE
-Name and keys must be atoms
-Generally declared separately and then included in the current file