You are previewing Introducing Erlang.

Introducing Erlang

Cover of Introducing Erlang by Simon St. Laurent Published by O'Reilly Media, Inc.
  1. Introducing Erlang
  2. Preface
    1. Who This Book Is For
    2. Who This Book Is Not For
    3. What This Book Will Do For You
    4. How This Book Works
    5. Why I Wrote This Book
    6. Other Resources
    7. Are You Sure You Want Erlang?
    8. Erlang Will Change You
    9. Conventions Used in This Book
    10. A Note on Erlang Syntax
    11. Using Code Examples
    12. Help This Book Grow
    13. Please Use It For Good
    14. Safari® Books Online
    15. How to Contact Us
    16. Acknowledgments
  3. 1. Getting Comfortable
    1. Installation
    2. Firing It Up
    3. First Steps: The Shell
      1. Moving through Text
      2. Moving through History
      3. Moving through Files
    4. Doing Something
    5. Calling Functions
    6. Numbers in Erlang
    7. Working with Variables in the Shell
      1. Seeing Your Bound Variables
      2. Clearing Bound Variables in the Shell
  4. 2. Functions and Modules
    1. Fun with fun
    2. Defining Modules
      1. From Module to Fun
      2. Functions and Variable Scope
      3. Module Directives
    3. Documenting Code
      1. Documenting Modules
      2. Documenting Functions
      3. Documenting Your Application
  5. 3. Atoms, Tuples, and Pattern Matching
    1. Atoms
    2. Pattern Matching with Atoms
    3. Atomic Booleans
    4. Guards
    5. Underscoring That You Don’t Care
    6. Adding Structure: Tuples
      1. Pattern Matching with Tuples
      2. Processing Tuples
  6. 4. Logic and Recursion
    1. Logic Inside of Functions
      1. Evaluating Cases
      2. If This, Then That
      3. Variable Assignment in case and if Constructs
    2. The Gentlest Side Effect: io:format
    3. Simple Recursion
      1. Counting Down
      2. Counting Up
      3. Recursing with Return Values
  7. 5. Communicating with Humans
    1. Strings
    2. Asking Users for Information
      1. Gathering Terms
      2. Gathering Characters
      3. Reading Lines of Text
  8. 6. Lists
    1. List Basics
    2. Splitting Lists into Heads and Tails
    3. Processing List Content
    4. Creating Lists with Heads and Tails
    5. Mixing Lists and Tuples
    6. Building a List of Lists
  9. 7. Higher-Order Functions and List Comprehensions
    1. Simple Higher-Order Functions
    2. Creating New Lists with Higher-Order Functions
      1. Reporting on a List
      2. Running List Values Through a Function
      3. Filtering List Values
    3. Beyond List Comprehensions
      1. Testing Lists
      2. Splitting Lists
      3. Folding Lists
  10. 8. Playing with Processes
    1. The Shell Is a Process
    2. Spawning Processes from Modules
    3. Lightweight Processes
    4. Registering a Process
    5. When Processes Break
    6. Processes Talking Amongst Themselves
    7. Watching Your Processes
    8. Breaking Things and Linking Processes
  11. 9. Exceptions, Errors, and Debugging
    1. Flavors of Errors
    2. Catching Runtime Errors as They Happen
    3. Raising Exceptions with throw
    4. Logging Progress and Failure
    5. Debugging through a GUI
    6. Tracing Messages
    7. Watching Function Calls
  12. 10. Storing Structured Data
    1. From Tuples to Records
      1. Setting Up Records
      2. Creating and Reading Records
      3. Using Records in Functions and Modules
    2. Storing Records in Erlang Term Storage
      1. Creating and Populating a Table
      2. Simple Queries
      3. A Key Feature: Overwriting Values
      4. ETS Tables and Processes
      5. Next Steps
    3. Storing Records in Mnesia
      1. Starting up Mnesia
      2. Creating Tables
      3. Reading Data
      4. Query List Comprehensions
  13. 11. Getting Started with OTP
    1. Creating Services with gen_server
    2. A Simple Supervisor
    3. Packaging an Application
  14. 12. Next Steps Through Erlang
    1. Moving Beyond the Shell
    2. Distributed Computing
    3. Processing Binary Data
    4. Input and Output
    5. Testing, Analyzing, and Refactoring
    6. Networking and the Web
    7. Data Storage
    8. Extending Erlang
    9. Languages Built on Erlang
    10. Community
    11. Sharing the Gospel of Erlang
  15. A. An Erlang Parts Catalog
    1. Shell Commands
    2. Reserved Words
    3. Operators
    4. Guard Components
    5. Common Functions
    6. Strings and Formatting
    7. Data Types for Documentation and Analysis
  16. B. OTP Templates
  17. Colophon
  18. Copyright
O'Reilly logo

Appendix A. An Erlang Parts Catalog

Like every language, Erlang has drawers full of parts that are fun to peruse. These are a very few of the more common ones. If you want much much more, see http://www.erlang.org/doc/reference_manual/users_guide.html.

Shell Commands

You can use most Erlang functions from the shell, but these are ones that are exclusive to the shell.

Table A-1. Erlang shell commands

Command Action

q()

Quits the shell and the Erlang runtime.

c(file)

Compiles the specified Erlang file.

b()

Displays all variable bindings.

f()

Clears all variable bindings.

f(X)

Clears specified variable binding.

h()

Prints the history list of commands.

e(N)

Repeats the command on line N.

v(N)

The return value of line N.

catch_exception(boolean)

Sets how strict the shell will be in passing errors.

rd(Name,Definition)

Defines a record type Name with contents specified by Definition.

rr(File)

Defines record types based on the contents of File.

rf()

Clears all record definitions. Can also clear specific definitions.

rl()

Lists all current record definitions.

pwd()

Gets the present working directory.

ls()

Lists files at the current location.

cd(Directory)

Changes to the specified Directory.

Reserved Words

There are a few Erlang terms you can’t use outside of their intended context.

The Erlang compiler will wonder what you’re trying to do if you use certain keywords as atoms or function names. It will try to treat your atoms as if they were code, and you can get very strange errors. After all, you should be able to have something ...

The best content for your career. Discover unlimited learning on demand for around $1/day.