Lunar Programming Language

by David A. Moon
January 2017 - January 2018



Last updated 9/17/2023.

Table of Contents

1. Introduction
1.1 Principles
1.2 Examples
2. Organizing Mechanisms
3. Data
3.1 Slots
3.2 Class Inheritance
3.3 Constructors
4. Behavior
4.1 Function Bundles
4.2 Methods
4.3 Method Selection
4.4 Casting and Delegation
4.5 Sealed Methods
4.6 Dominant Methods
4.7 Intrinsic Methods
5. Syntax
5.1 Tokens, Comments, and Whitespace
5.2 Meta-Syntax
6. Expressions
6.1 Bodies
6.2 Operators
6.3 Particles
6.4 Grouping
6.5 Function Call
6.6 Actual Parameter List
6.7 Literals
7. Statements
7.1 If Statement
7.2 Case Statement
7.3 Block Statement
7.3.1 Early Exit
7.3.2 Cleanup
7.3.3 Parsing the Block Statement
7.4 Iteration Statements
7.5 Function Statement
7.6 Formal Parameter List
7.7 Curried Functions
7.8 Assignment Statement
8. Definitions
8.1 Scope
8.1.1 Hoisting
8.2 Constant Definition
8.3 Variable Definition
8.4 Method Definition
8.5 Forward Definition
8.6 Operator Definition
8.7 Macro Definition
8.8 Class Definition
8.8.1 Simple Class Definition
8.8.2 Class Modifiers
9. For Statement
9.1 Predefined Emitters
9.2 Predefined Collectors
9.3 Extending Emitters
9.4 Extending Collectors
9.5 Definition of the for Macro
10. Bundles
11. Generic Classes
11.1 Syntax
12. Generic Methods
12.1 Syntax
13. Protocols
14. Basic Data Types
14.1 Everything
14.2 Nothing
14.3 Boolean
14.4 Name
14.5 Character
14.6 Number
14.6.1 Integer
14.6.2 Float
14.7 Type
14.7.1 Class
14.7.2 Range
14.7.3 Set
14.7.4 Union
14.7.5 Intersection
14.8 Function
14.9 Method
15. Collection Types
15.1 Sequences
15.2 Reversible Sequences
15.3 Keyed Sequences
15.4 Successions
15.5 Lists
15.6 Stacks
15.7 Ranges
15.8 Strings
15.9 Sets
15.10 Maps
15.11 Sequence Operators
15.12 Sequence Functions
16. Displays and Comprehensions
16.1 List Displays
16.2 List Comprehensions
16.3 Set Displays
16.4 Set Comprehensions
16.5 Map Displays
16.6 Map Comprehensions
17. Strings
17.1 String-specific functions
17.2 UTF-8 Utilities
17.3 String Interpolation
17.3.1 Interpolation Parameters
18. Streams
19. Destructuring
19.1 Nested Destructuring
19.2 Destructuring Constant Definition
19.3 Destructuring Formal Parameters
19.4 Destructuring Syntax and its Parsing
19.5 Defining Destructuring Behavior
19.6 String Destructuring
20. Modules
20.1 Module-Related Modifiers
20.2 Built-In Modules
21. Parsing
21.1 Token Streams
22. Patterns
22.1 Pattern Constants
22.2 Pattern Variables
22.3 Pattern Punctuation
22.4 Syntactic Constructs
23. Templates
23.1 Template Examples
24. Macros
24.1 Macro Definitions
24.1.1 Infix Macro Definitions
24.2 Name In Context
24.3 Hygienic Macros
25. Program Representation
26. Parsing the Def Statement
26.1 Method Modifiers
26.2 Parsing Formal Parameters
26.3 Type Declarations are Evaluated at Compile Time
26.4 Parsing Method Heads
26.5 Parsing Def
27. Exception Handling
27.1 Catch and Throw
27.2 Catch Statement
27.3 Exceptions
27.3.1 assert statement
27.4 Exception Handlers
27.5 Exception Restarts
27.6 Pre-defined Exceptions
28. Thrilling Examples
28.1 Suffix Macros
28.2 Percentages
28.3 S-Expressions
28.4 Parsing Expressions
29. Compiler Optimization
30. Method Selection Optimization
31. All Programming Languages are Wrong
32. Bootstrap Lunar



Creative Commons License
Lunar by David A. Moon is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Please inform me if you find this useful, or use any of the ideas embedded in it.
Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.