A complete guide to the programming language
Andreas Rumpf

#Nim
#Python
#C++
#Lisp
Nim is a general-purpose programming language inspired by Python, C++ and Lisp. Its most important features are type and resource safety, meta programming and combining readability with syntactic convenience.
Learning a programming language is a huge time investment. Why should you learn Nim?
Nim rewards you with a single coherent language that can be used for everything and it works well on everything:
It runs on virtually every operating system and on web browsers, as well as on tiny embedded devices and even on GPUs.
Nim's complexity is still very manageable, this book tries to cover Nim completely in about 300 pages.
Some describe Nim as a "better Python with types, macros and C's speed".
But please dive in and see for yourself!
Table of contents
Part I - Introduction to Nim via graphics
1 - Introduction
2 - Drawing a line
2.1 - Drawing horizontal and vertical lines
2.1.1 - Drawing a line using one point, length, direction
2.1.2 - Drawing a line by specifying start and end
3 - Rendering Text
4 - Sequences
5 - Parameter passing and mutability
6 - Let vs Var
7 - Iterators
7.1 - Yield
8 - Generics
9 - Templates
10 - Macros
Part II - Nim language specification
11 - Basic terms
12 - Lexical analysis
12.1 - Notation used in this chapter
12.2 - Indentation
12.3 - Comments
12.4 - Multiline comments
12.5 - Identifiers & Keywords
12.6 - Identifier equality
12.7 - String literals
12.8 - Triple quoted string literals
12.9 - Raw string literals
12.10 - Generalized raw string literals
12.11 - Character literals
12.12 - Numeric Literals
12.12.1 - Custom Numeric Literals
12.13 - Operators
12.14 - Other tokens
12.15 - Unicode Operators
13 - Syntax
13.1 - Associativity
13.1.1 - Precedence
13.2 - Dot-like operators
14 - Declarations and scope rules
15 - Modules
15.1 - Export marker
15.2 - Module processing
15.3 - Import statement
15.4 - Include statement
15.5 - Module names in imports
15.6 - Collective imports from a directory
15.7 - Pseudo import/include paths
15.8 - From import statement
15.9 - Export statement
15.10 - Scope rules
15.10.1 - Block scope
15.10.2 - Tuple or object scope
15.10.3 - Module scope
16 - Type system
16.1 - Ordinal types
16.2 - Pre-defined integer types
16.3 - Integer literals
16.4 - Subrange types
16.5 - Pre-defined floating-point types
16.5.1 - Nan and Inf checks
16.6 - Boolean type
16.7 - Character type
16.8 - Enumeration types
16.9 - Overloadable enum field names
16.10 - String type
16.11 - cstring type
16.12 - Structured types
16.13 - Array and sequence types
16.14 - Open arrays
16.15 - Varargs
16.16 - Unchecked arrays
16.17 - Tuples and object types
16.18 - fields and fieldPairs iterators
16.19 - Object construction
16.20 - Object variants
16.21 - cast uncheckedAssign
16.22 - Set type
16.22.1 - Bit fields
16.23 - Reference and pointer types
16.24 - Nil
16.25 - Procedural type
16.26 - Calling conventions
16.27 - Distinct type
16.27.1 - borrow annotation
16.28 - Auto type
16.29 - static[T]
16.30 - typedesc[T]
16.31 - typeof
17 - Type relations
17.1 - Type equality
17.2 - Subtype relation
17.3 - Convertible relation
17.4 - Assignment compatibility
18 - Constant expressions
19 - Overload resolution
19.1 - Overloading based on 'var T'
19.2 - Lazy type resolution for untyped
19.3 - Varargs matching
19.4 - Overload disambiguation
20 - Statements and expressions
20.1 - Statement list expression
20.2 - Discard statement
20.3 - Void context
20.4 - Var statement
20.5 - Let statement
20.6 - Tuple unpacking
20.7 - Const statement
20.8 - Type section
20.9 - Static statement/expression
20.10 - If statement
20.11 - Case statement
20.12 - When statement
20.13 - Return statement
20.14 - Yield statement
20.15 - Block statement
20.16 - Break statement
20.17 - While statement
20.18 - Continue statement
20.19 - Using statement
20.20 - If expression
20.21 - When expression
20.22 - Case expression
20.23 - Block expression
20.24 - Table constructor
20.25 - Type conversions
20.26 - Type casts
20.27 - The addr operator
20.28 - The unsafeAddr operator
21 - Procedures
21.1 - Method call syntax
21.2 - Properties
21.3 - Indexing
21.4 - Command invocation syntax
21.5 - Closures
21.5.1 - Creating closures in loops
21.6 - Anonymous procs
21.7 - Func
21.8 - Non-overloadable built-ins
21.9 - Var parameters
21.10 - Var return type
22 - Methods
22.1 - Static method calls via procCall
23 - Iterators and the for statement
23.1 - Implicit items/pairs invocations
23.2 - First-class iterators
24 - User definable conversions
24.1 - Converters
25 - Exception handling
25.1 - Try statement
25.2 - Try expression
25.3 - Except clauses
25.4 - Defer statement
25.5 - Exception hierarchy
25.6 - Raise statement
26 - Effect system
26.1 - Exception tracking
26.2 - EffectsOf annotation
26.3 - Tag tracking
26.4 - Side effects
26.5 - GC safety effect
27 - Generics
27.1 - Is operator
27.2 - Type Classes
27.3 - Implicit generics
27.4 - Generic inference restrictions
27.5 - Symbol lookup in generics
27.5.1 - Open and Closed symbols
27.6 - Mixin statement
27.7 - Bind statement
27.8 - Delegating bind statements
27.9 - Templates
27.10 - Typed vs untyped parameters
27.11 - Passing a code block to a template
27.12 - Varargs of untyped
27.13 - Symbol binding in templates
27.14 - Identifier construction
27.15 - Template parameter lookup rules
27.16 - Hygiene in templates
27.16.1 - Inject and gensym
27.17 - Method call syntax limitations
28 - Macros
28.1 - Macros API
28.2 - BindSym
28.3 - For loop macros
29 - Lifetime-tracking hooks
29.1 - =destroy hook
29.2 - =wasMoved hook
29.3 - =sink hook
29.4 - =copy hook
29.5 - =dup hook
29.6 - =trace hook
29.7 - Move semantics
29.8 - Swap
29.9 - Sink parameters
29.10 - Rewrite rules
29.11 - Object and array construction
29.12 - Destructor removal
29.13 - Self assignments
29.14 - Lent type
29.15 - The .cursor annotation
29.16 - Cursor inference / copy elision
29.17 - Hook lifting
29.18 - Hook generation
29.19 - nodestroy pragma
29.20 - Copy on write
29.21 - Practice
30 - Strict funcs
31 - View types
31.1 - Path expressions
31.2 - Start of a borrow
31.3 - End of a borrow
31.4 - Reborrows
Part III - Mastering Macros
32 - Introduction
33 - AST introspection
33.1 - Typed vs untyped ASTs
34 - AST creation
35 - Collect macro
36 - strformat
37 - strscans
38 - HTML trees
39 - Advice
Part IV - Mastering Parallelism
40 - Introduction
41 - Threading
41.1 - createThread
41.2 - Single worker, single channel
41.3 - Multiple workers, single channel
42 - spawn
42.1 - Return values
42.2 - Sharing memory
43 - Isolated data
44 - Smart pointers
45 - Parallel for each and reduce
45.1 - parMap
45.2 - parReduce
45.3 - parFind
46 - Final advice
46.1 - What to avoid
46.2 - What to use
Appendix A - Grammar
Appendix B - Nim standard library cheat sheet
B.1 - Integers
B.2 - Strings
B.3 - Sequences
B.4 - Bit sets
B.5 - Hashes
B.6 - Hash sets
B.7 - Hash tables
B.8 - Optionals
B.9 - String formatting
B.10 - Algorithms
B.11 - OS
B.12 - JSON
B.13 - Unicode
About the Author
Andreas Rumpf is the designer and original implementor of Nim. He received a diploma in computer science from the University of Kaiserslautern, Germany. His research interests include hard realtime systems, embedded systems, compiler construction and artificial intelligence.









