├── FeatureTracking.md ├── README.md ├── Resources ├── Derpy-Outlined.svg ├── Derpy.svg ├── Emojis │ ├── angry.svg │ ├── approved.svg │ ├── blush.svg │ ├── confused.svg │ ├── cry.svg │ ├── emojis.svg │ ├── facepalm.svg │ ├── glasses.svg │ ├── gun.svg │ ├── hearteyes.svg │ ├── lol.svg │ ├── party.svg │ ├── ree.svg │ ├── sad.svg │ ├── sick.svg │ ├── sip.svg │ ├── sleep.svg │ ├── smile.svg │ ├── think.svg │ └── triggered.svg ├── LICENSE ├── Logo-Long-Inverted-Outline.svg ├── Logo-Long-Inverted.svg ├── Logo-Long.svg ├── Logo-Short-Inverted-Outline.svg ├── Logo-Short-Inverted.svg └── Logo-Short.svg ├── Samples ├── 99BottlesOfBeer.draco ├── FizzBuzz.draco ├── FizzBuzzWithPatternMatching.draco ├── HashDeriveMacro.draco ├── LICENSE ├── ListProceduralMacro.draco ├── MemoizeMacro.draco ├── Quine.draco ├── RecursiveFibonacci.draco └── TruthMachine.draco └── Specification ├── Comments.md ├── ControlFlow.md ├── EntryPoint.md ├── ExpressionsAndBuiltins.md ├── Generics.md ├── Introduction.md ├── LICENSE ├── ModuleSystem.md └── Overloading.md /FeatureTracking.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | This document attempts to collect all aspects of a language (by some opinionated partitioning). The number of issues is becoming significant, and we need to know what we need to work on to actually get somewhere. Feel free to add aspects that are currently left out. 4 | 5 | Legend: 6 | - 🟢 - well-designed 7 | - 🟡 - a lot of work is still required, but first steps are made 8 | - 🔴 - hasn't been considered yet 9 | 10 | ## General features 11 | 12 | * 🟢 Variables 13 | * basic structure proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 14 | * [The val and var issue](https://github.com/Draco-lang/Language-suggestions/issues/12) 15 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) for both global and local variables 16 | * 🟡 Functions/methods 17 | * 🟢 Free functions 18 | * Proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 19 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) 20 | * 🟡 Member functions 21 | * Proposed in the issue about [record types](https://github.com/Draco-lang/Language-suggestions/issues/41) 22 | * 🟢 Main Function 23 | * Proposed in [Main function signatures issue](https://github.com/Draco-lang/Language-suggestions/issues/63) 24 | * Specification in [RFC0004](https://github.com/Draco-lang/Language-suggestions/pull/78) and [RFC0013](https://github.com/Draco-lang/Language-suggestions/pull/117) 25 | * 🟡 Control structures 26 | * 🟢 If-else 27 | * Proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 28 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) 29 | * 🟢 While-loop 30 | * Proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 31 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) 32 | * 🟡 For-loop 33 | * Proposed in [proposal 0.2](https://github.com/Draco-lang/Language-suggestions/issues/40) 34 | * 🟡 Match 35 | * Proposed in the [pattern matching issue](https://github.com/Draco-lang/Language-suggestions/issues/44) 36 | * 🟢 Goto 37 | * Proposed in the [goto and implicit loop labels issue](https://github.com/Draco-lang/Language-suggestions/issues/45) 38 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) 39 | * 🟢 Break/continue in loops 40 | * Proposed in the [goto and implicit loop labels issue](https://github.com/Draco-lang/Language-suggestions/issues/45) as specialized labels 41 | * Specification in [RFC0001](https://github.com/Draco-lang/Language-suggestions/pull/55) 42 | * 🟡 Let ... in construct 43 | * [Proposal](https://github.com/Draco-lang/Language-suggestions/issues/51) 44 | * 🟢Literal values 45 | * Proposal in the [literal values issue](https://github.com/Draco-lang/Language-suggestions/issues/50) 46 | * [String interpolation issue](https://github.com/Draco-lang/Language-suggestions/issues/53) 47 | * Specification for string literals in [RFC0005](https://github.com/Draco-lang/Language-suggestions/pull/79) 48 | * Specification for primitive literals in [RFC0002](https://github.com/Draco-lang/Language-suggestions/pull/56) 49 | * 🟡 Operators 50 | * Basic, built-in operators proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 51 | * [Exponential operator](https://github.com/Draco-lang/Language-suggestions/issues/34) 52 | * [Implies operator](https://github.com/Draco-lang/Language-suggestions/issues/36) 53 | * [Inequality syntax](https://github.com/Draco-lang/Language-suggestions/issues/35) 54 | * [Colon as tuple construction](https://github.com/Draco-lang/Language-suggestions/issues/22) 55 | * [User-defined operators](https://github.com/Draco-lang/Language-suggestions/issues/72) 56 | * Specification for basic operators in [RFC0002](https://github.com/Draco-lang/Language-suggestions/pull/56) 57 | * 🟡 Exceptions, throwing, catching 58 | * [Exceptions, try-catch-finally proposal](https://github.com/Draco-lang/Language-suggestions/issues/54) 59 | * 🟢 Modules 60 | * [Issue about declarations and definitions](https://github.com/Draco-lang/Language-suggestions/issues/30) 61 | * The [module system issue](https://github.com/Draco-lang/Language-suggestions/issues/58) 62 | * Specification for module system in [RFC0011](https://github.com/Draco-lang/Language-suggestions/pull/112) 63 | 64 | ## Type-system 65 | 66 | * 🟡 Built-in primitives 67 | * Many are proposed in [proposal 0.1](https://github.com/Draco-lang/Language-suggestions/issues/33) 68 | * There are quite a few left out, never mentioned (like interop primitives) 69 | * Specification in [RFC0002](https://github.com/Draco-lang/Language-suggestions/pull/56) 70 | * 🟡 Record types 71 | * Proposal about the [basics of record types](https://github.com/Draco-lang/Language-suggestions/issues/41) 72 | * 🟡 Discriminated unions 73 | * [The DUs vs inheritance issue](https://github.com/Draco-lang/Language-suggestions/issues/5) 74 | * 🟡 Traits 75 | * [Proposal](https://github.com/Draco-lang/Language-suggestions/issues/52) 76 | * [Internals](https://github.com/Draco-lang/Language-suggestions/issues/39) 77 | * Very much related and strong hints are in the [record types issue](https://github.com/Draco-lang/Language-suggestions/issues/41) 78 | * 🟡 Properties 79 | * Issue about possibilities, possible syntaxes [for properties](https://github.com/Draco-lang/Language-suggestions/issues/47) 80 | * 🟡 Type-inference 81 | * Overview is in the [proposal 0.2](https://github.com/Draco-lang/Language-suggestions/issues/40) 82 | * There is the [type inference issue](https://github.com/Draco-lang/Language-suggestions/issues/42) 83 | * The initial [inference issue](https://github.com/Draco-lang/Language-suggestions/issues/10) 84 | * 🟢 Overloading 85 | * Overview is in the [proposal 0.2](https://github.com/Draco-lang/Language-suggestions/issues/40) 86 | * Specification for overloading in [RFC0010](https://github.com/Draco-lang/Language-suggestions/pull/111) and [RFC0012](https://github.com/Draco-lang/Language-suggestions/pull/115) 87 | * 🟡 Generics 88 | * For methods, mentioned in [proposal 0.2](https://github.com/Draco-lang/Language-suggestions/issues/40) 89 | * For methods specification in [RFC0012](https://github.com/Draco-lang/Language-suggestions/pull/115) 90 | * For types, nothing is mentioned yet 91 | * 🟡 Nullability 92 | * The issue [about erasable nullables](https://github.com/Draco-lang/Language-suggestions/issues/24) 93 | * 🔴 Casting 94 | * Not mentioned anywhere yet 95 | 96 | ## Special features 97 | 98 | * 🔴 Asynchronous programming 99 | * Not mentioned anywhere yet 100 | * 🔴 Generators 101 | * Not mentioned anywhere yet 102 | * 🟡 Pattern matching 103 | * Proposed in the [pattern matching issue](https://github.com/Draco-lang/Language-suggestions/issues/44) 104 | * [Case-exclusion issue](https://github.com/Draco-lang/Language-suggestions/issues/9) 105 | * 🟡 Lambda functions 106 | * Discussed in the [lambdas issue](https://github.com/Draco-lang/Language-suggestions/issues/49) 107 | 108 | 109 | ## Metaprogramming 110 | 111 | * 🟡 Attributes 112 | * Briefly mentioned in the [metaprogramming issue](https://github.com/Draco-lang/Language-suggestions/issues/16) 113 | * Nothing exact proposed yet 114 | * 🟡 Derive-metchanism 115 | * Briefly mentioned in the [metaprogramming issue](https://github.com/Draco-lang/Language-suggestions/issues/16) 116 | * Nothing exact proposed yet 117 | * 🟡 Macro-system 118 | * Possibilities outlined in the [metaprogramming issue](https://github.com/Draco-lang/Language-suggestions/issues/16) 119 | * A slightly more detailed "wish-list" for capabilities in the [F# CEs expressed as higher-order macros issue](https://github.com/Draco-lang/Language-suggestions/issues/29) 120 | 121 | ## Other 122 | 123 | * 🟢 Documentation 124 | * [Documentation comments issue](https://github.com/Draco-lang/Language-suggestions/issues/37) 125 | * Specifications in [RFC0009](https://github.com/Draco-lang/Language-suggestions/pull/102) 126 | * 🟡 Enforcing TCO 127 | * [tailrec proposal](https://github.com/Draco-lang/Language-suggestions/issues/11) 128 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |

5 | 6 |

A new .NET programming language in the making

7 | 8 |

9 | Discord 10 |

11 | 12 | ### Important about this repository 13 | 14 | This was the initial repository we created to formulate very random ideas about designing a language. There are many-many issues discussing design choices ranging from "the usual" to very radical or plain weird ones. **The language isn't the collection of these issues.** We use these issues to initiate discussions, shift perspectives, collect ideas from other languages and so on. Currently, the actual [specification](Specification) is extremely small and bare-bones. 15 | 16 | ### I just want to see how the language looks! 17 | 18 | [See the Samples folder.](./Samples/) 19 | 20 | ### The aims of the language 21 | 22 | > I want to do to C# what Kotlin did to Java 23 | 24 | Draco should be a high-level language which could replace C#. Here are a few major key points that we aren't changing: 25 | 26 | * It is strongly statically typed 27 | * It is not academic & should be easily used by a regular .NET developer 28 | * It should be more or less readable by people not knowing it (as opposed to ML, for instance) 29 | * It should be debuggable 30 | * It prefers generalized approaches over sugared special cases 31 | * It adds a bigger and more worked out feature earlier, than an underspecified one that will result in extra features to work out the missed use cases 32 | 33 | ### Current state of the project 34 | 35 | There is a very basic and not finished [Compiler](https://github.com/Draco-lang/Compiler). 36 | 37 | Right now we are still working out the core of the language. We do this by collecting ideas, inspiration, frustrating things and useful bits from existing languages. We have started working on a specification (see the [Specification](Specification) folder) and you can see an [examples folder](./Samples/) that we try to keep updated to more or less reflect our current idea of the language. You can also take a look at the [feature tracking](FeatureTracking.md) document, where we keep track of all features we want to investigate. 38 | 39 | ### Our workflow 40 | 41 | 1. We start from an idea or a discussion, usually either on our [Discord server](https://discord.gg/gHfhpPFzYu) or in an issue. 42 | 2. The ideas we like are then worked on as an issue, we append comments, elaborate on the features and internals. 43 | 3. When we want to add something to the specification, we either create a new, or edit an existing file in the [Specification](Specification) folder, write the specification document and open a Pull Request with the name `RFCnnnn - Short description`. 44 | 4. We critique the RFC, modify if needed, even leave out features we can't agree on for a while. 45 | 5. When no more comments arrive on the RFC and we can agree on the feature, we merge it into the specification. 46 | 47 | ### Propose your ideas! 48 | 49 | Now that you grasped the main idea, feel free to open an issue which 50 | 51 | * Proposes a language idea. No strict requirements, so for now, any idea is welcomed 52 | * Tells about your experience using any programming language. Tell us what you find interesting about a language or what you disliked about it 53 | -------------------------------------------------------------------------------- /Resources/Derpy-Outlined.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 49 | 51 | 52 | 54 | image/svg+xml 55 | 57 | 58 | 59 | 60 | 61 | 67 | 72 | 78 | 79 | 85 | 90 | 95 | 96 | 101 | 106 | 107 | 113 | 119 | 123 | 129 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /Resources/Derpy.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 43 | 45 | 46 | 48 | image/svg+xml 49 | 51 | 52 | 53 | 54 | 55 | 60 | 66 | 67 | 73 | 78 | 79 | 84 | 89 | 90 | 96 | 102 | 103 | 109 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Resources/Emojis/angry.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 70 | 71 | 77 | 82 | 83 | 89 | 95 | 96 | 102 | 107 | 108 | 114 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /Resources/Emojis/approved.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 69 | 70 | 76 | 81 | 82 | 88 | 91 | 94 | 99 | 104 | 105 | 106 | 107 | 112 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /Resources/Emojis/blush.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 69 | 70 | 75 | 80 | 81 | 87 | 92 | 93 | 99 | 102 | 108 | 114 | 120 | 126 | 131 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /Resources/Emojis/confused.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 47 | 49 | 50 | 52 | image/svg+xml 53 | 55 | 56 | 57 | 58 | 59 | 65 | 70 | 71 | 77 | 85 | 86 | 92 | 100 | 108 | 116 | 117 | 122 | ? ? 151 | 152 | -------------------------------------------------------------------------------- /Resources/Emojis/cry.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 47 | 49 | 50 | 52 | image/svg+xml 53 | 55 | 56 | 57 | 58 | 59 | 65 | 70 | 71 | 76 | 82 | 83 | 88 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /Resources/Emojis/facepalm.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 70 | 71 | 76 | 81 | 82 | 88 | 94 | 95 | 101 | 107 | 113 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Resources/Emojis/glasses.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 69 | 70 | 76 | 81 | 82 | 88 | 94 | 95 | 101 | 106 | 107 | 113 | 118 | 123 | 124 | 131 | 138 | 139 | 144 | 150 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /Resources/Emojis/gun.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 69 | 74 | 75 | 80 | 85 | 86 | 92 | 97 | 102 | 107 | 114 | 121 | 126 | 127 | 132 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /Resources/Emojis/hearteyes.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 74 | 80 | 81 | 86 | 92 | 98 | 99 | 104 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /Resources/Emojis/lol.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 74 | 79 | 80 | 85 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Resources/Emojis/party.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 75 | 82 | 83 | 89 | 94 | 95 | 101 | 106 | 107 | 112 | 117 | 122 | 127 | 132 | 138 | 139 | 145 | 150 | 151 | 157 | 163 | 168 | 173 | 179 | 185 | 186 | 192 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /Resources/Emojis/ree.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 75 | 83 | 84 | 89 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Resources/Emojis/sad.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 69 | 70 | 75 | 80 | 81 | 86 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /Resources/Emojis/sick.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 25 | 28 | 32 | 33 | 34 | 56 | 58 | 59 | 61 | image/svg+xml 62 | 64 | 65 | 66 | 67 | 68 | 74 | 79 | 80 | 84 | 87 | 92 | 97 | 102 | 108 | 114 | 115 | 116 | 121 | 124 | 130 | 135 | 136 | 137 | 142 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /Resources/Emojis/sip.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 64 | 70 | 75 | 81 | 86 | 92 | 98 | 103 | 110 | 117 | 118 | 123 | 129 | 134 | 139 | 144 | 145 | 151 | 157 | 162 | 163 | 168 | 173 | 174 | 179 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /Resources/Emojis/sleep.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 74 | 79 | 80 | 85 | 91 | 92 | 97 | 102 | 103 | 108 | 113 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Resources/Emojis/smile.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 49 | 51 | 52 | 54 | image/svg+xml 55 | 57 | 58 | 59 | 60 | 61 | 67 | 72 | 77 | 78 | 83 | 88 | 89 | 95 | 101 | 105 | 111 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /Resources/Emojis/think.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 68 | 69 | 74 | 79 | 85 | 86 | 91 | 96 | 97 | 102 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /Resources/Logo-Short-Inverted.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 49 | 51 | 52 | 54 | image/svg+xml 55 | 57 | 58 | 59 | 60 | 61 | 67 | 72 | 77 | 82 | 88 | 94 | 99 | 105 | 110 | 115 | 121 | 127 | 128 | 133 | 144 | 145 | 150 | 155 | 159 | 160 | 165 | 169 | 174 | 178 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /Resources/Logo-Short.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 49 | 51 | 52 | 54 | image/svg+xml 55 | 57 | 58 | 59 | 60 | 61 | 67 | 72 | 77 | 82 | 88 | 94 | 99 | 105 | 110 | 115 | 121 | 127 | 128 | 133 | 144 | 145 | 150 | 155 | 160 | 161 | 162 | -------------------------------------------------------------------------------- /Samples/99BottlesOfBeer.draco: -------------------------------------------------------------------------------- 1 | import System.Linq.Enumerable; 2 | import System.Console; 3 | 4 | func main() { 5 | func capitalize(s: string): string = 6 | "\{char.ToUpper(s[0])}\{s.Substring(1)}"; 7 | 8 | func bottles(n: int32): string = match (n) 9 | { 10 | 0 -> "no more bottles"; 11 | 1 -> "1 bottle"; 12 | _ -> "\{n} bottles"; 13 | }; 14 | 15 | for (var i in Reverse(Range(1, 99))) { 16 | WriteLine(""" 17 | \{capitalize(bottles(i))} of beer on the wall, \{bottles(i)} of beer. 18 | Take one down, pass it around, \{bottles(i - 1)} of beer on the wall. 19 | """); 20 | } 21 | WriteLine(""" 22 | No more bottles of beer on the wall, no more bottles of beer. 23 | Go to the store and buy some more, 99 bottles of beer on the wall. 24 | """); 25 | } 26 | -------------------------------------------------------------------------------- /Samples/FizzBuzz.draco: -------------------------------------------------------------------------------- 1 | import System.Console; 2 | import System.Linq.Enumerable; 3 | 4 | func main() { 5 | for (i in Range(100)) { 6 | if (i mod 3 != 0 and i mod 5 != 0) { 7 | WriteLine(i); 8 | goto continue; 9 | } 10 | if (i mod 3 == 0) Write("Fizz"); 11 | if (i mod 5 == 0) Write("Buzz"); 12 | WriteLine(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Samples/FizzBuzzWithPatternMatching.draco: -------------------------------------------------------------------------------- 1 | import System.Console; 2 | import System.Linq.Enumerable; 3 | 4 | func main() { 5 | for (i in Range(100)) { 6 | match (i mod 3, i mod 5) { 7 | (0, 0) -> WriteLine("FizzBuzz"); 8 | (0, _) -> WriteLine("Fizz"); 9 | (_, 0) -> WriteLine("Buzz"); 10 | _ -> WriteLine(i); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Samples/HashDeriveMacro.draco: -------------------------------------------------------------------------------- 1 | import System.Collections.Generic; 2 | 3 | // Derive macros are a special case of attribute macros. They only append code 4 | // to the existing target instead of modifying it. This typically allows us to 5 | // implement extra traits for an annotated type. 6 | @derive_macro(Hash) 7 | func hash_derive(target: Ast, args: []Ast): Result { 8 | // We expect a type as a target 9 | val target = target.asTypeDeclaration(); 10 | 11 | // We don't expect any arguments 12 | if (args.Length > 0) return MacroExpansionError("Hash derive expects no arguments!"); 13 | 14 | // Generate the Add calls to the System.HashCode instance 15 | val adds = List(); 16 | for (m in target.Members) adds.Add(quote!{ hashCode.Add(this.#(m.name)); }); 17 | 18 | // Implement the function for the type 19 | return quote!{ 20 | impl #(target.Name) { 21 | func GetHashCode(this): int32 { 22 | val hashCode = System.HashCode(); 23 | #(adds)... 24 | return hashCode.ToHashCode(); 25 | } 26 | } 27 | }; 28 | } 29 | 30 | // Example time! 31 | 32 | @derive(Hash) 33 | type Person(name: string, age: int32); 34 | 35 | // The extra generated code: 36 | impl Person { 37 | func GetHashCode(this): int32 { 38 | val hashCode = System.HashCode(); 39 | hashCode.Add(this.name); 40 | hashCode.Add(this.age); 41 | return hashCode.ToHashCode(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Samples/LICENSE: -------------------------------------------------------------------------------- 1 | CC0 1.0 Universal 2 | 3 | Statement of Purpose 4 | 5 | The laws of most jurisdictions throughout the world automatically confer 6 | exclusive Copyright and Related Rights (defined below) upon the creator and 7 | subsequent owner(s) (each and all, an "owner") of an original work of 8 | authorship and/or a database (each, a "Work"). 9 | 10 | Certain owners wish to permanently relinquish those rights to a Work for the 11 | purpose of contributing to a commons of creative, cultural and scientific 12 | works ("Commons") that the public can reliably and without fear of later 13 | claims of infringement build upon, modify, incorporate in other works, reuse 14 | and redistribute as freely as possible in any form whatsoever and for any 15 | purposes, including without limitation commercial purposes. These owners may 16 | contribute to the Commons to promote the ideal of a free culture and the 17 | further production of creative, cultural and scientific works, or to gain 18 | reputation or greater distribution for their Work in part through the use and 19 | efforts of others. 20 | 21 | For these and/or other purposes and motivations, and without any expectation 22 | of additional consideration or compensation, the person associating CC0 with a 23 | Work (the "Affirmer"), to the extent that he or she is an owner of Copyright 24 | and Related Rights in the Work, voluntarily elects to apply CC0 to the Work 25 | and publicly distribute the Work under its terms, with knowledge of his or her 26 | Copyright and Related Rights in the Work and the meaning and intended legal 27 | effect of CC0 on those rights. 28 | 29 | 1. Copyright and Related Rights. A Work made available under CC0 may be 30 | protected by copyright and related or neighboring rights ("Copyright and 31 | Related Rights"). Copyright and Related Rights include, but are not limited 32 | to, the following: 33 | 34 | i. the right to reproduce, adapt, distribute, perform, display, communicate, 35 | and translate a Work; 36 | 37 | ii. moral rights retained by the original author(s) and/or performer(s); 38 | 39 | iii. publicity and privacy rights pertaining to a person's image or likeness 40 | depicted in a Work; 41 | 42 | iv. rights protecting against unfair competition in regards to a Work, 43 | subject to the limitations in paragraph 4(a), below; 44 | 45 | v. rights protecting the extraction, dissemination, use and reuse of data in 46 | a Work; 47 | 48 | vi. database rights (such as those arising under Directive 96/9/EC of the 49 | European Parliament and of the Council of 11 March 1996 on the legal 50 | protection of databases, and under any national implementation thereof, 51 | including any amended or successor version of such directive); and 52 | 53 | vii. other similar, equivalent or corresponding rights throughout the world 54 | based on applicable law or treaty, and any national implementations thereof. 55 | 56 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, 57 | applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and 58 | unconditionally waives, abandons, and surrenders all of Affirmer's Copyright 59 | and Related Rights and associated claims and causes of action, whether now 60 | known or unknown (including existing as well as future claims and causes of 61 | action), in the Work (i) in all territories worldwide, (ii) for the maximum 62 | duration provided by applicable law or treaty (including future time 63 | extensions), (iii) in any current or future medium and for any number of 64 | copies, and (iv) for any purpose whatsoever, including without limitation 65 | commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes 66 | the Waiver for the benefit of each member of the public at large and to the 67 | detriment of Affirmer's heirs and successors, fully intending that such Waiver 68 | shall not be subject to revocation, rescission, cancellation, termination, or 69 | any other legal or equitable action to disrupt the quiet enjoyment of the Work 70 | by the public as contemplated by Affirmer's express Statement of Purpose. 71 | 72 | 3. Public License Fallback. Should any part of the Waiver for any reason be 73 | judged legally invalid or ineffective under applicable law, then the Waiver 74 | shall be preserved to the maximum extent permitted taking into account 75 | Affirmer's express Statement of Purpose. In addition, to the extent the Waiver 76 | is so judged Affirmer hereby grants to each affected person a royalty-free, 77 | non transferable, non sublicensable, non exclusive, irrevocable and 78 | unconditional license to exercise Affirmer's Copyright and Related Rights in 79 | the Work (i) in all territories worldwide, (ii) for the maximum duration 80 | provided by applicable law or treaty (including future time extensions), (iii) 81 | in any current or future medium and for any number of copies, and (iv) for any 82 | purpose whatsoever, including without limitation commercial, advertising or 83 | promotional purposes (the "License"). The License shall be deemed effective as 84 | of the date CC0 was applied by Affirmer to the Work. Should any part of the 85 | License for any reason be judged legally invalid or ineffective under 86 | applicable law, such partial invalidity or ineffectiveness shall not 87 | invalidate the remainder of the License, and in such case Affirmer hereby 88 | affirms that he or she will not (i) exercise any of his or her remaining 89 | Copyright and Related Rights in the Work or (ii) assert any associated claims 90 | and causes of action with respect to the Work, in either case contrary to 91 | Affirmer's express Statement of Purpose. 92 | 93 | 4. Limitations and Disclaimers. 94 | 95 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 96 | surrendered, licensed or otherwise affected by this document. 97 | 98 | b. Affirmer offers the Work as-is and makes no representations or warranties 99 | of any kind concerning the Work, express, implied, statutory or otherwise, 100 | including without limitation warranties of title, merchantability, fitness 101 | for a particular purpose, non infringement, or the absence of latent or 102 | other defects, accuracy, or the present or absence of errors, whether or not 103 | discoverable, all to the greatest extent permissible under applicable law. 104 | 105 | c. Affirmer disclaims responsibility for clearing rights of other persons 106 | that may apply to the Work or any use thereof, including without limitation 107 | any person's Copyright and Related Rights in the Work. Further, Affirmer 108 | disclaims responsibility for obtaining any necessary consents, permissions 109 | or other rights required for any use of the Work. 110 | 111 | d. Affirmer understands and acknowledges that Creative Commons is not a 112 | party to this document and has no duty or obligation with respect to this 113 | CC0 or use of the Work. 114 | 115 | For more information, please see 116 | -------------------------------------------------------------------------------- /Samples/ListProceduralMacro.draco: -------------------------------------------------------------------------------- 1 | // Procedural macros are invoked by 2 | // foo!(arg1, arg2, ...) 3 | // or foo![arg1, arg2, ...] 4 | // or foo!{arg1, arg2, ...} 5 | // 6 | // The punctuation doesn't matter, it just needs to be pairwise. 7 | @procedural_macro(list) 8 | func make_list(args: []Ast): Result { 9 | val adds = List(); 10 | for (a in args) adds.Add(quote!{ result.Add(#a); }); 11 | 12 | return quote!{ 13 | // In a new block to be a valid expression 14 | { 15 | val result = System.Collections.Generic.List(); 16 | #(adds)... 17 | result 18 | } 19 | }; 20 | } 21 | 22 | // Example time! 23 | 24 | func main() { 25 | val l = list![1, 2, 3]; 26 | } 27 | 28 | // Expanded to: 29 | func main() { 30 | val l = { 31 | val result = System.Collections.Generic.List(); 32 | result.Add(1); 33 | result.Add(2); 34 | result.Add(3); 35 | result 36 | }; 37 | } -------------------------------------------------------------------------------- /Samples/MemoizeMacro.draco: -------------------------------------------------------------------------------- 1 | // Attribute macros are functions annotated with 'attribute_macro', passing in 2 | // the name of the created attribute as an identifier. The name of the function 3 | // doesn't matter, it's not related to how you actually invoke the macro. This 4 | // is useful when there is potential that you need to reuse your macro logic in 5 | // multiple metaprograms. Other than the attribute, this is a regular function. 6 | // All syntax-based metaprograms are functions that take in the AST + the 7 | // optional arguments, then return the modified result or an expansion error. 8 | // Attribute macros mean that their target is the language element they are 9 | // annotating and they replace that element with their result. This macro can be 10 | // used to annotate functions to make them memoize their results by storing 11 | // already computed results in a dictionary. The biggest difference between this 12 | // and a Roslyn SourceGenerator, is that here the original function is extended 13 | // with the new functionality, we don't need to externally augment the function 14 | // and then reference an externally implemented function in the original 15 | // implementation. 16 | 17 | // The exact APIs is debatable, the point is more towards illustrating how this 18 | // doesn't have to be a super hard thing to do. Writing syntactic abstractions 19 | // like this should be simple. 20 | 21 | // Here 'unwrap' is used to mean unwrap the Ok value of a Result, or 22 | // return the error on error, similarly to Rust's '?''. The exact syntax is 23 | // debatable and isn't really an important part of the snippet. 24 | 25 | // A builtin macro could be provided that would act as a template engine around 26 | // the language, this is the role of 'quote!' (just like the Rust crate). 27 | @attribute_macro(Memoize) 28 | func memoize_logic(target: Ast, args: []Ast): Result { 29 | // First, we assert that the target is a function. The type-checking 30 | // functions can conveniently return a Result 31 | val target = unwrap target.asFunc(); // Variable shadowing can be lovely! 32 | 33 | // We don't expect any arguments 34 | if (args.Length > 0) return MacroExpansionError("Memoization expects no arguments!"); 35 | 36 | // We will need this later 37 | val argNames = target.Signature.Parameters.Select(p => p.Name); 38 | 39 | // Here #(...) means substitution of an AST 40 | return quote!{ 41 | // Declare a dictionary outside 42 | val cache = System.Collections.Generic.Dictionary(); 43 | // Generate the new function 44 | #(target.Signature) // func name(...args): ReturnType 45 | { 46 | // Build a tuple of parameter names, check if cache has it 47 | if (!cache.TryGetValue((#(argNames),...), out val result) { 48 | // Not in the cache, invoke the original computation 49 | // We a bit cheat here by wrapping it up in a lambda and invoke it 50 | result = (func() { 51 | return #(target.Body); 52 | })(); 53 | // Store 54 | cache.Add((#(argNames),...), result); 55 | } 56 | return result; 57 | } 58 | }; 59 | } 60 | 61 | // Example: 62 | 63 | @Memoize 64 | func fib(n: int32): int32 = 65 | if (n < 2) 1 66 | else fib(n - 1) + fib(n - 2); 67 | 68 | // Expanded to: 69 | // val cache = System.Collections.Generic.Dictionary(); 70 | // func fib(n: int32): int32 { 71 | // if (!cache.TryGetValue((n), out val result)) { 72 | // result = (func() { 73 | // return if (n < 2) 1 74 | // else fib(n - 1) + fib(n - 2); 75 | // })(); 76 | // cache.Add((n), result); 77 | // } 78 | // return result; 79 | // } 80 | -------------------------------------------------------------------------------- /Samples/Quine.draco: -------------------------------------------------------------------------------- 1 | import System.Console; 2 | 3 | func main() { 4 | var s = #""" 5 | import System.Console; 6 | 7 | func main() { 8 | var s = {0}""" 9 | {1} 10 | """{0}; 11 | Write(s, '#', s); 12 | } 13 | """#; 14 | Write(s, '#', s); 15 | } 16 | -------------------------------------------------------------------------------- /Samples/RecursiveFibonacci.draco: -------------------------------------------------------------------------------- 1 | func fib(n: int32): int32 = 2 | if (n < 2) 1 3 | else fib(n - 1) + fib(n - 2); 4 | -------------------------------------------------------------------------------- /Samples/TruthMachine.draco: -------------------------------------------------------------------------------- 1 | import System.Console; 2 | 3 | func main() { 4 | val input = ReadLine(); 5 | if (input == "0") { 6 | Write("0"); 7 | } 8 | else { 9 | // We just assume 1 for anything non-0 10 | while (true) Write("1"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Specification/Comments.md: -------------------------------------------------------------------------------- 1 | # Comments in code 2 | This document specifies regular comments and documentation comments. 3 | ## What are comments 4 | Comments are non-functional text written in the code that does not alter the behavior of the language element. 5 | ## Single line comments 6 | Single line comments start with a `//`, if the `//` is not part of a string, and end with a newline. 7 | ## Documentation comments 8 | Documentation comments are a special type of comments, they add a description to a language element. In draco, documentation comments are written using markdown. 9 | Documentation comments are continuous lines that start with a `///`, and everything that comes after the `///` is interpreted as markdown. 10 | The documentation comment is attached to the first language element declared under it. If there is no such element, the documentation comment is ignored like a normal comment. 11 | Linking to other language elements can be done using the regular markdown syntax, either `[Text that should be displayed](Path to the language element)` or ``, the latter being a shorthand for `[language element](language element)` to avoid repetition. Alternatively, the empty link `[Path to the language element]()` will be interpreted as `[Path to the language element](Path to the language element)` as well to be able to avoid syntactical ambiguities with the angle brackets variant. Linking to symbols using HTML links is not specified yet. 12 | The documentation comment is in the same scope as the language element the comment is attached to. If the language element exposes any language elements the comment could refer to, these elements are implicitly accessible for the comment without any further qualifications. This is the case for function definitions and their parameters. For example, if we use function `Abs` with one parameter `num`, this parameter can be accessed like `[num](num)`. 13 | Every markdown heading corresponds to a section in the documentation comment. Documentation comments are expected to be either a simple paragraph without any sections, or a more complex structure containing sections. A general description of the language element (in C# this would be under the `summary` tag) is expected either under the `summary` section, or at the start of the documentation without being contained in any sections. There is a small set of standard sections, but the user can use any section they want. 14 | The standard sections are: 15 | - `summary` - general description of the language element, if this section is not present any text at the start of the documentation that is not contained in any section is considered to be summary 16 | - `returns` - value the language element returns (only makes sense for functions). 17 | - `parameters` - description of the parameters the language element accepts, either enumeration or subsections are expected here (only makes sense for functions). 18 | - `type parameters` - description of the type parameters the language element accepts, either enumeration or subsections are expected here (only makes sense for functions). 19 | - `exception` - exceptions the language element throws (only makes sense for functions). 20 | - `example` - code example how to use the language element. 21 | Example of documentation comment with sections: 22 | ```js 23 | /// Function, that adds 2 numbers. 24 | /// # parameters 25 | /// - num1: The first number to add. 26 | /// - num2: The second number to add. 27 | /// # returns 28 | /// The sum of and . 29 | func Add(num1: int32, num2: int32): int32 = num1 + num2; 30 | ``` 31 | The documentation generated from this comment could look something like: 32 |
33 | Function, that adds 2 numbers.
34 | parameters
35 | num1: The first number to add.
36 | num2: The second number to add.
37 | returns
38 | The sum of num1 and num2.
39 | 
40 | 41 | Example of documentation comment without sections: 42 | ```js 43 | /// Adds [num1]() and [num2](). 44 | func Add(num1: int32, num2: int32): int32 = num1 + num2; 45 | ``` 46 | The documentation generated from this comment could look something like: 47 |
48 | Adds num1 and num2.
49 | 
50 | -------------------------------------------------------------------------------- /Specification/ControlFlow.md: -------------------------------------------------------------------------------- 1 | # Basic control-flow/declarations 2 | 3 | This RFC lays down the fundamental control-flow and declaration structures for the language. It describes both the the syntax and intended semantics in a semi-formal way. The goal is to have even just some bare-bones elements that we can agree on and build the other RFCs and proposals on. 4 | 5 | ## Function definition 6 | 7 | This RFC introduces free-functions (functions that are not tied to types), member functions are not part of it. 8 | 9 | ### Syntax 10 | 11 | There will be two syntax variants, the "block syntax": 12 | 13 | ```swift 14 | func function_name(arg1: Type1, arg2: Type2): ReturnType { 15 | // Function body 16 | } 17 | ``` 18 | 19 | And the "inline-expression" syntax (roughly equivalent to arrow-bodied methods in C#): 20 | 21 | ```swift 22 | func function_name(arg1: Type1, arg2: Type2): ReturnType = expression; 23 | ``` 24 | 25 | The `: ReturnType` part is optional for both syntaxes. 26 | 27 | The parameter list can optionally contain a variadic argument list as the last parameter, which must have the `...parameterName: CollectionType` declaration syntax. 28 | ```swift 29 | func function_name(arg1: Type1, arg2: Type2, ...args: Array) 30 | ``` 31 | 32 | If a collection is passed as a variadic argument, the collection won't be passed as individual elements - like in C# -, but as a single element instead. If the given collection should be passed as the individual elements it contains, the spread operator must be used. 33 | ```swift 34 | func foo(...args: Array) {} 35 | 36 | func main(){ 37 | val arr = arrayOf(1, 2, 3); 38 | foo(arr); // The entire array is passed as a single element 39 | foo(...arr); // The elements of the array are passed individually 40 | } 41 | ``` 42 | 43 | ### Semantics 44 | 45 | Omitting the return type means that the return type is `unit` (equivalent to `void` in C#). 46 | 47 | ```swift 48 | func foo(): int32 { 49 | return 0; // OK 50 | } 51 | 52 | func foo() { 53 | return 0; // ERROR: integer returned, declared return type was unit 54 | } 55 | 56 | func foo(): int32 = 0; // OK 57 | 58 | func foo() = 0; // ERROR: integer returned, declared return type was unit 59 | ``` 60 | 61 | Defining a local function inside another function is allowed. 62 | 63 | ```swift 64 | func main(): int32 { 65 | func first(a: int32, b: int32): int32 = a; 66 | 67 | return first(1, 2); // OK 68 | } 69 | ``` 70 | 71 | Variadic arguments can be used as regular collections inside the function - as their type specified. While currently only variadic argument lists with type `Array` are supported, in the future this can be extended to more collections and even spans. Calling a function that contains a variadic argument list allows the user to append an arbitrary number of arguments that has the same type as the element type of the variadic argument collection. 72 | ```swift 73 | func foo(arg1: string, ...args: Array) 74 | { 75 | var result = 0; 76 | var i = 0; 77 | while(i < args.Length){ 78 | result += args[i]; 79 | i += 1; 80 | } 81 | return result; 82 | } 83 | 84 | func main(){ 85 | foo("Hi", 5); // OK 86 | foo("Hello", 5, 10, 15, 25); // OK 87 | foo("Hello"); // OK 88 | foo(5, 10, 15, 25); // ERROR: all regular arguments still must be provided 89 | } 90 | ``` 91 | 92 | ## Return 93 | 94 | Return is an expression that evaluates to the `unreachable` type. 95 | 96 | ### Syntax 97 | 98 | Return has two syntax variants, with an optional expression to return: 99 | 100 | ```swift 101 | return // unit return value 102 | 103 | return expr // some evaluated expression return value 104 | ``` 105 | 106 | ### Semantics 107 | 108 | Return terminates the currently executed function and returns the value specified (or unit, if none was specified). If a return expression is omitted from a block-syntax function, it is assumed to return `unit` at the very end. 109 | 110 | ### Usage in expressions 111 | 112 | The rationale behind `return` being an expression with the `unreachable` type is to be able to terminate computations early, while not tripping up type checking: 113 | 114 | ```cs 115 | // If return was a statement, there would be an error here, saying that the 'else' branch has type 'unit', but the other branch has type 'int32' 116 | var x = if (y % 2 == 0) y / 2 else return; 117 | ``` 118 | 119 | ## Goto 120 | 121 | Goto is an expression that evaluates to the `unreachable` type. Labels are statements (or rather, declarations). 122 | 123 | ### Syntax 124 | 125 | The syntax for a labels is: 126 | 127 | ```cs 128 | label_name: 129 | ``` 130 | 131 | The syntax of a goto expression is: 132 | 133 | ```cs 134 | goto label_name 135 | ``` 136 | 137 | ### Semantics 138 | 139 | Executing a `goto` means jumping the execution to the specified label. The jump can not jump into or out of the containing function (not even into contained or container functions). 140 | 141 | ### Usage in expressions 142 | 143 | The rationale behind it being an expression is similar to the return expression: 144 | 145 | ```cs 146 | retry: 147 | n = n / 2; 148 | x += 1; 149 | var mustBeZero = if (n == 0) x else goto retry; 150 | ``` 151 | 152 | ## Code blocks 153 | 154 | Code-blocks are expressions that are able to evaluate to some value. 155 | 156 | ### Syntax 157 | 158 | ```swift 159 | { 160 | statement1 161 | statement2 162 | // ... 163 | expr 164 | } 165 | ``` 166 | 167 | The expression at the end is optional. 168 | 169 | ### Semantics 170 | 171 | Code-blocks introduce a new lexical scope. Is there is an expression at the end of the code block, the block evaluates to that expression. If there is no expression at the end (it ends with a statement or the block is empty), it's implicitly assumed to evaluate to unit. The evaluation of block is done by executing all statements in it in sequence, finally evaluating the expression at the end as the result. 172 | 173 | ## If-else 174 | 175 | If-else is an expression, evaluating to some value. 176 | 177 | ### Syntax 178 | 179 | ```swift 180 | if (cond-expr) then-expr else els-expr 181 | 182 | if (cond-expr) then-expr 183 | ``` 184 | 185 | The else branch is optional. Note, that since blocks are expressions, something like 186 | 187 | ```swift 188 | if (cond-expr) { ... } else { ... } 189 | ``` 190 | 191 | is also valid, it requires no further specification. 192 | 193 | ### Semantics 194 | 195 | If the condition (`cond-expr`) evaluates to true, then `then-expr` is evaluated, else `els-expr` is evaluated. If the else branch is omitted, it is assumed to evaluate to unit. The two branches must evaluate to compatible types (see the [type-inference proposal](https://github.com/Draco-lang/Language-suggestions/issues/42) for what this will mean exactly). 196 | 197 | ## While loop 198 | 199 | The while-loop is an expression, always evaluating to unit. 200 | 201 | ### Syntax 202 | 203 | ```swift 204 | while (cond-expr) body-expr 205 | ``` 206 | 207 | Note, that since blocks are expressions, something like 208 | 209 | ```swift 210 | while (cond-expr) { ... } 211 | ``` 212 | 213 | is also valid, it requires no further specification. 214 | 215 | ### Semantics 216 | 217 | While the condition (`cond-expr`) evaluates to true, `body-expr` is evaluated. A while-loop always evaluates to unit, the body is simply "executed", not taken into account as the result. 218 | 219 | The loop defines specialized labels, `break` and `continue`. If we desugar the loop into ifs and gotos, it would be equivalent to the following: 220 | 221 | ```swift 222 | continue: 223 | if (not cond-expr) goto break; 224 | body-expr 225 | break: 226 | ``` 227 | 228 | For nested loops, the innermost label simply shadows the outer ones. This means, that our `break` and `continue` statements are just `goto`s with automatically generated labels and written as: 229 | 230 | ```swift 231 | while (...) { 232 | if (...) goto break; 233 | if (...) goto continue; 234 | } 235 | ``` 236 | 237 | ## Variables 238 | 239 | Variables can be both function-local and global and they are statements (or rather, declarations). 240 | 241 | ### Syntax 242 | 243 | They come in two flavors, with the keyword `var` and the keyword `val`: 244 | 245 | ```kt 246 | var var_name: VarType = VarValue; 247 | val var_name: VarType = VarValue; 248 | ``` 249 | 250 | Both the type specification (`: VarType`) and the value initializer (`= VarValue`) are optional elements. 251 | 252 | ### Semantics 253 | 254 | `var` introduces a mutable, and `val` introduces an immutable variable. Local variables are order-dependent (meaning they can't be referenced before use), and global variables are order-independent. By #13, arbitrary variable shadowing is allowed, meaning that function-local variables can overwrite each other. Example: 255 | 256 | ```kt 257 | var x = 1; 258 | val x = x.ToString(); // From now on, this x is available and is immutable 259 | 260 | { 261 | var x = 1; // Inside here, x refers to the integer 262 | } 263 | 264 | // Here again, the immutable string is accessible 265 | ``` 266 | 267 | The syntax gives 4 combinations: 268 | * Type specified, value specified: The specified values type has to be assignable to the specified type 269 | * Only type specified: Variable has the exact type specified 270 | * Only value specified: The type is inferred from the specified value and usage 271 | * Nothing specified: The type will be inferred from use 272 | 273 | On inference, see [the issue](https://github.com/Draco-lang/Language-suggestions/issues/42). 274 | -------------------------------------------------------------------------------- /Specification/EntryPoint.md: -------------------------------------------------------------------------------- 1 | # Application entry point 2 | 3 | This RFC describes the entry point of application-style projects. Note, that the specification leaves out some details that will be filled in by other RFCs. 4 | 5 | ## Possible signatures 6 | 7 | The entry point has to be a free-function named `main` (case-sensitive). The allowed parameterization/return types: 8 | * `func main(): unit` 9 | * `func main(): int32`, where the returned value is the exit code of the application 10 | * `func main(args: Array): unit`, where `args` are the CLI arguments passed to the application 11 | * `func main(args: Array): int32`, where the returned value is the exit code of the application and where `args` are the CLI arguments passed to the application 12 | 13 | The visibility of the `main` function doesn't matter. 14 | 15 | ## Placement in the project 16 | 17 | The entry point must be placed in a file `main.draco` in the root module of a package. 18 | 19 | The rationale behind this is to introduce a convention to easily navigate to the true entry point of the application. Many C# projects already used `Program.cs` for this as a soft convention. 20 | -------------------------------------------------------------------------------- /Specification/Generics.md: -------------------------------------------------------------------------------- 1 | # Generics 2 | 3 | _Note: Since we don't have user-defined types or traits yet, it makes little sense to define generics on user-defined types, or constraints on generic parameters. For now, this document will omit these._ 4 | 5 | ## Generic functions 6 | 7 | Generic functions are defined using the following syntax: 8 | 9 | ```swift 10 | func foo() { 11 | // ... 12 | } 13 | ``` 14 | 15 | Where `T1`, `T2`, ... are the generic parameters, and can be referenced as types within the function signature and body. Example: 16 | 17 | ```swift 18 | // ok -- -- ok 19 | // v v 20 | func foo(x: T1): T2 { 21 | var z: T3; // ok 22 | } 23 | 24 | var w: T4; // NOT OK, outside of signature and body 25 | ``` 26 | 27 | ### Calling generic functions 28 | 29 | Calling a generic function can be done with explicit instantiation: 30 | 31 | ```swift 32 | foo(); 33 | ``` 34 | 35 | Here, `TypeArg1`, `TypeArg2`, ... are type arguments. 36 | 37 | If the type arguments can be inferred from context, the type argument can be partially, or even completely elided. Partial elision can be done by using the discard `_` syntax in the place of the elided type argument. Complete elision can be done by skipping the type argument list entirely. 38 | 39 | Examples: 40 | 41 | ```cs 42 | func second(a: T, b: U): U = b; 43 | 44 | // Explicitly instantiated 45 | second(12, "hello"); 46 | 47 | // Partially elided, second argument is inferred 48 | second(12, "hello"); 49 | 50 | // Partially elided, first argument is inferred 51 | second<_, string>(12, "hello"); 52 | 53 | // Partially elided, both arguments are inferred 54 | second<_, _>(12, "hello"); 55 | 56 | // Fully elided 57 | second(12, "hello"); 58 | ``` 59 | 60 | ## Generic types 61 | 62 | Generic types can be instantiated using the syntax `GenericType`, where `TypeArg1`, `TypeArg1`, ... are type parameters. For example, `List` can be used with `int32` from `System.Collection.Generics` as `List`. 63 | 64 | ## Syntactical ambiguities 65 | 66 | This proposed syntax is quite familiar for C# developers, but it does mean a slight syntactical ambiguity is introduced. The following syntactical construct become ambiguous: 67 | 68 | ``` 69 | name1 < name2 > (expr) 70 | ``` 71 | 72 | Where `name1` and `name2` are (potentially qualified) identifiers, and `expr` is an arbitrary expression. 73 | 74 | The above could be interpreted in two different ways: 75 | * A chained comparison between `name1`, `name2` and `expr`, where `expr` is simply a parenthesized expression. 76 | * A generic function call of the function `name1` with the generic argument `name2` and call argument `expr`. 77 | 78 | ### Disambiguation 79 | 80 | To syntactically disambiguate the two cases, a set of rules is defined to determine if a `<` starts a generic argument list, or is simply a comparison operator: 81 | * If no matching `>` is found after the `<` within the expression, the sequence is deemed to be comparison 82 | * If anywhere after `<` and before the matching `>` a syntactic construct is found that is only valid in expression context, the sequence is deemed to be comparison 83 | * If anywhere after `<` and before the matching `>` a syntactic construct is found that is only valid in type context, the sequence is deemed to be a generic argument list (NOTE. that there is currently no such syntactic construct) 84 | * If anywhere after `<` and before `>` a comma can be found between two top-level constructs, the sequence is deemed to be a generic argument list 85 | * In any other case, the sequence stays ambiguous, and the follow-up token decides, how it is interpreted: 86 | * A `(`, `.`, `,`, or any other punctuation character that can not continue a comparison expression right after a comparison operator deems the sequence a generic argument list 87 | * In any other case, the sequence is considered to be a comparison 88 | 89 | If the user wants to disambiguate to the other option than what would be inferred from these rules, they can do so by parenthesizing: 90 | ```swift 91 | A(C) // Generic call 92 | (A)(C) // Comparison chain 93 | ``` 94 | -------------------------------------------------------------------------------- /Specification/Introduction.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | TODO. 4 | -------------------------------------------------------------------------------- /Specification/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS -------------------------------------------------------------------------------- /Specification/ModuleSystem.md: -------------------------------------------------------------------------------- 1 | # Module System 2 | This document defines how code is split to multiple files, how symbols are exported and imported and how reusable units of code are defined. 3 | 4 | ## Packages and modules 5 | A package is a reusable unit of code that consists of modules. In C# terminology, a package is equivalent to a project. Modules are building blocks of packages, they provide or hide pieces of functionality that make up the package. 6 | A module is a collection of source files within a folder. Every source file in the folder contributes to the module. Modules can also be defined in code using the syntax `module `. 7 | If a module is within another module (the folder is within another folder), it is considered a submodule of that parent module. Modules defined in code will become submodules of the module they were declared in. The only module that doesn't have a parent module (it is not a submodule) is the root module of the package. A root module is a collection of source files in the same folder as the projectfile. 8 | Contents of a module (submodules are also contents of a module) can be accessed with the syntax `.`. 9 | A package is defined by the projectfile `.dracoproj`, which is an MSBuild project file with a special extension. 10 | 11 | ## Visibility of language elements 12 | Language elements can have three types of visibility in Draco: `public`, `internal` and `private`. 13 | Any language element marked as `public` will be visible outside of the package, meaning that consumer code can reference it. Language elements marked as `internal` will be visible everywhere inside the defining package. Language elements not marked by any visibility modifier will be considered private and will be visible only inside the module they were declared in. The syntax for marking the visibility of language elements is ` `. A module will be visible outside of a package if it defines at least one public member. If the module doesn't define any public members, it will be only visible in the package it was declared in. 14 | 15 | Example of visibility modifiers: 16 | ```c# 17 | // Marking function as public 18 | public func abs(x: int32): int32 = if(x > 0) x else -x; 19 | 20 | // Member is not marked by any visibility, it is private 21 | val PI = 3.1415; 22 | 23 | // Marking function as internal 24 | internal func CircleCircumference(r: float64): float64 = 2 * PI * r; 25 | ``` 26 | 27 | ## Importing language elements 28 | Importing language elements into local scope can be done with the `import` statement. The import statement can have two forms. You can either import a module, such import statement has the syntax `import ;`. In this case, the import statement brings every member of that module into scope. You can also import a single module member while aliasing that member, then only that member is brought into the scope and can be used under its aliased name. The syntax for this import is `import = ;`. Import statements must always be on the top of a scope. If an import in a parent scope imports a language element with the same name as an import in a child scope, the element imported in the child scope will be used. Even without an import, language elements can be accessed anywhere in the code using their fully qualified name. 29 | 30 | Example of importing: 31 | ```js 32 | // Import every member of the module System 33 | // C# equivalent of this would be using System; 34 | import System; 35 | // Import every member of the module System.Console 36 | // C# equivalent of this would be using static System.Console; 37 | import System.Console; 38 | // Import single type, this is different than the above example, because this type is not static, which means it is not a module 39 | // C# equivalent of this would be using Stream = System.IO.Stream; 40 | import Stream = System.IO.Stream; 41 | // Import WriteLine from System.Console and alias it as println 42 | // C# doesn't allow importing free functions 43 | import println = System.Console.WriteLine; 44 | 45 | func main(){ 46 | // References System.Console.Writeline 47 | WriteLine(); 48 | // References System.Console.Writeline 49 | println(); 50 | 51 | // Child scope 52 | { 53 | // Foo.Console also defines WriteLine 54 | import Foo.Console; 55 | 56 | // References Foo.Console.WriteLine 57 | WriteLine(); 58 | // References System.Console.Writeline 59 | println(); 60 | } 61 | } 62 | ``` 63 | 64 | ## Example of module system inside a project 65 | Consider package Algorithms with this structure: 66 | ``` 67 | Algorithms 68 | |-Algorithms.dracoproj 69 | |-Graphs 70 | |-Dfs.draco 71 | |-Bfs.draco 72 | |-Trees 73 | |-BinaryTree.draco 74 | ``` 75 | There would be two modules: `Algorithms.Graphs`, where files `Dfs.draco` and `Bfs.draco` contribute to this module, and module `Algorithms.Graphs.Trees`, where the file `BinaryTree.draco` contributes to this module. 76 | --------------------------------------------------------------------------------