VanderHart / Sierra | Practical Clojure | E-Book | www2.sack.de
E-Book

E-Book, Englisch, 232 Seiten

VanderHart / Sierra Practical Clojure


1. ed
ISBN: 978-1-4302-7230-4
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark

E-Book, Englisch, 232 Seiten

ISBN: 978-1-4302-7230-4
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark



This book is the first definitive reference for the Clojure language, providing both an introduction to functional programming in general and a more specific introduction to Clojure's features. This book demonstrates the use of the language through examples, including features such as software transactional memory (STM) and immutability, which may be new to programmers coming from other languages. Overview of functional programming and description of what sets Clojure apart from other languages Detailed explanation of Clojure's special features Examples of real-world tasks that are well-suited to Clojure's capabilities, starting with simple tasks and moving on to more complex applications

Luke VanderHart is a professional software developer living and working in Washington, D.C. as a consultant with NuWave Solutions. He has more than five years of experience working with the Java platform, and has worked on programs ranging from distributed client-server networks serving and synchronizing semantic XML data, to GUI development using Java Swing, to enterprise web portals serving tens of thousands of pages per day. He is a very active member of the Clojure community.

VanderHart / Sierra Practical Clojure jetzt bestellen!

Weitere Infos & Material


1;Title Page;1
2;Copyright Page;2
3;Contents at a Glance;4
4;Table of Contents;5
5;About the Authors;14
6;About the Technical Reviewer;15
7;Acknowledgments;16
8;Chapter 1 The Clojure Way;17
8.1;Clojure’s Philosophy and Special Features;17
8.1.1;A Next-Generation Language;17
8.1.2;Dynamic and Powerful (Yes, It’s a Lisp);17
8.1.3;The Java Platform;18
8.2;Functional Programming;18
8.2.1;Purely Functional Programming;20
8.2.2;Clojure’s Compromise;22
8.2.3;Immutability;23
8.2.4;What about Object-Oriented Programming?;25
8.2.4.1;Structure of a Clojure Program;26
8.2.5;State Management;27
8.2.6;State and Identity;28
8.2.7;Software Transactional Memory;29
8.3;Summary;31
9;Chapter 2 The Clojure Environment;32
9.1;"Hello World" in Clojure;32
9.2;Clojure Forms;33
9.2.1;Literals;33
9.2.2;Symbols;34
9.2.3;Composite Forms;34
9.2.4;Special Forms;34
9.3;Writing and Running Source Files;35
9.4;Vars, Namespaces, and the Environment;36
9.5;Symbols and Symbol Resolution;38
9.5.1;Symbol Names;38
9.5.2;Symbol Resolution and Scope;39
9.6;Namespaces;39
9.6.1;Declaring Namespaces;40
9.6.2;Referencing Namespaces;40
9.6.3;Structuring Source Files;41
9.7;Summary;41
10;Chapter 3 Controlling Program Flow;43
10.1;Functions;43
10.1.1;First-Class Functions;43
10.1.2;Defining Functions with fn;43
10.1.3;Defining Functions with defn;45
10.1.4;Functions of Multiple Arities;45
10.1.5;Functions with Variable Arguments;46
10.1.6;Shorthand Function Declaration;47
10.2;Conditional Expressions;48
10.3;Local Bindings;49
10.4;Looping and Recursion;50
10.4.1;Tail Recursion;53
10.4.1.1;Clojure’s recur;53
10.4.1.2;Using loop;55
10.5;Deliberate Side Effects;56
10.5.1;Using do;56
10.5.1.1;Side Effects in Function Definitions;57
10.6;Functional Programming Techniques;57
10.6.1;First-Class Functions;57
10.6.1.1;Consuming First-Class Functions;58
10.6.1.2;Producing First-Class Functions;59
10.6.2;Closures;60
10.6.3;Currying and Composing Functions;60
10.6.3.1;Using partial to Curry Functions;60
10.6.3.2;Using comp to Compose Functions;61
10.6.4;Putting It All Together;62
11;Chapter 4 Data in Clojure;64
11.1;How to Represent and Manipulate Data;64
11.1.1;Nil;65
11.2;Primitive Types;65
11.2.1;Numbers;65
11.2.1.1;Common Numeric Functions;66
11.2.2;Strings;70
11.2.2.1;Common String Functions;70
11.2.2.2;Regular Expression Functions;71
11.2.3;Boolean;73
11.2.3.1;Common Boolean Functions;73
11.2.4;Characters;73
11.2.4.1;char;74
11.2.5;Keywords;74
11.3;Collections;74
11.3.1;Lists;75
11.3.1.1;list;76
11.3.1.2;peek;76
11.3.1.3;pop;76
11.3.1.4;list?;76
11.3.2;Vectors;77
11.3.2.1;vector;77
11.3.2.2;vec;77
11.3.2.3;get;77
11.3.2.4;peek;78
11.3.2.5;vector?;78
11.3.2.6;conj;78
11.3.2.7;assoc;78
11.3.2.8;pop;78
11.3.2.9;subvec;79
11.3.3;Maps;79
11.3.3.1;Struct Maps;80
11.3.3.2;Maps As Objects;81
11.3.4;Sets;83
11.3.4.1;Common Set Functions;84
11.4;Summary;84
12;Chapter 5 Sequences;85
12.1;What Are Sequences?;85
12.1.1;Sequenceable Types;87
12.2;Anatomy of a Sequence;87
12.3;Constructing Sequences;88
12.4;Lazy Sequences;89
12.4.1;An Example of Laziness;90
12.4.2;Constructing Lazy Sequences;92
12.4.2.1;Constructing Lazy Sequences Directly;92
12.4.2.2;Constructing Lazy Sequences Using Sequence Generator Functions;93
12.4.3;Lazy Sequences and Memory Management;94
12.5;The Sequence API;95
12.5.1;Sequence Creation;95
12.5.1.1;seq;95
12.5.1.2;vals;95
12.5.1.3;keys;95
12.5.1.4;rseq;95
12.5.1.5;lazy-seq;96
12.5.1.6;repeatedly;96
12.5.1.7;iterate;96
12.5.1.8;repeat;96
12.5.1.9;range;97
12.5.1.10;distinct;97
12.5.1.11;filter;97
12.5.1.12;remove;97
12.5.1.13;cons;98
12.5.1.14;concat;98
12.5.1.15;lazy-cat;98
12.5.1.16;mapcat;98
12.5.1.17;cycle;99
12.5.1.18;interleave;99
12.5.1.19;interpose;99
12.5.1.20;rest;99
12.5.1.21;next;99
12.5.1.22;drop;100
12.5.1.23;drop-while;100
12.5.1.24;take;100
12.5.1.25;take-nth;100
12.5.1.26;take-while;101
12.5.1.27;drop-last;101
12.5.1.28;reverse;101
12.5.1.29;sort;101
12.5.1.30;sort-by;101
12.5.1.31;split-at;102
12.5.1.32;split-with;102
12.5.1.33;partition;102
12.5.1.34;map;103
12.6;Summary;106
13;Chapter 6 State Management;107
13.1;State in an Immutable World;107
13.1.1;The Old Way;107
13.1.2;State and Identity;108
13.1.3;State and Identity in Clojure;108
13.1.3.1;Coordinated vs. Independent State;109
13.1.3.2;Synchronous vs. Asynchronous Updates;109
13.2;Refs and Transactions;109
13.2.1;Creating and Accessing refs;110
13.2.2;Updating refs;110
13.2.2.1;Transactions;111
13.2.2.2;Tools for Updating refs;111
13.2.2.3;Examples;113
13.3;Atoms;116
13.3.1;Using Atoms;116
13.3.2;When to Use Atoms;117
13.4;Asynchronous Agents;117
13.4.1;Creating and Updating Agents;117
13.4.1.1;Update Semantics;118
13.4.2;Errors and Agents;119
13.4.2.1;Dealing with Agents in a Failed State;119
13.4.3;Waiting for Agents;120
13.4.4;Shutting Down Agents;120
13.4.5;When to Use Agents;121
13.5;Vars and Thread-Local State;121
13.5.1;When to Use Thread-Local Vars;122
13.6;Keeping Track of Identities;123
13.6.1;Validators;123
13.6.2;Watches;124
13.7;Summary;125
14;Chapter 7 Namespaces and Libraries;126
14.1;Organizing Clojure Code;126
14.2;Namespace Basics;126
14.2.1;Switching Namespaces with in-ns;126
14.2.2;Referring to Other Namespaces;127
14.3;Loading Other Namespaces;128
14.3.1;Loading from a File or Stream;128
14.3.2;Loading from the Classpath;129
14.3.2.1;Namespace Names vs. File Names;129
14.3.2.2;Loading Resources from the Classpath;129
14.3.3;Loading and Referring Namespaces in One Step;131
14.3.4;Importing Java Classes;131
14.4;Bringing It All Together: Namespace Declarations;132
14.5;Symbols and Namespaces;132
14.5.1;Namespace Metadata;133
14.5.2;Forward Declarations;133
14.5.3;Namespace-Qualified Symbols and Keywords;133
14.5.4;Constructing Symbols and Keywords;134
14.5.5;Public and Private Vars;134
14.6;Advanced Namespace Operations;135
14.6.1;Querying Namespaces;135
14.6.2;Manipulating Namespaces;136
14.7;Namespaces As References;137
14.8;Summary;137
15;Chapter 8 Metadata;138
15.1;Reading and Writing Metadata;138
15.2;Metadata-Preserving Operations;139
15.3;Read-Time Metadata;140
15.4;Metadata on Vars;140
15.4.1;Type Tags;142
15.4.2;Private Vars;142
15.5;Metadata on Reference Types;142
15.6;Summary;142
16;Chapter 9 Multimethods and Hierarchies;143
16.1;Multimethods;143
16.1.1;Multiple Dispatch;145
16.1.2;Default Dispatch Values;145
16.2;Hierarchies;146
16.2.1;Querying Hierarchies;147
16.3;Hierarchies with Multimethods;147
16.3.1;Hierarchies with Java Classes;148
16.3.2;More Hierarchy Queries;149
16.3.3;Resolving Conflicts;149
16.3.4;Type Tags;151
16.4;User-Defined Hierarchies;151
16.5;Summary;152
17;Chapter 10 Java Interoperability;153
17.1;Calling Java from Clojure;153
17.1.1;Java Interop Special Forms;153
17.1.2;Java Interop Preferred Forms;154
17.1.3;Clojure Types and Java Interfaces;155
17.1.4;Java Arrays;156
17.1.4.1;Creating Arrays;157
17.1.4.2;Manipulating Arrays;158
17.1.4.3;Iterating Over Arrays;158
17.2;Calling Clojure from Java;158
17.2.1;Loading and Evaluating Clojure Code;159
17.2.2;Using Clojure Functions and Vars;159
17.3;Creating Java Classes;160
17.3.1;Proxying Java Classes;160
17.3.2;Generating Java Classes;161
17.3.2.1;Ahead-of-Time Compilation;162
17.3.2.2;Basic gen-class Options;164
17.3.2.3;Defining Methods for the Generated Class;164
17.3.2.4;Adding State to the Generated Class;164
17.3.2.5;Adding Methods to the Generated Class;165
17.3.2.6;Adding Constructors and Factories;165
17.3.2.7;Exposing Superclass Members;166
17.3.2.8;Generating Command-Line Programs;166
17.3.2.9;Loading the Implementation;166
17.3.2.10;Namespace Declarations with gen-class;166
17.3.2.11;Simple Command-Line Program;167
17.4;Summary;167
18;Chapter 11 Parallel Programming;168
18.1;Parallelism in Clojure;168
18.2;Agents;168
18.2.1;Agent Thread Pools;168
18.2.2;Agent Example;169
18.2.3;Concurrent Agent Performance;170
18.3;Concurrency Functions;170
18.3.1;Overhead and Performance;171
18.4;Futures and Promises;172
18.4.1;Futures;172
18.4.1.1;Controlling Futures;173
18.4.2;Promises;173
18.5;Java-based Threading;174
18.5.1;Creating a Thread;174
18.6;Summary;175
19;Chapter 12 Macros and Metaprogramming;176
19.1;What Is Metaprogramming?;176
19.1.1;Code vs. Data;176
19.1.2;Homoiconicity;176
19.2;Macros;177
19.2.1;Working with Macros;178
19.2.1.1;Debugging Macros;179
19.2.2;Code Templating;180
19.2.2.1;Splicing Unquotes;180
19.2.3;Generating Symbols;181
19.2.4;When to Use Macros;182
19.2.5;Using Macros;182
19.2.5.1;Implementing a Control Structure;182
19.2.5.2;Implementing a Macro with Variadic Arguments;183
19.2.5.3;Implementing a Macro Using Recursion;185
19.2.6;Using Macros to Create DSLs;185
19.3;Summary;187
20;Chapter 13 Datatypes and Protocols;188
20.1;Protocols;188
20.1.1;Protocols As Interfaces;189
20.2;Datatypes;189
20.3;Implementing Protocols and Interfaces;190
20.3.1;In-Line Methods;190
20.3.2;Extending Java Interfaces;191
20.3.3;Datatypes As Classes;192
20.4;Extending Protocols to Pre-Existing Types;192
20.4.1;Extending Java Classes and Interfaces;193
20.5;Reifying Anonymous Datatypes;193
20.6;Working with Datatypes and Protocols;194
20.6.1;A Complete Example;195
20.7;Advanced Datatypes;195
20.8;Summary;196
21;Chapter 14 Performance;197
21.1;Profiling on the JVM;197
21.1.1;General Tips for Java Performance;197
21.1.2;Simple Profiling with Time;198
21.1.3;Using Java Profiling Tools;198
21.2;Memoization;199
21.3;Reflection and Type Hints;199
21.4;Working with Primitives;201
21.4.1;Loop Primitives;201
21.4.2;Unchecked Integer Arithmetic;202
21.4.3;Primitive Arrays;203
21.5;Transients;203
21.6;Var Lookups;204
21.7;Inlining;205
21.7.1;Macros and definline;205
21.8;Summary;205
22;Index;207



Ihre Fragen, Wünsche oder Anmerkungen
Vorname*
Nachname*
Ihre E-Mail-Adresse*
Kundennr.
Ihre Nachricht*
Lediglich mit * gekennzeichnete Felder sind Pflichtfelder.
Wenn Sie die im Kontaktformular eingegebenen Daten durch Klick auf den nachfolgenden Button übersenden, erklären Sie sich damit einverstanden, dass wir Ihr Angaben für die Beantwortung Ihrer Anfrage verwenden. Selbstverständlich werden Ihre Daten vertraulich behandelt und nicht an Dritte weitergegeben. Sie können der Verwendung Ihrer Daten jederzeit widersprechen. Das Datenhandling bei Sack Fachmedien erklären wir Ihnen in unserer Datenschutzerklärung.