
Erlang Reference Manual version 5.7 Typeset in LATEX from SGML source using the DocBuilder-0.9.8.6 Document System. Contents 1 Erlang Reference Manual 1 1.1 Introduction.......................................... 1 1.1.1Purpose........................................ 1 1.1.2Prerequisites..................................... 1 1.1.3DocumentConventions............................... 1 1.1.4CompleteListofBIFs................................ 1 1.1.5ReservedWords.................................... 2 1.1.6CharacterSet..................................... 2 1.2 DataTypes.......................................... 2 1.2.1Terms......................................... 2 1.2.2Number........................................ 2 1.2.3Atom......................................... 3 1.2.4BitStringsandBinaries................................ 3 1.2.5Reference....................................... 3 1.2.6Fun.......................................... 4 1.2.7PortIdentifier..................................... 4 1.2.8Pid........................................... 4 1.2.9Tuple......................................... 5 1.2.10List........................................... 5 1.2.11String......................................... 6 1.2.12Record......................................... 6 1.2.13Boolean........................................ 7 1.2.14EscapeSequences................................... 7 1.2.15TypeConversions................................... 7 1.3 PatternMatching....................................... 8 1.3.1PatternMatching................................... 8 1.4 Modules............................................ 8 1.4.1ModuleSyntax.................................... 8 1.4.2ModuleAttributes.................................. 9 1.4.3Comments...................................... 10 Erlang Reference Manual iii 1.4.4 The module info/0 and module info/1functions.................. 11 1.5 Functions........................................... 11 1.5.1FunctionDeclarationSyntax............................. 11 1.5.2FunctionEvaluation................................. 12 1.5.3Tailrecursion..................................... 13 1.5.4Built-InFunctions,BIFs............................... 13 1.6 Expressions.......................................... 14 1.6.1ExpressionEvaluation................................ 14 1.6.2Terms......................................... 14 1.6.3Variables........................................ 14 1.6.4Patterns........................................ 15 1.6.5Match......................................... 17 1.6.6FunctionCalls..................................... 17 1.6.7If............................................ 18 1.6.8Case.......................................... 18 1.6.9Send.......................................... 19 1.6.10Receive........................................ 19 1.6.11TermComparisons.................................. 21 1.6.12ArithmeticExpressions................................ 22 1.6.13BooleanExpressions................................. 23 1.6.14Short-CircuitExpressions.............................. 23 1.6.15ListOperations.................................... 24 1.6.16BitSyntaxExpressions................................ 25 1.6.17FunExpressions.................................... 27 1.6.18CatchandThrow................................... 28 1.6.19Try........................................... 29 1.6.20ParenthesizedExpressions.............................. 31 1.6.21BlockExpressions................................... 31 1.6.22ListComprehensions................................. 31 1.6.23BitStringComprehensions.............................. 32 1.6.24GuardSequences................................... 33 1.6.25OperatorPrecedence................................. 34 1.7 ThePreprocessor....................................... 35 1.7.1FileInclusion..................................... 35 1.7.2DefiningandUsingMacros............................. 36 1.7.3PredefinedMacros.................................. 37 1.7.4FlowControlinMacros............................... 37 1.7.5StringifyingMacroArguments............................ 38 1.8 Records............................................ 38 1.8.1DefiningRecords................................... 38 iv Erlang Reference Manual 1.8.2CreatingRecords................................... 39 1.8.3AccessingRecordFields............................... 39 1.8.4UpdatingRecords................................... 39 1.8.5RecordsinGuards.................................. 40 1.8.6RecordsinPatterns.................................. 40 1.8.7InternalRepresentationofRecords......................... 40 1.9 ErrorsandErrorHandling.................................. 41 1.9.1Terminology...................................... 41 1.9.2Exceptions...................................... 41 1.9.3HandlingofRun-TimeErrorsinErlang....................... 42 1.9.4ExitReasons..................................... 42 1.10Processes............................................ 43 1.10.1Processes....................................... 43 1.10.2ProcessCreation................................... 43 1.10.3RegisteredProcesses................................. 43 1.10.4ProcessTermination................................. 44 1.10.5MessageSending................................... 44 1.10.6Links.......................................... 44 1.10.7ErrorHandling.................................... 44 1.10.8Monitors........................................ 45 1.10.9ProcessDictionary.................................. 45 1.11DistributedErlang...................................... 46 1.11.1DistributedErlangSystem.............................. 46 1.11.2Nodes......................................... 46 1.11.3NodeConnections.................................. 46 1.11.4epmd......................................... 47 1.11.5HiddenNodes..................................... 47 1.11.6CNodes........................................ 47 1.11.7Security........................................ 47 1.11.8DistributionBIFs................................... 48 1.11.9DistributionCommandLineFlags.......................... 48 1.11.10DistributionModules................................. 48 1.12CompilationandCodeLoading............................... 49 1.12.1Compilation...................................... 49 1.12.2CodeLoading..................................... 50 1.12.3CodeReplacement.................................. 50 1.13PortsandPortDrivers.................................... 50 1.13.1Ports.......................................... 51 1.13.2PortDrivers...................................... 51 1.13.3PortBIFs........................................ 51 Erlang Reference Manual v List of Tables 53 vi Erlang Reference Manual Chapter 1 Erlang Reference Manual 1.1 Introduction 1.1.1 Purpose This reference manual describes the Erlang programming language. The focus is on the language itself, not the implementation. The language constructs are described in text and with examples rather than formally specified, with the intention to make the manual more readable. The manual is not intended as a tutorial. Information about this implementation of Erlang can be found, for example, in System Principles (starting and stopping, boot scripts, code loading, error logging, creating target systems), Efficiency Guide (memory consumption, system limits) and ERTS User’s Guide (crash dumps, drivers). 1.1.2 Prerequisites It is assumed that the reader has done some programming and is familiar with concepts such as data types and programming language syntax. 1.1.3 Document Conventions In the document, the following terminology is used: ¯ A sequence is one or more items. For example, a clause body consists of a sequence of expressions. This means that there must be at least one expression. ¯ A list is any number of items. For example, an argument list can consist of zero, one or more arguments. If a feature has been added recently, in Erlang 5.0/OTP R7 or later, this is mentioned in the text. 1.1.4 Complete List of BIFs For a complete list of BIFs, their arguments and return values, refer to erlang(3). Erlang Reference Manual 1 Chapter 1: Erlang Reference Manual 1.1.5 Reserved Words The following are reserved words in Erlang: after and andalso band begin bnot bor bsl bsr bxor case catch cond div end fun if let not of or orelse query receive rem try when xor 1.1.6 Character Set In Erlang 4.8/OTP R5A the syntax of Erlang tokens was extended to allow the use of the full ISO-8859-1 (Latin-1) character set. This is noticeable in the following ways: ¯ All the Latin-1 printable characters can be used and are shown without the escape backslash convention. ¯ Atoms and variables can use all Latin-1 letters. Octal Decimal Class 200 - 237 128 - 159 Control characters 240 - 277 160 - 191 - Punctuation characters 300 - 326 192 - 214 - Uppercase letters 327 215 Punctuation character 330 - 336 216 - 222 - Uppercase letters 337 - 366 223 - 246 - Lowercase letters 367 247 Punctuation character 370 - 377 248 - 255 - Lowercase letters Table 1.1: Character Classes. 1.2 Data Types 1.2.1 Terms Erlang provides a number of data types which are listed in this chapter. A piece of data of any data type is called a term. 1.2.2 Number There are two types of numeric literals, integers and floats. Besides the conventional notation, there are two Erlang-specific notations: ¯ $char ASCII value of the character char. ¯ base#value Integer with the base base, which must be an integer in the range 2..36. In Erlang 5.2/OTP R9B and earlier versions, the allowed range is 2..16. Examples: 2 Erlang Reference Manual 1.2: Data Types
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages59 Page
-
File Size-