Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Erlang (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Data types== Erlang has eight primitive [[data type]]s: ;Integers: Integers are written as sequences of decimal digits, for example, 12, 12375 and -23427 are integers. Integer arithmetic is exact and only limited by available memory on the machine. (This is called [[arbitrary-precision arithmetic]].) ;Atoms: Atoms are used within a program to denote distinguished values. They are written as strings of consecutive alphanumeric characters, the first character being lowercase. Atoms can contain any character if they are enclosed within single quotes and an escape convention exists which allows any character to be used within an atom. Atoms are never garbage collected and should be used with caution, especially if using dynamic atom generation. ;Floats: Floating point numbers use the [[binary64|IEEE 754 64-bit representation]]. ;References: References are globally unique symbols whose only property is that they can be compared for equality. They are created by evaluating the Erlang primitive <code>make_ref()</code>. ;Binaries: A binary is a sequence of bytes. Binaries provide a space-efficient way of storing binary data. Erlang primitives exist for composing and decomposing binaries and for efficient input/output of binaries. ;Pids: Pid is short for ''process identifier''{{snd}}a Pid is created by the Erlang primitive <code>spawn(...)</code> Pids are references to Erlang processes. ;Ports: Ports are used to communicate with the external world. Ports are created with the built-in function <code>open_port</code>. Messages can be sent to and received from ports, but these messages must obey the so-called "port protocol." ;Funs: Funs are function [[Closure (computer programming)|closures]]. Funs are created by expressions of the form: <code>fun(...) -> ... end</code>. And three compound data types: ;Tuples: Tuples are containers for a fixed number of Erlang data types. The syntax <code>{D1,D2,...,Dn}</code> denotes a tuple whose arguments are <code>D1, D2, ... Dn.</code> The arguments can be primitive data types or compound data types. Any element of a tuple can be accessed in constant time. ;Lists: Lists are containers for a variable number of Erlang data types. The syntax <code>[Dh|Dt]</code> denotes a list whose first element is <code>Dh</code>, and whose remaining elements are the list <code>Dt</code>. The syntax <code>[]</code> denotes an empty list. The syntax <code>[D1,D2,..,Dn]</code> is short for <code>[D1|[D2|..|[Dn|[]]]]</code>. The first element of a list can be accessed in constant time. The first element of a list is called the ''head'' of the list. The remainder of a list when its head has been removed is called the ''tail'' of the list. ;Maps: Maps contain a variable number of key-value associations. The syntax is<code>#{Key1=>Value1,...,KeyN=>ValueN}</code>. Two forms of [[syntactic sugar]] are provided: ;Strings: Strings are written as doubly quoted lists of characters. This is syntactic sugar for a list of the integer [[Unicode]] code points for the characters in the string. Thus, for example, the string "cat" is shorthand for <code>[99,97,116]</code>.<ref>{{cite web |url=http://erlang.org/doc/apps/stdlib/unicode_usage.html#string-and-character-literals |title=String and Character Literals |access-date=2 May 2015}}</ref> ;Records: Records provide a convenient way for associating a tag with each of the elements in a tuple. This allows one to refer to an element of a tuple by name and not by position. A pre-compiler takes the record definition and replaces it with the appropriate tuple reference. Erlang has no method to define classes, although there are external [[Library (computing)|libraries]] available.<ref>{{cite web |url=https://code.google.com/p/ect/ |title=ect β Erlang Class Transformation β add object-oriented programming to Erlang β Google Project Hosting |access-date=2 May 2015}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)