Prolog, Erlang, Elixir
a side-by-side reference sheet
grammar and invocation | variables and expressions | arithmetic and logic | strings | regexes | dates and time | lists | tuples | dictionaries | algebraic data types | functions | execution control | file handles | files | directories | processes and environment | libraries and namespaces | reflection | repl
Version used for testing the examples in the sheet.
How to determine the version.
A "Hello, World!" program.
The native compiler.
erlang:
Sometimes the HiPE native compiler must be installed separately.
Modules can be compiled to native code, but an Erlang runtime is still required to run the code.
The bytecode compiler.
The interpreter.
How to associate an interpreter with a file on a Unix system.
How to run the read-evaluate-print loop.
How blocks are delimited. A block is a sequence of statements which are executed in order.
How statements are terminated.
prolog:
A prolog program consists of facts, rules, and goals.
Facts define the data of a Prolog program. They are analogous to variable definitions in other languages.
Rules define facts in a recursive manner. In this sheet they are discussed in the section on functions.
Facts and rules usually found in files; they are not entered in the interactive toplevel directly. A fact typed directly into the toplevel is treated as a goal. A rule directly typed into the toplevel results in an error message. However, the assert goal can be used to create a fact or rule in the top level.
Goals are either queries or they have a side effect.
Queries are handled by the Prolog infererence engine. If the query has an unbound variable, the inference engine searches for values which make the query true. If the query does not have an unbound variable, the inference engine determines whether the query is true or false. Queries are a distinctive feature of logic programming and have no analog in other languages.
Goals with side effect are analogous to statements with side effect in other languages. They are used in Prolog for I/O. They are used to give instructions to the infererence engine, e.g. the cut goal which prevents backtracking. Also, the {{assert} goal described above is a goal with side effect.
Goals can be typed directly into the toplevel. They can also be placed in a file when preceded by the :- notation.
The syntax for a comment which goes to the end of the current line.
The syntax for a delimited comment which can span lines.
The literals for true and false.
Values which evaluate as false in a boolean context.
erlang:
Relational operators can be used on values with different types. In this case the precedence is determined by
the type according to this sequence:
number < atom < reference < fun < port < pid < tuple < list < binary
If a comparison is performed on an integer and a float, the integer will be converted to a float. =:= and =/= do not perform conversions and thus will always return false and true respectively when called on an integer and a float.
How to find the quotient of two integers.
The result of dividing an integer by zero.
How to perform float division of two integers.
The result of dividing a float by zero.
erlang:
Some of the Erlang backslash escapes are not derived from C:
\d delete \s space
atom to string
string to atom
function definition
function definition with guards
erlang:
The expressions in guards must be side-effect free. Thus they can only contain the following:
bound variables
literals
type tests: is_atom, is_boolean, is_tuple, …
relational operators
arithmetic operators
boolean operators
a few built-in functions
read line
erlang:
io:get_line accepts an argument which is displayed as a prompt. The return value is a string which includes the newline.
read character
erlang:
io:get_chars accepts two arguments. The first is a string which is displayed as a prompt. The second is the number of characters to be read. The function keeps reading lines until the requested number of characters has been collected. The return value is a string which can contain newlines if a line of less than the requested number of characters was entered.
SWI Prolog Reference Manual
Prolog: The ISO Standard Document
Erlang Reference Manual User's Guide
Erlang Standard Library
Elixir: Introduction
Elixir: Standard Library