Introducing Elixir_ Getting Started in Functional Programming [St. Laurent & Eisenberg 2014-09-25].pdf

(3005 KB) Pobierz
Elixir
GETTING STARTED IN FUNCTIONAL PROGRAMMING
Introducing
Simon St. Laurent & J. David Eisenberg
www.it-ebooks.info
Introducing Elixir
Elixir is an excellent language if you want to learn about functional
programming, and with this hands-on introduction, you’ll discover just
how powerful and fun Elixir can be. This language combines the robust
functional programming of Erlang with a syntax similar to Ruby, and
includes powerful features for metaprogramming.
This book shows you how to write simple Elixir programs by teaching one skill
at a time. Once you pick up pattern matching, process-oriented programming,
and other concepts, you’ll understand why Elixir makes it easier to build
concurrent and resilient programs that scale up and down with ease.
Get comfortable with IEx, Elixir’s command-line interface
Discover atoms, pattern matching, and guards: the foundations
of your program structure
Delve into the heart of Elixir with recursion, strings, lists, and
higher-order functions
Create processes, send messages among them, and apply
pattern matching to incoming messages
Store and manipulate structured data with Erlang Term Storage
and the Mnesia database
Build resilient applications with Erlang’s Open Telecom
Platform
Define macros with Elixir’s metaprogramming tools
Simon St. Laurent
is a Strategic Content Director at O’Reilly Media, Inc., focusing
primarily on web-related topics. He is co-chair of O’Reilly’s Fluent and OSCON
conferences. Simon has written or co-written books, including
Introducing Erlang,
Learning Rails 3,
and
XML Pocket Reference,
Third Edition (all O’Reilly).
J. David Eisenberg
is a programmer and instructor in San Jose, California, with a
talent for teaching and explaining. He’s developed courses for CSS, JavaScript,
CGI, and XML, and teaches Computer Information Technology courses at
Evergreen Valley College. David has written books including
SVG Essentials,
Études for Erlang
(both O’Reilly), and
Let’s Read Hiragana
(Eisenberg Consulting).
PROGR AMMING L ANGUAGES
Twitter: @oreillymedia
facebook.com/oreilly
US $24.99
CAN $26.99
ISBN: 978-1-449-36999-6
www.it-ebooks.info
Introducing Elixir
Simon St. Laurent and J. David Eisenberg
www.it-ebooks.info
Introducing Elixir
by Simon St. Laurent and J. David Eisenberg
Copyright © 2014 Simon St. Laurent and J. David Eisenberg. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are
also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/
institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editors:
Simon St. Laurent and Meghan Blanchette
Production Editor:
Melanie Yarbrough
Proofreader:
Amanda Kersey
Indexer:
J. David Eisenberg
September 2014:
First Edition
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrator:
Rebecca Demarest
Revision History for the First Edition:
2014-09-10:
First release
See
http://oreilly.com/catalog/errata.csp?isbn=9781449369996
for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Introducing Elixir,
the cover image of a
four-horned antelope, and related trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark
claim, the designations have been printed in caps or initial caps.
While the publisher and the authors have used good faith efforts to ensure that the information and in‐
structions contained in this work are accurate, the publisher and the authors disclaim all responsibility for
errors or omissions, including without limitation responsibility for damages resulting from the use of or
reliance on this work. Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to open source licenses or
the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies
with such licenses and/or rights.
ISBN: 978-1-449-36999-6
[LSI]
www.it-ebooks.info
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1. Getting Comfortable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Installation
Installing Erlang
Installing Elixir
Firing It Up
First Steps
Moving Through Text and History
Moving Through Files
Doing Something
Calling Functions
Numbers in Elixir
Working with Variables in the Shell
1
1
2
2
2
3
3
4
5
6
8
2. Functions and Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Fun with fn
And the &
Defining Modules
From Module to Free-Floating Function
Splitting Code Across Modules
Combining Functions with the Pipe Operator
Importing Functions
Default Values for Arguments
Documenting Code
Documenting Functions
Documenting Modules
11
13
13
16
17
18
19
20
21
22
23
iii
www.it-ebooks.info
Zgłoś jeśli naruszono regulamin