From f932cb5b4498d33df83e4c100a352006dd26bfea Mon Sep 17 00:00:00 2001 From: Midyan Hamdoun Date: Wed, 19 Jan 2022 14:22:48 +0200 Subject: [PATCH] Add all concepts and fix CI (#199) Add all concepts and fix CI --- concepts/abstract-types/.meta/config.json | 4 +- concepts/abstract-types/about.md | 34 ++++++++++- concepts/abstract-types/introduction.md | 23 ++++++- concepts/abstract-types/links.json | 4 ++ .../array-comprehension/.meta/config.json | 4 +- concepts/array-comprehension/about.md | 43 ++++++++++++- concepts/array-comprehension/introduction.md | 28 ++++++++- concepts/array-comprehension/links.json | 4 ++ concepts/arrays/.meta/config.json | 4 +- concepts/arrays/about.md | 47 ++++++++++++++- concepts/arrays/introduction.md | 28 ++++++++- concepts/arrays/links.json | 8 +++ concepts/basics/.meta/config.json | 4 +- concepts/basics/about.md | 39 +++++++++++- concepts/basics/introduction.md | 41 ++++++++++++- concepts/basics/links.json | 8 +++ concepts/bit-manipulation/.meta/config.json | 4 +- concepts/bit-manipulation/about.md | 15 ++++- concepts/bit-manipulation/introduction.md | 12 +++- concepts/bit-manipulation/links.json | 8 +++ concepts/booleans/.meta/config.json | 4 +- concepts/booleans/about.md | 2 + concepts/booleans/introduction.md | 2 + concepts/chars/.meta/config.json | 5 -- concepts/chars/about.md | 1 - concepts/chars/introduction.md | 1 - concepts/chars/links.json | 2 - concepts/classes/.meta/config.json | 4 +- concepts/classes/about.md | 51 +++++++++++++++- concepts/classes/introduction.md | 48 ++++++++++++++- concepts/classes/links.json | 8 +++ concepts/constructors/.meta/config.json | 4 +- concepts/constructors/about.md | 46 +++++++++++++- concepts/constructors/introduction.md | 32 +++++++++- concepts/constructors/links.json | 4 ++ concepts/datetimes/.meta/config.json | 4 +- concepts/datetimes/about.md | 8 ++- concepts/datetimes/introduction.md | 6 +- concepts/datetimes/links.json | 4 ++ concepts/do-while-loops/.meta/config.json | 6 +- concepts/do-while-loops/about.md | 14 ++++- concepts/do-while-loops/introduction.md | 12 +++- concepts/do-while-loops/links.json | 4 ++ concepts/enums/.meta/config.json | 6 +- concepts/enums/about.md | 13 +++- concepts/enums/introduction.md | 13 +++- concepts/enums/links.json | 4 ++ concepts/equality/.meta/config.json | 6 +- concepts/equality/about.md | 12 +++- concepts/equality/introduction.md | 12 +++- concepts/equality/links.json | 4 ++ concepts/exceptions/.meta/config.json | 6 +- concepts/exceptions/about.md | 32 +++++++++- concepts/exceptions/introduction.md | 30 +++++++++- concepts/exceptions/links.json | 8 +++ concepts/final/.meta/config.json | 6 +- concepts/final/about.md | 29 ++++++++- concepts/final/introduction.md | 15 ++++- concepts/final/links.json | 4 ++ concepts/flag-enums/.meta/config.json | 6 +- concepts/flag-enums/about.md | 25 +++++++- concepts/flag-enums/introduction.md | 25 +++++++- concepts/flag-enums/links.json | 4 ++ .../floating-point-numbers/.meta/config.json | 6 +- concepts/floating-point-numbers/about.md | 6 +- .../floating-point-numbers/introduction.md | 6 +- concepts/floating-point-numbers/links.json | 4 ++ concepts/for-loops/.meta/config.json | 6 +- concepts/for-loops/about.md | 46 +++++++++++++- concepts/for-loops/introduction.md | 26 +++++++- concepts/for-loops/links.json | 4 ++ concepts/foreach-loops/.meta/config.json | 5 -- concepts/foreach-loops/about.md | 1 - concepts/foreach-loops/introduction.md | 1 - concepts/foreach-loops/links.json | 2 - concepts/generic-types/.meta/config.json | 6 +- concepts/generic-types/about.md | 20 ++++++- concepts/generic-types/introduction.md | 20 ++++++- concepts/generic-types/links.json | 4 ++ concepts/if-statements/.meta/config.json | 6 +- concepts/if-statements/about.md | 28 ++++++++- concepts/if-statements/introduction.md | 28 ++++++++- concepts/if-statements/links.json | 4 ++ concepts/indexers/.meta/config.json | 5 -- concepts/indexers/about.md | 1 - concepts/indexers/introduction.md | 1 - concepts/indexers/links.json | 2 - concepts/inheritance/.meta/config.json | 6 +- concepts/inheritance/about.md | 59 +++++++++++++++++- concepts/inheritance/introduction.md | 59 +++++++++++++++++- concepts/inheritance/links.json | 4 ++ concepts/integral-numbers/.meta/config.json | 5 -- concepts/integral-numbers/about.md | 1 - concepts/integral-numbers/introduction.md | 1 - concepts/integral-numbers/links.json | 2 - concepts/interfaces/.meta/config.json | 6 +- concepts/interfaces/about.md | 24 +++++++- concepts/interfaces/introduction.md | 24 +++++++- concepts/interfaces/links.json | 4 ++ concepts/iterators/.meta/config.json | 6 +- concepts/iterators/about.md | 60 ++++++++++++++++++- concepts/iterators/introduction.md | 22 ++++++- concepts/iterators/links.json | 4 ++ concepts/lambda/.meta/config.json | 6 +- concepts/lambda/about.md | 30 +++++++++- concepts/lambda/introduction.md | 30 +++++++++- concepts/lambda/links.json | 4 ++ concepts/lists/.meta/config.json | 6 +- concepts/lists/about.md | 29 ++++++++- concepts/lists/introduction.md | 27 ++++++++- concepts/lists/links.json | 4 ++ concepts/maps/.meta/config.json | 6 +- concepts/maps/about.md | 36 ++++++++++- concepts/maps/introduction.md | 27 ++++++++- concepts/maps/links.json | 4 ++ concepts/nullability/.meta/config.json | 6 +- concepts/nullability/about.md | 19 +++++- concepts/nullability/introduction.md | 19 +++++- concepts/nullability/links.json | 4 ++ concepts/numbers/.meta/config.json | 6 +- concepts/numbers/about.md | 32 +++++++++- concepts/numbers/introduction.md | 14 ++++- concepts/numbers/links.json | 12 ++++ .../operator-overloading/.meta/config.json | 6 +- concepts/operator-overloading/about.md | 29 ++++++++- concepts/operator-overloading/introduction.md | 29 ++++++++- concepts/operator-overloading/links.json | 4 ++ concepts/option-type/.meta/config.json | 6 +- concepts/option-type/about.md | 42 ++++++++++++- concepts/option-type/introduction.md | 38 +++++++++++- concepts/option-type/links.json | 4 ++ concepts/optional-arguments/.meta/config.json | 6 +- concepts/optional-arguments/about.md | 29 ++++++++- concepts/optional-arguments/introduction.md | 29 ++++++++- concepts/optional-arguments/links.json | 8 +++ concepts/pattern-matching/.meta/config.json | 6 +- concepts/pattern-matching/about.md | 47 ++++++++++++++- concepts/pattern-matching/introduction.md | 47 ++++++++++++++- concepts/pattern-matching/links.json | 8 +++ concepts/properties/.meta/config.json | 6 +- concepts/properties/about.md | 40 ++++++++++++- concepts/properties/introduction.md | 40 ++++++++++++- concepts/properties/links.json | 8 +++ concepts/randomness/.meta/config.json | 6 +- concepts/randomness/about.md | 10 +++- concepts/randomness/introduction.md | 10 +++- concepts/randomness/links.json | 4 ++ concepts/reflection/.meta/config.json | 6 +- concepts/reflection/about.md | 27 ++++++++- concepts/reflection/introduction.md | 22 ++++++- concepts/reflection/links.json | 12 ++++ .../regular-expressions/.meta/config.json | 6 +- concepts/regular-expressions/about.md | 28 ++++++++- concepts/regular-expressions/introduction.md | 28 ++++++++- concepts/regular-expressions/links.json | 4 ++ concepts/rest-args/.meta/config.json | 6 +- concepts/rest-args/about.md | 14 ++++- concepts/rest-args/introduction.md | 14 ++++- concepts/rest-args/links.json | 4 ++ concepts/string-buffer/.meta/config.json | 6 +- concepts/string-buffer/about.md | 12 +++- concepts/string-buffer/introduction.md | 12 +++- concepts/string-buffer/links.json | 4 ++ .../string-interpolation/.meta/config.json | 10 +++- concepts/string-interpolation/about.md | 2 + concepts/string-interpolation/introduction.md | 8 +++ concepts/string-interpolation/links.json | 4 +- concepts/strings/.meta/config.json | 6 +- concepts/strings/links.json | 20 ++++--- concepts/switch-expressions/.meta/config.json | 6 +- concepts/switch-expressions/about.md | 23 ++++++- concepts/switch-expressions/introduction.md | 23 ++++++- concepts/switch-expressions/links.json | 4 ++ concepts/templates/.meta/config.json | 6 +- concepts/templates/about.md | 24 +++++++- concepts/templates/introduction.md | 24 +++++++- concepts/templates/links.json | 4 ++ concepts/ternary-operators/.meta/config.json | 6 +- concepts/ternary-operators/about.md | 11 +++- concepts/ternary-operators/introduction.md | 11 +++- concepts/ternary-operators/links.json | 4 ++ concepts/throw-expressions/.meta/config.json | 6 +- concepts/throw-expressions/about.md | 8 ++- concepts/throw-expressions/introduction.md | 8 ++- concepts/throw-expressions/links.json | 4 ++ concepts/time/.meta/config.json | 4 +- concepts/time/about.md | 8 ++- concepts/time/introduction.md | 6 +- concepts/time/links.json | 4 ++ concepts/typedefs/.meta/config.json | 6 +- concepts/typedefs/about.md | 17 +++++- concepts/typedefs/introduction.md | 17 +++++- concepts/typedefs/links.json | 4 ++ concepts/using-statements/.meta/config.json | 6 +- concepts/using-statements/about.md | 20 ++++++- concepts/using-statements/introduction.md | 20 ++++++- concepts/using-statements/links.json | 4 ++ concepts/while-loops/.meta/config.json | 6 +- concepts/while-loops/about.md | 15 ++++- concepts/while-loops/introduction.md | 15 ++++- concepts/while-loops/links.json | 4 ++ config.json | 7 +-- docs/ABOUT.md | 33 ++++++++++ docs/RESOURCES.md | 5 ++ 204 files changed, 2597 insertions(+), 233 deletions(-) delete mode 100644 concepts/chars/.meta/config.json delete mode 100644 concepts/chars/about.md delete mode 100644 concepts/chars/introduction.md delete mode 100644 concepts/chars/links.json delete mode 100644 concepts/foreach-loops/.meta/config.json delete mode 100644 concepts/foreach-loops/about.md delete mode 100644 concepts/foreach-loops/introduction.md delete mode 100644 concepts/foreach-loops/links.json delete mode 100644 concepts/indexers/.meta/config.json delete mode 100644 concepts/indexers/about.md delete mode 100644 concepts/indexers/introduction.md delete mode 100644 concepts/indexers/links.json delete mode 100644 concepts/integral-numbers/.meta/config.json delete mode 100644 concepts/integral-numbers/about.md delete mode 100644 concepts/integral-numbers/introduction.md delete mode 100644 concepts/integral-numbers/links.json create mode 100644 docs/ABOUT.md create mode 100644 docs/RESOURCES.md diff --git a/concepts/abstract-types/.meta/config.json b/concepts/abstract-types/.meta/config.json index 6f0adddd..dc99f1e1 100644 --- a/concepts/abstract-types/.meta/config.json +++ b/concepts/abstract-types/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for abstract types concept", - "authors": [], + "blurb": "Abstract types are types that change on run-time.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/abstract-types/about.md b/concepts/abstract-types/about.md index b5512bc8..37d17071 100644 --- a/concepts/abstract-types/about.md +++ b/concepts/abstract-types/about.md @@ -1 +1,33 @@ -TODO about: abstract-types \ No newline at end of file +# About + +In Haxe, an abstract type is a type which is a different type at run-time. It is a compile-time feature which defines types "over" concrete types in order to modify or augment their behavior: + +```haxe +abstract AbstractInt(Int) { + inline public function new(i:Int) { + this = i; + } +} +``` + +Here we are declaring the `AbstractInt` type using the `abstract` keyword. Its syntax is very similar that of `class`. And just like classes, abstarct types can have methods. They can also be instantiated and used just like classes: + +```haxe +class Main { + static public function main() { + var a = new AbstractInt(12); + trace(a); // 12 + } +} +``` + +As mentioned above, abstracts are a compile-time feature. Compiling the above example to JavaScript gives the following: + +```javascript +var a = 12; +console.log(a) +``` + +The abstract type `AbstractInt` completely disappears from the output. That's because the constructor of `Abstract` is [inlined][inline], which we'll see later. + +[inline]: https://haxe.org/manual/class-field-inline.html \ No newline at end of file diff --git a/concepts/abstract-types/introduction.md b/concepts/abstract-types/introduction.md index caee889f..be653796 100644 --- a/concepts/abstract-types/introduction.md +++ b/concepts/abstract-types/introduction.md @@ -1 +1,22 @@ -TODO introduction: abstract-types \ No newline at end of file +# Introduction + +In Haxe, an abstract type is a type which is a different type at run-time. It is a compile-time feature which defines types "over" concrete types in order to modify or augment their behavior: + +```haxe +abstract AbstractInt(Int) { + inline public function new(i:Int) { + this = i; + } +} +``` + +Here we are declaring the `AbstractInt` type using the `abstract` keyword. Its syntax is very similar that of `class`. And just like classes, abstarct types can have methods. They can also be instantiated and used just like classes: + +```haxe +class Main { + static public function main() { + var a = new AbstractInt(12); + trace(a); // 12 + } +} +``` \ No newline at end of file diff --git a/concepts/abstract-types/links.json b/concepts/abstract-types/links.json index 0d4f101c..b513343b 100644 --- a/concepts/abstract-types/links.json +++ b/concepts/abstract-types/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-abstract.html", + "description": "Haxe: Abstract types" + } ] diff --git a/concepts/array-comprehension/.meta/config.json b/concepts/array-comprehension/.meta/config.json index 988a57a8..79ac6c0f 100644 --- a/concepts/array-comprehension/.meta/config.json +++ b/concepts/array-comprehension/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for array comprehension concept", - "authors": [], + "blurb": "Array comprehension in Haxe is the combination of array decelartions and loops.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/array-comprehension/about.md b/concepts/array-comprehension/about.md index 32240af6..2e2dee8c 100644 --- a/concepts/array-comprehension/about.md +++ b/concepts/array-comprehension/about.md @@ -1 +1,42 @@ -TODO about: array-comprehension \ No newline at end of file +# About + +Array comprehension in Haxe combines array decelartion and loops to allow array initialization. The keywords `for` and `while` are used: + +```haxe +function main() { + var a = [for (i in 0...10) i]; + trace(a); // [0,1,2,3,4,5,6,7,8,9] + + var i = 0; + var b = [while(i < 10) i++]; + trace(b); // [0,1,2,3,4,5,6,7,8,9] +} +``` + +The compiler generates code required to fulfill the array comprehension. So for the above example, the `a` variable is done like this: + +```haxe +var a = []; +for (i in 0...10) a.push(i); +``` + +And for the `b` variable: + +```haxe +var i = 0; +var b = []; +while (i < 10) b.push(i++); +``` + +The loop expression can be anything, including conditions and nested loops, so the following works as expected: + +```haxe +function main() { + var a = [ + for (i in 0...10) + for (j in 2...4) + i + "." + j + ]; + trace(a); // [2,3,3,4,4,5,5,6,6,7] +} +``` \ No newline at end of file diff --git a/concepts/array-comprehension/introduction.md b/concepts/array-comprehension/introduction.md index 527581a6..7e4924b0 100644 --- a/concepts/array-comprehension/introduction.md +++ b/concepts/array-comprehension/introduction.md @@ -1 +1,27 @@ -TODO introduction: array-comprehension \ No newline at end of file +# Introduction + +Array comprehension in Haxe combines array decelartion and loops to allow array initialization. The keywords `for` and `while` are used: + +```haxe +function main() { + var a = [for (i in 0...10) i]; + trace(a); // [0,1,2,3,4,5,6,7,8,9] + + var i = 0; + var b = [while(i < 10) i++]; + trace(b); // [0,1,2,3,4,5,6,7,8,9] +} +``` + +The loop expression can be anything, including conditions and nested loops, so the following works as expected: + +```haxe +function main() { + var a = [ + for (i in 0...10) + for (j in 2...4) + i + "." + j + ]; + trace(a); // [2,3,3,4,4,5,5,6,6,7] +} +``` diff --git a/concepts/array-comprehension/links.json b/concepts/array-comprehension/links.json index 0d4f101c..063cff15 100644 --- a/concepts/array-comprehension/links.json +++ b/concepts/array-comprehension/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/lf-array-comprehension.html", + "description": "Haxe: Array comprehension" + } ] diff --git a/concepts/arrays/.meta/config.json b/concepts/arrays/.meta/config.json index 52428324..2616d421 100644 --- a/concepts/arrays/.meta/config.json +++ b/concepts/arrays/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for arrays concept", - "authors": [], + "blurb": "Arrays are a collection of multiple values of the same type.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/arrays/about.md b/concepts/arrays/about.md index eff64baf..c5ba8277 100644 --- a/concepts/arrays/about.md +++ b/concepts/arrays/about.md @@ -1 +1,46 @@ -TODO about: arrays \ No newline at end of file +# About + +In Haxe, an **array** is a collection of elements (usually) of the same type. There are three ways to create an array in Haxe; either by constructor or by a decleration syntax. In Haxe, the first element of an array has an index of zero: + +```haxe +var a = [1, 2, 3]; +trace(a); // [1,2,3] + +// Here the second element is called by index +trace(a[1]); // 2 + +// The actual first element's index is 0 +trace(a[0]); // 1 +``` + +To create an array using a constructor, you need to pass the type of the elements that are going to be included in the array: + +```haxe +var a:Array = [0, 1, 2, 3]; +a[1] = "Hello"; // Error: the array a takes integers only +``` + +Since array access in Haxe is unbounded, i.e. it is guaranteed to not throw an exception, this requires further discussion: + +- If a read access is made on a non-existing index, a target-dependent value is returned. +- If a write access is made with a positive index which is out of bounds, `null` (or the default value for basic types on static targets) is inserted at all positions between the last defined index and the newly written one. +- If a write access is made with a negative index, the result is unspecified. + +If we want an array to contain multiple types of elements, we add the `Dynamic` type to the type indicator: + +```haxe +var a:Array = [10, "Bob", true] +``` + +## Iteration + +Arrays can be iterated using a `for` loop: + +```haxe +var nums = [2, 3, 5]; +var sum = 0; +for (num in nums) { + sum += num; +} +trace(sum); // 10 +``` diff --git a/concepts/arrays/introduction.md b/concepts/arrays/introduction.md index eb607906..a0434f66 100644 --- a/concepts/arrays/introduction.md +++ b/concepts/arrays/introduction.md @@ -1 +1,27 @@ -TODO introduction: arrays \ No newline at end of file +# Introduction + +In Haxe, an **array** is a collection of elements (usually) of the same type. There are three ways to create an array in Haxe; either by constructor or by a decleration syntax. In Haxe, the first element of an array has an index of zero: + +```haxe +var a = [1, 2, 3]; +trace(a); // [1,2,3] + +// Here the second element is called by index +trace(a[1]); // 2 + +// The actual first element's index is 0 +trace(a[0]); // 1 +``` + +To create an array using a constructor, you need to pass the type of the elements that are going to be included in the array: + +```haxe +var a:Array = [0, 1, 2, 3]; +a[1] = "Hello"; // Error: the array a takes integers only +``` + +If we want an array to contain multiple types of elements, we add the `Dynamic` type to the type indicator: + +```haxe +var a:Array = [10, "Bob", true] +``` diff --git a/concepts/arrays/links.json b/concepts/arrays/links.json index 0d4f101c..4bdc9cfc 100644 --- a/concepts/arrays/links.json +++ b/concepts/arrays/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/std-Array.html", + "description": "Haxe: Arrays" + }, + { + "url": "https://api.haxe.org/Array.html", + "description": "Haxe: Array class" + } ] diff --git a/concepts/basics/.meta/config.json b/concepts/basics/.meta/config.json index bab475a4..c577f6e0 100644 --- a/concepts/basics/.meta/config.json +++ b/concepts/basics/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for basics concept", - "authors": [], + "blurb": "Learn about Haxe basics like functions and variables.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/basics/about.md b/concepts/basics/about.md index 17c4503d..8dd74679 100644 --- a/concepts/basics/about.md +++ b/concepts/basics/about.md @@ -1 +1,38 @@ -TODO about: basics \ No newline at end of file +# About + +Haxe is a strongly typed, but the typing system can be subverted where required. Assigning a value to a name is referred to as defining a variable. A variable can be defined either by explicitly specifying its type, or by letting the Haxe compiler infer the type using the [`var` keyword](var). Therefore, the following two variable definitions are equal: + +```haxe +var explicitVariable:Int = 10; // Explicitly typed +var implicitVariable = 10; // Implicit typed +``` + +Updating a variable can be done using the `=` operator: + +```haxe +var number = 0; // Initial value +number = 1; // Updated value +``` + +The compiler will throw an error when trying to assign a value that's type is different from the variable: + +```haxe +var number = 1; // Variable number is of integer type +number = "Hello" // Error trying to assign a string to an integer variable +``` + +In Haxe, code is usually written inside a _function_, also called [_method_](method). These functions can take parameters (arguments), and return values using the `return` keyword. Functions are invoked using `()` syntax. All functions must have a return type. + +```haxe +function add(x:Int, y:Int):Int { + return x + y; +} +``` + +Scope in Haxe is defined between the `{` and `}` characters. + +Haxe supports two types of comments. Single line are preceded by `//` and multiline comments are inserted between `/*` and `*/`. + +[var]: https://haxe.org/manual/expression-var.html +[oop]: https://en.wikipedia.org/wiki/Object-oriented_programming +[method]: https://haxe.org/manual/class-field-method.html diff --git a/concepts/basics/introduction.md b/concepts/basics/introduction.md index 6050c8fb..8e7c79b0 100644 --- a/concepts/basics/introduction.md +++ b/concepts/basics/introduction.md @@ -1 +1,40 @@ -TODO introduction: basics \ No newline at end of file +# Introduction + +Haxe is a strongly typed, but the typing system can be subverted where required. Assigning a value to a name is referred to as defining a variable. A variable can be defined either by explicitly specifying its type, or by letting the Haxe compiler infer the type. Therefore, the following two variable definitions are equal: + +```haxe +var explicitVariable:Int = 10; // Explicitly typed +var implicitVariable = 10; // Implicit typed +``` + +Updating a variable can be done using the `=` operator: + +```haxe +var number = 0; // Initial value +number = 1; // Updated value +``` + +The compiler will throw an error when trying to assign a value that's type is different from the variable: + +```haxe +var number = 1; // Variable number is of integer type +number = "Hello" // Error trying to assign a string to an integer variable +``` + +A function that's inside a class is called a _method_. Methods can have zero or more parameters. All parameters must be explicitly typed. Just like the parameters, the return type of a method can't be inferred and must be typed. Values are returned from methods using the `return` keyword: + +```haxe +function add(x:Int, y:Int):Int { + return x + y; +} +``` + +Invoking a method is done by specifying its class and method name and passing arguments: + +```haxe +var sum = add(1, 2) // sum = 3 +``` + +Scope in Haxe is defined between the `{` and `}` characters. + +Haxe supports two types of comments. Single line are preceded by `//` and multiline comments are inserted between `/*` and `*/`. diff --git a/concepts/basics/links.json b/concepts/basics/links.json index 0d4f101c..b217fadc 100644 --- a/concepts/basics/links.json +++ b/concepts/basics/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/expression-var.html", + "description": "var" + }, + { + "url": "https://haxe.org/manual/class-field-method.html", + "description": "method" + } ] diff --git a/concepts/bit-manipulation/.meta/config.json b/concepts/bit-manipulation/.meta/config.json index ed7f6d96..165a0dd8 100644 --- a/concepts/bit-manipulation/.meta/config.json +++ b/concepts/bit-manipulation/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for bit-manipulation concept", - "authors": [], + "blurb": "Haxe supports bitwise operators like AND, OR, XOR and shifting.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/bit-manipulation/about.md b/concepts/bit-manipulation/about.md index f51f0317..ea839301 100644 --- a/concepts/bit-manipulation/about.md +++ b/concepts/bit-manipulation/about.md @@ -1 +1,14 @@ -TODO about: bit-manipulation \ No newline at end of file +# About + +Haxe has some [unary][unary] and [binary][binary] operators to perform bitwise manipulation: + +- `&`: bitwise AND +- `|`: bitwise OR +- `^`: bitwise XOR +- `~`: bitwise NEGATION +- `<<`: shift left +- `>>`: shift right +- `>>>`: unsigned shift right + +[binary]: https://haxe.org/manual/expression-operators-binops.html#bitwise-operators +[unary]: https://haxe.org/manual/expression-operators-unops.html \ No newline at end of file diff --git a/concepts/bit-manipulation/introduction.md b/concepts/bit-manipulation/introduction.md index 6f8f4298..ddde835c 100644 --- a/concepts/bit-manipulation/introduction.md +++ b/concepts/bit-manipulation/introduction.md @@ -1 +1,11 @@ -TODO introduction: bit-manipulation \ No newline at end of file +# Introduction + +Haxe has some unary and binary operators to perform bitwise manipulation: + +- `&`: bitwise AND +- `|`: bitwise OR +- `^`: bitwise XOR +- `~`: bitwise NEGATION +- `<<`: shift left +- `>>`: shift right +- `>>>`: unsigned shift right \ No newline at end of file diff --git a/concepts/bit-manipulation/links.json b/concepts/bit-manipulation/links.json index 0d4f101c..be15f915 100644 --- a/concepts/bit-manipulation/links.json +++ b/concepts/bit-manipulation/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/expression-operators-unops.html", + "description": "Haxe: Unary operators" + }, + { + "url": "https://haxe.org/manual/expression-operators-binops.html", + "description": "Haxe: Binary operators" + } ] diff --git a/concepts/booleans/.meta/config.json b/concepts/booleans/.meta/config.json index 074b0e77..93ec525e 100644 --- a/concepts/booleans/.meta/config.json +++ b/concepts/booleans/.meta/config.json @@ -3,5 +3,7 @@ "authors": [ "mfoda" ], - "contributors": [] + "contributors": [ + "midyHamdoun" + ] } diff --git a/concepts/booleans/about.md b/concepts/booleans/about.md index a0fc4c2f..d97f427a 100644 --- a/concepts/booleans/about.md +++ b/concepts/booleans/about.md @@ -1,3 +1,5 @@ +# About + Booleans in Haxe are represented by the `Bool` type, whose values can be either `true` or `false`. Haxe supports three [boolean operators][operators]: `!` (unary NOT), `&&` (binary AND), and `||` (binary OR) diff --git a/concepts/booleans/introduction.md b/concepts/booleans/introduction.md index e06c346a..35d698f6 100644 --- a/concepts/booleans/introduction.md +++ b/concepts/booleans/introduction.md @@ -1,3 +1,5 @@ +# Introduction + Booleans in Haxe are represented by the `Bool` type, whose values can be either `true` or `false`. Haxe supports three boolean operators: `!` (NOT), `&&` (AND), and `||` (OR) diff --git a/concepts/chars/.meta/config.json b/concepts/chars/.meta/config.json deleted file mode 100644 index 38348b5b..00000000 --- a/concepts/chars/.meta/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "blurb": "TODO: add blurb for chars concept", - "authors": [], - "contributors": [] -} diff --git a/concepts/chars/about.md b/concepts/chars/about.md deleted file mode 100644 index 70546d40..00000000 --- a/concepts/chars/about.md +++ /dev/null @@ -1 +0,0 @@ -TODO about: chars \ No newline at end of file diff --git a/concepts/chars/introduction.md b/concepts/chars/introduction.md deleted file mode 100644 index b3e4e995..00000000 --- a/concepts/chars/introduction.md +++ /dev/null @@ -1 +0,0 @@ -TODO introduction: chars \ No newline at end of file diff --git a/concepts/chars/links.json b/concepts/chars/links.json deleted file mode 100644 index 0d4f101c..00000000 --- a/concepts/chars/links.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/concepts/classes/.meta/config.json b/concepts/classes/.meta/config.json index 70666b5f..a5deeec2 100644 --- a/concepts/classes/.meta/config.json +++ b/concepts/classes/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for classes concept", - "authors": [], + "blurb": "In Haxe, classes are the primary data structures.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/classes/about.md b/concepts/classes/about.md index 25961a2e..5b0ae1b2 100644 --- a/concepts/classes/about.md +++ b/concepts/classes/about.md @@ -1 +1,50 @@ -TODO about: classes \ No newline at end of file +# About + +In Haxe, a `class` is the primary data structure, which encapsulates data (fields) and behavior (methods). The fields and methods are also called members of a class. + +Access to the members can be restricted using [access modifiers][visibility], which are: + +- `public`: the member can be accessed from anywhere. +- `private`: the member can only be accessed by the same class. + +Classes can be thought of as templates for creating instances. To create an [instance][class-instance], simply use the `new` keyword: + +```haxe +class Car { + public function new() {} +} + +var myCar = new Car(); +var yourCar = new Car(); +``` + +To define a field, use an access modifier followed by the variable name and type: + +```haxe +class Car { + public var weight:Int; // Accessable by anyone + + private var color:String; // Accessable only within this class +} +``` + +You can also set an initial value when defining a field. If a field does not specify an initial value, it will take the value of `null`. You can access a field using the dot notation: + +```haxe +class Car { + public var weight:Int = 2500; // Weight will be set to 2500 + public var year:Int; // year will be null + + public function new() {} +} + +var newCar = new Car(); +newCar.weight; // 2500 +newCar.year; // null + +// Update value of field +newCar.year = 2020; +``` + +[visibility]: https://haxe.org/manual/class-field-visibility.html +[class-instance]: https://haxe.org/manual/types-class-instance.html \ No newline at end of file diff --git a/concepts/classes/introduction.md b/concepts/classes/introduction.md index aa5545bb..145ab4b3 100644 --- a/concepts/classes/introduction.md +++ b/concepts/classes/introduction.md @@ -1 +1,47 @@ -TODO introduction: classes \ No newline at end of file +# Introduction + +In Haxe, a `class` is the primary data structure, which encapsulates data (fields) and behavior (methods). The fields and methods are also called members of a class. + +Access to the members can be restricted using access modifiers, which are: + +- `public`: the member can be accessed from anywhere. +- `private`: the member can only be accessed by the same class. + +Classes can be thought of as templates for creating instances. To create an instance, simply use the `new` keyword: + +```haxe +class Car { + public function new() {} +} + +var myCar = new Car(); +var yourCar = new Car(); +``` + +To define a field, use an access modifier followed by the variable name and type: + +```haxe +class Car { + public var weight:Int; // Accessable by anyone + + private var color:String; // Accessable only within this class +} +``` + +You can also set an initial value when defining a field. If a field does not specify an initial value, it will take the value of `null`. You can access a field using the dot notation: + +```haxe +class Car { + public var weight:Int = 2500; // Weight will be set to 2500 + public var year:Int; // year will be null + + public function new() {} +} + +var newCar = new Car(); +newCar.weight; // 2500 +newCar.year; // null + +// Update value of field +newCar.year = 2020; +``` diff --git a/concepts/classes/links.json b/concepts/classes/links.json index 0d4f101c..a40e0235 100644 --- a/concepts/classes/links.json +++ b/concepts/classes/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/class-field-visibility.html", + "description": "Haxe: Visibility modifiers" + }, + { + "url": "https://haxe.org/manual/types-class-instance.html", + "description": "Haxe: Class instance" + } ] diff --git a/concepts/constructors/.meta/config.json b/concepts/constructors/.meta/config.json index 9f78a3fe..be172cc4 100644 --- a/concepts/constructors/.meta/config.json +++ b/concepts/constructors/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for constructors concept", - "authors": [], + "blurb": "Constructors are used to create a new instance of a class.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/constructors/about.md b/concepts/constructors/about.md index bb1a9ede..44121387 100644 --- a/concepts/constructors/about.md +++ b/concepts/constructors/about.md @@ -1 +1,45 @@ -TODO about: constructors \ No newline at end of file +# Introduction + +Creating an instance of a class is done by calling its [_constructor_][constructor] through the `new` operator. A constructor is a special method within a class whose goal is to initialize the class. In Haxe, the constructor method has the name of `new()`. + +```haxe +class Library { + private var books:Int; + + public function new() { + this.books = 10; // Initialize the books field + } +} + +var library = new Library(); // This calls the constructor +``` + +Just like normal methods, constructors can have parameters. These parameters are (usually) stored in private fields and accessed later. + +```haxe +class Building { + private var numberOfStories:Int; + private var totalHeight: Float; + + public function new(numberOfStories:Int, storyHeight:Float) { + this.numberOfStories = numberOfStories; + this.totalHeight = storyHeight * numberOfStories; + } +} + +var largeBuilding = new Building(55, 6.2); +``` + +You **cannot** create a new instance of a class if it doesn't have a constructor. Thus, using an empty constructor is the only way. + +```haxe +class Car { + public var weight:Int = 1000; + + public function new() {} +} + +var myCar = new Car(); +``` + +[constructor]: https://haxe.org/manual/types-class-constructor.html \ No newline at end of file diff --git a/concepts/constructors/introduction.md b/concepts/constructors/introduction.md index b9700825..0cd761ac 100644 --- a/concepts/constructors/introduction.md +++ b/concepts/constructors/introduction.md @@ -1 +1,31 @@ -TODO introduction: constructors \ No newline at end of file +# Introduction + +Creating an instance of a class is done by calling its _constructor_ through the `new` operator. A constructor is a special method within a class whose goal is to initialize the class. In Haxe, the constructor method has the name of `new()`. + +```haxe +class Library { + private var books:Int; + + public function new() { + this.books = 10; // Initialize the books field + } +} + +var library = new Library(); // This calls the constructor +``` + +Just like normal methods, constructors can have parameters. These parameters are (usually) stored in private fields and accessed later. + +```haxe +class Building { + private var numberOfStories:Int; + private var totalHeight: Float; + + public function new(numberOfStories:Int, storyHeight:Float) { + this.numberOfStories = numberOfStories; + this.totalHeight = storyHeight * numberOfStories; + } +} + +var largeBuilding = new Building(55, 6.2); +``` diff --git a/concepts/constructors/links.json b/concepts/constructors/links.json index 0d4f101c..6cb2b771 100644 --- a/concepts/constructors/links.json +++ b/concepts/constructors/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-class-constructor.html", + "description": "Haxe: Constructors" + } ] diff --git a/concepts/datetimes/.meta/config.json b/concepts/datetimes/.meta/config.json index b592b122..a831fe7d 100644 --- a/concepts/datetimes/.meta/config.json +++ b/concepts/datetimes/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for datetimes concept", - "authors": [], + "blurb": "Datetimes are objects that contain date and time.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/datetimes/about.md b/concepts/datetimes/about.md index 2dbc5de2..f259aab8 100644 --- a/concepts/datetimes/about.md +++ b/concepts/datetimes/about.md @@ -1 +1,7 @@ -TODO about: datetimes \ No newline at end of file +# About + +A [`Date`][date] object in Haxe is and object that contains both _date_ and _time_. Its value cannot be mutated once the constructor has been called. + +The default format of the `Date` object is: `DAY MONTH day year hours:minutes:seconds timezone`. For example `Sat Jan 1 2022 10:30:43 GMT+0000 (Greenwich Mean Time)`. + +[date]: https://api.haxe.org/Date.html diff --git a/concepts/datetimes/introduction.md b/concepts/datetimes/introduction.md index 2143025c..c32c90b1 100644 --- a/concepts/datetimes/introduction.md +++ b/concepts/datetimes/introduction.md @@ -1 +1,5 @@ -TODO introduction: datetimes \ No newline at end of file +# Introduction + +A `Date` object in Haxe is and object that contains both _date_ and _time_. Its value cannot be mutated once the constructor has been called. + +The default format of the `Date` object is: `DAY MONTH day year hours:minutes:seconds timezone`. For example `Sat Jan 1 2022 10:30:43 GMT+0000 (Greenwich Mean Time)`. diff --git a/concepts/datetimes/links.json b/concepts/datetimes/links.json index 0d4f101c..66c5eda1 100644 --- a/concepts/datetimes/links.json +++ b/concepts/datetimes/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/Date.html", + "description": "Haxe API: Date" + } ] diff --git a/concepts/do-while-loops/.meta/config.json b/concepts/do-while-loops/.meta/config.json index b5209254..7b0d5fe6 100644 --- a/concepts/do-while-loops/.meta/config.json +++ b/concepts/do-while-loops/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for do-while-loops concept", - "authors": [], + "blurb": "A do-while loops is similar to a while loop but code in the loop executed at least once.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/do-while-loops/about.md b/concepts/do-while-loops/about.md index d130a551..81ead852 100644 --- a/concepts/do-while-loops/about.md +++ b/concepts/do-while-loops/about.md @@ -1 +1,13 @@ -TODO about: do-while-loops \ No newline at end of file +# About + +A `do-while` loop is an alternative for a `while` loop, with the only difference being that a `do-while` is run at least once: + +```haxe +var i = 0; + +do { + trace("Hello"); +} while (i < 10); +``` + +The cases to use a `do-while` loop are very rare, so the normal `while` is used instead. diff --git a/concepts/do-while-loops/introduction.md b/concepts/do-while-loops/introduction.md index 6356a2d3..7957b23f 100644 --- a/concepts/do-while-loops/introduction.md +++ b/concepts/do-while-loops/introduction.md @@ -1 +1,11 @@ -TODO introduction: do-while-loops \ No newline at end of file +# Introduction + +A `do-while` loop is an alternative for a `while` loop, with the only difference being that a `do-while` is run at least once: + +```haxe +var i = 0; + +do { + trace("Hello"); +} while (i < 10); +``` diff --git a/concepts/do-while-loops/links.json b/concepts/do-while-loops/links.json index 0d4f101c..faf96bb9 100644 --- a/concepts/do-while-loops/links.json +++ b/concepts/do-while-loops/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-do-while.html", + "description": "Haxe: Do-While" + } ] diff --git a/concepts/enums/.meta/config.json b/concepts/enums/.meta/config.json index 93a91c4e..2688e4b0 100644 --- a/concepts/enums/.meta/config.json +++ b/concepts/enums/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for enums concept", - "authors": [], + "blurb": "Enum types are very useful for describing data structures.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/enums/about.md b/concepts/enums/about.md index aed80917..bfab82cf 100644 --- a/concepts/enums/about.md +++ b/concepts/enums/about.md @@ -1 +1,12 @@ -TODO about: enums \ No newline at end of file +# About + +Haxe provides enum types, which are used to describe a data structure: + +```haxe +enum Color { + Red; + Green; + Blue; + Rgb(r:Int, g:Int, b:Int); +} +``` diff --git a/concepts/enums/introduction.md b/concepts/enums/introduction.md index 51cb0265..7da648f4 100644 --- a/concepts/enums/introduction.md +++ b/concepts/enums/introduction.md @@ -1 +1,12 @@ -TODO introduction: enums \ No newline at end of file +# Introduction + +Haxe provides enum types, which are used to describe a data structure: + +```haxe +enum Color { + Red; + Green; + Blue; + Rgb(r:Int, g:Int, b:Int); +} +``` diff --git a/concepts/enums/links.json b/concepts/enums/links.json index 0d4f101c..fd826f7d 100644 --- a/concepts/enums/links.json +++ b/concepts/enums/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-enum-instance.html", + "description": "Haxe: Enums" + } ] diff --git a/concepts/equality/.meta/config.json b/concepts/equality/.meta/config.json index 6ba71a2c..0c3f09b9 100644 --- a/concepts/equality/.meta/config.json +++ b/concepts/equality/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for equality concept", - "authors": [], + "blurb": "The equality operator checks if two variables have the same value.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/equality/about.md b/concepts/equality/about.md index 2cbeed55..1cf86037 100644 --- a/concepts/equality/about.md +++ b/concepts/equality/about.md @@ -1 +1,11 @@ -TODO about: equality \ No newline at end of file +# About + +To test if two variables of simple types (strings, integers etc.), we use the equality operators `==` and `!=`: + +```haxe +var a = 5; +var b = 5; + +a == b; // true +a != b; // false +``` diff --git a/concepts/equality/introduction.md b/concepts/equality/introduction.md index 33e354e4..6baa7783 100644 --- a/concepts/equality/introduction.md +++ b/concepts/equality/introduction.md @@ -1 +1,11 @@ -TODO introduction: equality \ No newline at end of file +# Introduction + +To test if two variables of simple types (strings, integers etc.), we use the equality operators `==` and `!=`: + +```haxe +var a = 5; +var b = 5; + +a == b; // true +a != b; // false +``` diff --git a/concepts/equality/links.json b/concepts/equality/links.json index 0d4f101c..e6dce4ea 100644 --- a/concepts/equality/links.json +++ b/concepts/equality/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-operators-binops.html#numeric-comparison-operators", + "description": "Haxe: Comparison operators" + } ] diff --git a/concepts/exceptions/.meta/config.json b/concepts/exceptions/.meta/config.json index a0e5a363..41af3af6 100644 --- a/concepts/exceptions/.meta/config.json +++ b/concepts/exceptions/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for exceptions concept", - "authors": [], + "blurb": "Exceptions should be thrown when an error that needs special handling occurs.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/exceptions/about.md b/concepts/exceptions/about.md index 2044d2a3..56a2a178 100644 --- a/concepts/exceptions/about.md +++ b/concepts/exceptions/about.md @@ -1 +1,31 @@ -TODO about: exceptions \ No newline at end of file +# About + +In Haxe, exceptions are a safe way to handle errors that occur when running the code. All exceptions should contain a message describing the error. We can _throw_ exceptions using the `throw` keyword: + +```haxe +public function main(num:Int) { + if (num < 10) { + throw "Argument num cannot be greater than 10"; + } + // ... +} +``` + +When an exception is thrown, the code looks for a piece that's assigned to handle the error. If it doesn't find one, it will display the error message while also stopping the execution of the program. + +To handle excpetions in Haxe, we use the `try-catch` block. This block statement consists of one `try` block and one or more `catch` blocks. The `try` block _tries_ to execute a piece of code, while the `catch` block waits in case there's an exception thrown to _catch_ it, so that the execution is not stopped. When the `catch` blocks catches an excpetion, it also executes everything within the block: + +```haxe +try { + if (num < 10) { + throw "Argument num cannot be greater than 10"; + } +} catch (e) { + // All exceptions will be caught here + trace(e.message); // Argument num cannot be greater than 10 +} +``` + +The `catch` block argument's type should be omitted. + +It is important to note that exceptions should be used in cases where something exceptional happens, an error that needs special handling. It should not be used for control-flow of a program, as that is considered bad design, which often leads to bad performance and maintainability. diff --git a/concepts/exceptions/introduction.md b/concepts/exceptions/introduction.md index 0712238e..b7399aca 100644 --- a/concepts/exceptions/introduction.md +++ b/concepts/exceptions/introduction.md @@ -1 +1,29 @@ -TODO introduction: exceptions \ No newline at end of file +# Introduction + +In Haxe, exceptions are a safe way to handle errors that occur when running the code. All exceptions should contain a message describing the error. We can _throw_ exceptions using the `throw` keyword: + +```haxe +public function main(num:Int) { + if (num < 10) { + throw "Argument num cannot be greater than 10"; + } + // ... +} +``` + +When an exception is thrown, the code looks for a piece that's assigned to handle the error. If it doesn't find one, it will display the error message while also stopping the execution of the program. + +To handle excpetions in Haxe, we use the `try-catch` block. This block statement consists of one `try` block and one or more `catch` blocks. The `try` block _tries_ to execute a piece of code, while the `catch` block waits in case there's an exception thrown to _catch_ it, so that the execution is not stopped. When the `catch` blocks catches an excpetion, it also executes everything within the block: + +```haxe +try { + if (num < 10) { + throw "Argument num cannot be greater than 10"; + } +} catch (e) { + // All exceptions will be caught here + trace(e.message); // Argument num cannot be greater than 10 +} +``` + +The `catch` block argument's type should be omitted. diff --git a/concepts/exceptions/links.json b/concepts/exceptions/links.json index 0d4f101c..3bca3677 100644 --- a/concepts/exceptions/links.json +++ b/concepts/exceptions/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/expression-try-catch.html", + "description": "Haxe: Try/Catch" + }, + { + "url": "https://haxe.org/manual/expression-throw.html", + "description": "Haxe: Throw" + } ] diff --git a/concepts/final/.meta/config.json b/concepts/final/.meta/config.json index ac38d1ce..88b1582e 100644 --- a/concepts/final/.meta/config.json +++ b/concepts/final/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for final concept", - "authors": [], + "blurb": "Final variables cannot change their values.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/final/about.md b/concepts/final/about.md index 0ac2f8db..50bfc80e 100644 --- a/concepts/final/about.md +++ b/concepts/final/about.md @@ -1 +1,28 @@ -TODO about: final \ No newline at end of file +# About + +Variables that are declared with the keyword `final` instead of `var` can only be assigned a value once. + +```haxe +final a = "hello"; +var b = "world"; +trace(a, b); // hello, world +b = "haxe"; +trace(a, b); // hello, haxe + +// The following line would cause a compilation error: +// a = "bye"; +``` + +It is important to note that `final` may not have the intended effect with types that are not immutable, such as arrays or objects: + +```haxe +final a = [0, 1, 2]; +trace(a); // [0,1,2] + +// this would cause a compilation error: +// a = [0, 1, 2, 3]; + +// but the following line works: +a.push(3); +trace(a); // [0,1,2,3] +``` diff --git a/concepts/final/introduction.md b/concepts/final/introduction.md index a20062a7..7c468f73 100644 --- a/concepts/final/introduction.md +++ b/concepts/final/introduction.md @@ -1 +1,14 @@ -TODO introduction: final \ No newline at end of file +# Introduction + +Variables that are declared with the keyword `final` instead of `var` can only be assigned a value once. + +```haxe +final a = "hello"; +var b = "world"; +trace(a, b); // hello, world +b = "haxe"; +trace(a, b); // hello, haxe + +// The following line would cause a compilation error: +// a = "bye"; +``` diff --git a/concepts/final/links.json b/concepts/final/links.json index 0d4f101c..ab89e512 100644 --- a/concepts/final/links.json +++ b/concepts/final/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-var.html#since-haxe-4.0.0", + "description": "Haxe: Final" + } ] diff --git a/concepts/flag-enums/.meta/config.json b/concepts/flag-enums/.meta/config.json index 133e5c72..853903ba 100644 --- a/concepts/flag-enums/.meta/config.json +++ b/concepts/flag-enums/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for flag-enums concept", - "authors": [], + "blurb": "To allow a single enum instance to represent multiple values (usually referred to as flags), one can use EnumFlags.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/flag-enums/about.md b/concepts/flag-enums/about.md index d47e61c4..2754979d 100644 --- a/concepts/flag-enums/about.md +++ b/concepts/flag-enums/about.md @@ -1 +1,24 @@ -TODO about: flag-enums \ No newline at end of file +# About + +Normally, in Haxe, an `enum` member can only refer to exactly one of the constants defined in the `enum`. However, sometimes we need a member to refer to two or constants. To do so, we use the [`haxe.EnumFlags`][enumflags] package: + +```haxe +import haxe.EnumFlags; + +enum Phone { + Call; + Text; +} + +public function main() { + var flags = new EnumFlags(); + flags.set(Call); + flags.set(Text); + + if (flags.has(Call) && flags.has(Test)) { + trace("Phone has both Call and Text active"); + } +} +``` + +[enumflags]: https://api.haxe.org/haxe/EnumFlags.html diff --git a/concepts/flag-enums/introduction.md b/concepts/flag-enums/introduction.md index 351e73c5..49025805 100644 --- a/concepts/flag-enums/introduction.md +++ b/concepts/flag-enums/introduction.md @@ -1 +1,24 @@ -TODO introduction: flag-enums \ No newline at end of file +# Introduction + +Normally, in Haxe, an `enum` member can only refer to exactly one of the constants defined in the `enum`. However, sometimes we need a member to refer to two or constants. To do so, we use the [`haxe.EnumFlags`][enumflags] package: + +```haxe +import haxe.EnumFlags; + +enum Phone { + Call; + Text; +} + +public function main() { + var flags = new EnumFlags(); + flags.set(Call); + flags.set(Text); + + if (flags.has(Call) && flags.has(Test)) { + trace("Phone has both Call and Text active"); + } +} +``` + +[enumflags]: https://api.haxe.org/haxe/EnumFlags.html diff --git a/concepts/flag-enums/links.json b/concepts/flag-enums/links.json index 0d4f101c..3991b5d1 100644 --- a/concepts/flag-enums/links.json +++ b/concepts/flag-enums/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/haxe/EnumFlags.html", + "description": "Haxe API: EnumFlags" + } ] diff --git a/concepts/floating-point-numbers/.meta/config.json b/concepts/floating-point-numbers/.meta/config.json index c138794a..6a4d7ce6 100644 --- a/concepts/floating-point-numbers/.meta/config.json +++ b/concepts/floating-point-numbers/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for floating-point-numbers concept", - "authors": [], + "blurb": "A floating point number is a number with zero or more digits behind the decimal seperator.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/floating-point-numbers/about.md b/concepts/floating-point-numbers/about.md index 499b30da..895dcce9 100644 --- a/concepts/floating-point-numbers/about.md +++ b/concepts/floating-point-numbers/about.md @@ -1 +1,5 @@ -TODO about: floating-point-numbers \ No newline at end of file +# About + +A floating point number is a number that has zero or more digits behind the decimal seperator. Examples are `1.0`, `-4.68`, `3.14`, `-213.21309`. + +A float variable stores up to 8 bytes (~15-17 digits precision). diff --git a/concepts/floating-point-numbers/introduction.md b/concepts/floating-point-numbers/introduction.md index aaf9af0c..fc7a8393 100644 --- a/concepts/floating-point-numbers/introduction.md +++ b/concepts/floating-point-numbers/introduction.md @@ -1 +1,5 @@ -TODO introduction: floating-point-numbers \ No newline at end of file +# Introduction + +A floating point number is a number that has zero or more digits behind the decimal seperator. Examples are `1.0`, `-4.68`, `3.14`, `-213.21309`. + +A float variable stores up to 8 bytes (~15-17 digits precision). diff --git a/concepts/floating-point-numbers/links.json b/concepts/floating-point-numbers/links.json index 0d4f101c..92e3d893 100644 --- a/concepts/floating-point-numbers/links.json +++ b/concepts/floating-point-numbers/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-numeric-types.html", + "description": "Haxe: Numeric types" + } ] diff --git a/concepts/for-loops/.meta/config.json b/concepts/for-loops/.meta/config.json index 322ef82a..02d24cad 100644 --- a/concepts/for-loops/.meta/config.json +++ b/concepts/for-loops/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for for-loops concept", - "authors": [], + "blurb": "For-loops allow for iteration over an array", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/for-loops/about.md b/concepts/for-loops/about.md index 8577f495..11c0b8f5 100644 --- a/concepts/for-loops/about.md +++ b/concepts/for-loops/about.md @@ -1 +1,45 @@ -TODO about: for-loops \ No newline at end of file +# About + +## Array iteration + +A `for` loop allow to iterate over an array and repeat the code for each element: + +```haxe +var fruitList = ["apple", "banana", "pear"]; + +for (fruit in fruitList) { + trace(fruit); +} + +// apple +// banana +// pear +``` + +In the above example, `fruit` is the variable that holds the value of an individual element of the array `fruitList`. The compiler ensures that `fruitList` can be iterated over, else it will stop the execution. + +## Range iteration + +You can iterate over numbers by using the range operator. The operator takes two `Int` operands and is written as `min...max`. The `min` is inclusive and the `max` is exclusive (`min` <= i AND `max` > i) + +```haxe +for (i in 0...10) { + trace(i); // from 0 to 9 +} +``` + +## Key-value iteration + +It is possible to iterate over collections of key-value pairs. The only difference in syntax is that instead of a single variable, a key variable identifier is used, followed by `=>`, followed by the value variable identifier: + +```haxe +var map = [1 => 101, 2 => 202, 3 => 303]; + +for (k => v in map) { + trace(key, value); +} + +// 1, 101 +// 2, 202 +// 3, 303 +``` diff --git a/concepts/for-loops/introduction.md b/concepts/for-loops/introduction.md index b8ccbcf5..a37bd7d2 100644 --- a/concepts/for-loops/introduction.md +++ b/concepts/for-loops/introduction.md @@ -1 +1,25 @@ -TODO introduction: for-loops \ No newline at end of file +# Introduction + +A `for` loop allow to iterate over an array and repeat the code for each element: + +```haxe +var fruitList = ["apple", "banana", "pear"]; + +for (fruit in fruitList) { + trace(fruit); +} + +// apple +// banana +// pear +``` + +In the above example, `fruit` is the variable that holds the value of an individual element of the array `fruitList`. The compiler ensures that `fruitList` can be iterated over, else it will stop the execution. + +You can iterate over numbers by using the range operator. The operator takes two `Int` operands and is written as `min...max`: + +```haxe +for (i in 0...10) { + trace(i); // from 0 to 9 +} +``` diff --git a/concepts/for-loops/links.json b/concepts/for-loops/links.json index 0d4f101c..0cff3967 100644 --- a/concepts/for-loops/links.json +++ b/concepts/for-loops/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-for.html", + "description": "Haxe: For loop" + } ] diff --git a/concepts/foreach-loops/.meta/config.json b/concepts/foreach-loops/.meta/config.json deleted file mode 100644 index 2dd40215..00000000 --- a/concepts/foreach-loops/.meta/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "blurb": "TODO: add blurb for foreach-loops concept", - "authors": [], - "contributors": [] -} diff --git a/concepts/foreach-loops/about.md b/concepts/foreach-loops/about.md deleted file mode 100644 index 32e67088..00000000 --- a/concepts/foreach-loops/about.md +++ /dev/null @@ -1 +0,0 @@ -TODO about: foreach-loops \ No newline at end of file diff --git a/concepts/foreach-loops/introduction.md b/concepts/foreach-loops/introduction.md deleted file mode 100644 index 57a9725b..00000000 --- a/concepts/foreach-loops/introduction.md +++ /dev/null @@ -1 +0,0 @@ -TODO introduction: foreach-loops \ No newline at end of file diff --git a/concepts/foreach-loops/links.json b/concepts/foreach-loops/links.json deleted file mode 100644 index 0d4f101c..00000000 --- a/concepts/foreach-loops/links.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/concepts/generic-types/.meta/config.json b/concepts/generic-types/.meta/config.json index 473b73d2..9226cb42 100644 --- a/concepts/generic-types/.meta/config.json +++ b/concepts/generic-types/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for generic-types concept", - "authors": [], + "blurb": "Generic-types allow for classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/generic-types/about.md b/concepts/generic-types/about.md index 111025f0..958fbc8d 100644 --- a/concepts/generic-types/about.md +++ b/concepts/generic-types/about.md @@ -1 +1,19 @@ -TODO about: generic-types \ No newline at end of file +# About + +A collection definition typically includes a place holder in angle brackets, often T by convention. Such a collection is referred to as a generic type. This allows the collection user to specify what type of items to store in the collection. In the above example code we are instantiating a list of strings. + +A class or a function is made **generic** is by using the `@:generic` attribute. This causes the compiler to identify the class or function as generic: + +```haxe +@:generic +class MyValue { + public var value:T; + + public function new(value:T) { + this.value = value; + } +} + +var a = MyValue("Hello"); +trace(a.value); // Hello +``` diff --git a/concepts/generic-types/introduction.md b/concepts/generic-types/introduction.md index 85b3b677..6fcc1537 100644 --- a/concepts/generic-types/introduction.md +++ b/concepts/generic-types/introduction.md @@ -1 +1,19 @@ -TODO introduction: generic-types \ No newline at end of file +# Introduction + +A collection definition typically includes a place holder in angle brackets, often T by convention. Such a collection is referred to as a generic type. This allows the collection user to specify what type of items to store in the collection. In the above example code we are instantiating a list of strings. + +A class or a function is made **generic** is by using the `@:generic` attribute. This causes the compiler to identify the class or function as generic: + +```haxe +@:generic +class MyValue { + public var value:T; + + public function new(value:T) { + this.value = value; + } +} + +var a = MyValue("Hello"); +trace(a.value); // Hello +``` diff --git a/concepts/generic-types/links.json b/concepts/generic-types/links.json index 0d4f101c..867b4cd9 100644 --- a/concepts/generic-types/links.json +++ b/concepts/generic-types/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/type-system-generic.html", + "description": "Haxe: Generic type" + } ] diff --git a/concepts/if-statements/.meta/config.json b/concepts/if-statements/.meta/config.json index 2c31973e..a19f0fbc 100644 --- a/concepts/if-statements/.meta/config.json +++ b/concepts/if-statements/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for if-statements concept", - "authors": [], + "blurb": "An if statement is used to conditionally execute code.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/if-statements/about.md b/concepts/if-statements/about.md index 07f9f5c7..caaf066d 100644 --- a/concepts/if-statements/about.md +++ b/concepts/if-statements/about.md @@ -1 +1,27 @@ -TODO about: if-statements \ No newline at end of file +# About + +Conditional expressions are used to execute code based on **if** a condition is **true** or **false**. These expressions are written as: + +```haxe +if (condition) { + expressions +}; +``` + +The condition's output is of `Bool` type, so when the output is `true` the expressions are executed. + +Sometimes, when the condition is actually `false`, we want another bit of code to be executed. That's where the `else` expression comes in. `else` executes expressions when the initial condition is `false`. But what if we want to check the condition for multiple possibilities? We then use `else if (condition)`. Here is a full example: + +```haxe +var a = 10; + +if (a == 2) { + trace("a is 2"); +} else if (a == 5) { + trace("a is 5"); +} else { + trace("a is 10"); +} + +// a is 10 +``` diff --git a/concepts/if-statements/introduction.md b/concepts/if-statements/introduction.md index 6654cf2b..06c16f28 100644 --- a/concepts/if-statements/introduction.md +++ b/concepts/if-statements/introduction.md @@ -1 +1,27 @@ -TODO introduction: if-statements \ No newline at end of file +# Introduction + +Conditional expressions are used to execute code based on **if** a condition is **true** or **false**. These expressions are written as: + +```haxe +if (condition) { + expressions +}; +``` + +The condition's output is of `Bool` type, so when the output is `true` the expressions are executed. + +Sometimes, when the condition is actually `false`, we want another bit of code to be executed. That's where the `else` expression comes in. `else` executes expressions when the initial condition is `false`. But what if we want to check the condition for multiple possibilities? We then use `else if (condition)`. Here is a full example: + +```haxe +var a = 10; + +if (a == 2) { + trace("a is 2"); +} else if (a == 5) { + trace("a is 5"); +} else { + trace("a is 10"); +} + +// a is 10 +``` diff --git a/concepts/if-statements/links.json b/concepts/if-statements/links.json index 0d4f101c..813030e0 100644 --- a/concepts/if-statements/links.json +++ b/concepts/if-statements/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-if.html", + "description": "Haxe: If statement" + } ] diff --git a/concepts/indexers/.meta/config.json b/concepts/indexers/.meta/config.json deleted file mode 100644 index 9c452599..00000000 --- a/concepts/indexers/.meta/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "blurb": "TODO: add blurb for indexers concept", - "authors": [], - "contributors": [] -} diff --git a/concepts/indexers/about.md b/concepts/indexers/about.md deleted file mode 100644 index 928b50c6..00000000 --- a/concepts/indexers/about.md +++ /dev/null @@ -1 +0,0 @@ -TODO about: indexers \ No newline at end of file diff --git a/concepts/indexers/introduction.md b/concepts/indexers/introduction.md deleted file mode 100644 index f74cfd20..00000000 --- a/concepts/indexers/introduction.md +++ /dev/null @@ -1 +0,0 @@ -TODO introduction: indexers \ No newline at end of file diff --git a/concepts/indexers/links.json b/concepts/indexers/links.json deleted file mode 100644 index 0d4f101c..00000000 --- a/concepts/indexers/links.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/concepts/inheritance/.meta/config.json b/concepts/inheritance/.meta/config.json index fd8e8d85..29b18c7a 100644 --- a/concepts/inheritance/.meta/config.json +++ b/concepts/inheritance/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for inheritance concept", - "authors": [], + "blurb": "Inheritance allows derived classes to inherit the behavior and data of its parent class.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/inheritance/about.md b/concepts/inheritance/about.md index 7dee192d..679e41d3 100644 --- a/concepts/inheritance/about.md +++ b/concepts/inheritance/about.md @@ -1 +1,58 @@ -TODO about: inheritance \ No newline at end of file +# About + +In Haxe, a class hierarchy can be defined using _inheritance_, which allows a derived class (`Car`) to inherit the behavior and data of its parent class (`Vehicle`). + +In the parent class, you can: + +- Methods that can be overriden +- Abstract methods that must be implemented by the derived classes + +```haxe +abstract class Vehicle { + public function new() {} + + // Can be overridden + public function drive() { + // ... + } + + // Must be implemented + public abstract function getSpeed():Int; +} + +class Car extends Vehicle { + public function new() { + super(); // Runs the parent class' constructor + } + + public override function drive() { + // ... + } + + public function getSpeed():Int { + // ... + } +} +``` + +If the parent class has a constructor, we use `super()` to call it: + +```haxe +abstract class Vehicle { + var wheels:Int; + + public function new(wheels:Int) { + this.wheels = wheels + } +} + +class Car extends Vehicle { + var color:String; + + public function new(wheels:Int, color:String) { + super(wheels); + this.color = color; + } +} + +``` diff --git a/concepts/inheritance/introduction.md b/concepts/inheritance/introduction.md index 12202bd3..84a8b974 100644 --- a/concepts/inheritance/introduction.md +++ b/concepts/inheritance/introduction.md @@ -1 +1,58 @@ -TODO introduction: inheritance \ No newline at end of file +# Introduction + +In Haxe, a class hierarchy can be defined using _inheritance_, which allows a derived class (`Car`) to inherit the behavior and data of its parent class (`Vehicle`). + +In the parent class, you can: + +- Methods that can be overriden +- Abstract methods that must be implemented by the derived classes + +```haxe +abstract class Vehicle { + public function new() {} + + // Can be overridden + public function drive() { + // ... + } + + // Must be implemented + public abstract function getSpeed():Int; +} + +class Car extends Vehicle { + public function new() { + super(); // Runs the parent class' constructor + } + + public override function drive() { + // ... + } + + public function getSpeed():Int { + // ... + } +} +``` + +If the parent class has a constructor, we use `super()` to call it: + +```haxe +abstract class Vehicle { + var wheels:Int; + + public function new(wheels:Int) { + this.wheels = wheels + } +} + +class Car extends Vehicle { + var color:String; + + public function new(wheels:Int, color:String) { + super(wheels); + this.color = color; + } +} + +``` diff --git a/concepts/inheritance/links.json b/concepts/inheritance/links.json index 0d4f101c..57d20fea 100644 --- a/concepts/inheritance/links.json +++ b/concepts/inheritance/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-class-inheritance.html", + "description": "Haxe: Class Inheritance" + } ] diff --git a/concepts/integral-numbers/.meta/config.json b/concepts/integral-numbers/.meta/config.json deleted file mode 100644 index 3ab66e05..00000000 --- a/concepts/integral-numbers/.meta/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "blurb": "TODO: add blurb for integral-numbers concept", - "authors": [], - "contributors": [] -} diff --git a/concepts/integral-numbers/about.md b/concepts/integral-numbers/about.md deleted file mode 100644 index eacee4b6..00000000 --- a/concepts/integral-numbers/about.md +++ /dev/null @@ -1 +0,0 @@ -TODO about: integral-numbers \ No newline at end of file diff --git a/concepts/integral-numbers/introduction.md b/concepts/integral-numbers/introduction.md deleted file mode 100644 index bad20b22..00000000 --- a/concepts/integral-numbers/introduction.md +++ /dev/null @@ -1 +0,0 @@ -TODO introduction: integral-numbers \ No newline at end of file diff --git a/concepts/integral-numbers/links.json b/concepts/integral-numbers/links.json deleted file mode 100644 index 0d4f101c..00000000 --- a/concepts/integral-numbers/links.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/concepts/interfaces/.meta/config.json b/concepts/interfaces/.meta/config.json index 6bc03ee6..86ca7921 100644 --- a/concepts/interfaces/.meta/config.json +++ b/concepts/interfaces/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for interfaces concept", - "authors": [], + "blurb": "An interface describes the public fields of a class.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/interfaces/about.md b/concepts/interfaces/about.md index e52771d3..013aadb9 100644 --- a/concepts/interfaces/about.md +++ b/concepts/interfaces/about.md @@ -1 +1,23 @@ -TODO about: interfaces \ No newline at end of file +# About + +An interface can be understood as the signature of a class because it describes the public fields of a class. A class _implements_ an `interface` with the `implments` keyword. + +Its syntax is very similar to that of a class except that the methods appear as signatures without bodies: + +```haxe +interface Language { + private var languageName:String; + + public function speak():String; +} + +class FrenchSpeaker implements Language { + var languageName = "French"; + + public function speak():String { + return "Bonjour!"; + } +} +``` + +Fields that are implemented from an interface **must** always use the same visibility modifier. For example, if variable `a` is `public` in an interface, its implementation must also be `public`. diff --git a/concepts/interfaces/introduction.md b/concepts/interfaces/introduction.md index 66faa0cd..3e3518c8 100644 --- a/concepts/interfaces/introduction.md +++ b/concepts/interfaces/introduction.md @@ -1 +1,23 @@ -TODO introduction: interfaces \ No newline at end of file +# Introduction + +An interface can be understood as the signature of a class because it describes the public fields of a class. A class _implements_ an `interface` with the `implments` keyword. + +Its syntax is very similar to that of a class except that the methods appear as signatures without bodies: + +```haxe +interface Language { + private var languageName:String; + + public function speak():String; +} + +class FrenchSpeaker implements Language { + var languageName = "French"; + + public function speak():String { + return "Bonjour!"; + } +} +``` + +Fields that are implemented from an interface **must** always use the same visibility modifier. For example, if variable `a` is `public` in an interface, its implementation must also be `public`. diff --git a/concepts/interfaces/links.json b/concepts/interfaces/links.json index 0d4f101c..7e051c87 100644 --- a/concepts/interfaces/links.json +++ b/concepts/interfaces/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-interfaces.html", + "description": "Haxe: Interfaces" + } ] diff --git a/concepts/iterators/.meta/config.json b/concepts/iterators/.meta/config.json index a403a698..0adef1b1 100644 --- a/concepts/iterators/.meta/config.json +++ b/concepts/iterators/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for iterators concept", - "authors": [], + "blurb": "Iterators are used to iterate over a variable.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/iterators/about.md b/concepts/iterators/about.md index 2d09c15b..a93055ba 100644 --- a/concepts/iterators/about.md +++ b/concepts/iterators/about.md @@ -1 +1,59 @@ -TODO about: iterators \ No newline at end of file +# About + +Iterators in Haxe are used to iterate over a value using a `for` loop. There are two types of iterators: + +- `Iterator` which iterates over a value. +- `Iterable` data which makes it possible to iterate over a data type. + +Both of these concepts are represented by `Iterator` and `Iterable`: + +```haxe +typedef Iterator = { + function hasNext():Bool; + function next():T; +} + +typedef Iterable = { + function iterator():Iterator; +} +``` + +Any class that unifies with one of these types can be iterated over using a `for` loop. If a class defines the methods `hasNext` and `next` it is considered an iterator, else if it defines an `iterator` methods it's considered an iterable type: + +```haxe +class MyStringIterator { + var str:String; + var i:Int; + + public function new(str:String) { + this.str = str; + i = 0; + } + + public function hasNext():Bool { + return i < str.length; + } + + public function next():String { + return str.charAt(i++); + } +} +``` + +In the above example, the class `MyStringIterator` is considered an iterator since it implements both `hasNext` and `next` methods, making it compatible with `Iterator`. + +```haxe +class MyArrayWrap { + var arr:Array; + + public function new(a:Array) { + this.a = a; + } + + public function iterator() { + return a.iterator(); + } +} +``` + +Here, class `MyArrayWrap` is considered an iterable data type since it's compatible with `Iterable>`. diff --git a/concepts/iterators/introduction.md b/concepts/iterators/introduction.md index c61f1f7b..ae035179 100644 --- a/concepts/iterators/introduction.md +++ b/concepts/iterators/introduction.md @@ -1 +1,21 @@ -TODO introduction: iterators \ No newline at end of file +# Introduction + +Iterators in Haxe are used to iterate over a value using a `for` loop. There are two types of iterators: + +- `Iterator` which iterates over a value. +- `Iterable` data which makes it possible to iterate over a data type. + +Both of these concepts are represented by `Iterator` and `Iterable`: + +```haxe +typedef Iterator = { + function hasNext():Bool; + function next():T; +} + +typedef Iterable = { + function iterator():Iterator; +} +``` + +Any class that unifies with one of these types can be iterated over using a `for` loop. If a class defines the methods `hasNext` and `next` it is considered an iterator, else if it defines an `iterator` methods it's considered an iterable type. diff --git a/concepts/iterators/links.json b/concepts/iterators/links.json index 0d4f101c..3f591289 100644 --- a/concepts/iterators/links.json +++ b/concepts/iterators/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/lf-iterators.html", + "description": "Haxe: Iterators" + } ] diff --git a/concepts/lambda/.meta/config.json b/concepts/lambda/.meta/config.json index 948ce8cf..07525a06 100644 --- a/concepts/lambda/.meta/config.json +++ b/concepts/lambda/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for lambda concept", - "authors": [], + "blurb": "Lambdas allow us to operate on an entire Iterable data type at once.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/lambda/about.md b/concepts/lambda/about.md index a31c9deb..9f777620 100644 --- a/concepts/lambda/about.md +++ b/concepts/lambda/about.md @@ -1 +1,29 @@ -TODO about: lambda \ No newline at end of file +# About + +The Lambda class is a collection of functional methods in order to use functional-style programming with Haxe. It allows us to operate on an entire Iterable at once. This is often preferable to looping routines since it is less error-prone and easier to read. For convenience, the Array and List class contains some of the frequently used methods from the Lambda class. + +Some of the `Lambda` class functions include: + +- `Lambda.array`, `Lambda.list` Convert Iterable to Array or List. It always returns a new instance. +- `Lambda.count` Count the number of elements. If the Iterable is a Array or List it is faster to use its length property. +- `Lambda.has` Determine if the specified element is in the Iterable. +- `Lambda.indexOf` Find out the index of the specified element. +- `Lambda.find` Find first element of given search function. +- `Lambda.concat` Merge two Iterables, returning a new List. +- `Lambda.filter` Find the elements that satisfy a criteria, returning a new List. + +An example demonstrating som functions: + +```haxe +using Lambda; + +class Main { + static function main() { + var words = ["boat", "dog", "phone", "cat", "food"]; + + var isThreeLetters = function(word) return word.length == 3; + + trace(words.filter(isThreeLetters)); // [dog,cat] + } +} +``` diff --git a/concepts/lambda/introduction.md b/concepts/lambda/introduction.md index e8e104e7..c31d1fbe 100644 --- a/concepts/lambda/introduction.md +++ b/concepts/lambda/introduction.md @@ -1 +1,29 @@ -TODO introduction: lambda \ No newline at end of file +# Introduction + +The Lambda class is a collection of functional methods in order to use functional-style programming with Haxe. It allows us to operate on an entire Iterable at once. This is often preferable to looping routines since it is less error-prone and easier to read. For convenience, the Array and List class contains some of the frequently used methods from the Lambda class. + +Some of the `Lambda` class functions include: + +- `Lambda.array`, `Lambda.list` Convert Iterable to Array or List. It always returns a new instance. +- `Lambda.count` Count the number of elements. If the Iterable is a Array or List it is faster to use its length property. +- `Lambda.has` Determine if the specified element is in the Iterable. +- `Lambda.indexOf` Find out the index of the specified element. +- `Lambda.find` Find first element of given search function. +- `Lambda.concat` Merge two Iterables, returning a new List. +- `Lambda.filter` Find the elements that satisfy a criteria, returning a new List. + +An example demonstrating som functions: + +```haxe +using Lambda; + +class Main { + static function main() { + var words = ["boat", "dog", "phone", "cat", "food"]; + + var isThreeLetters = function(word) return word.length == 3; + + trace(words.filter(isThreeLetters)); // [dog,cat] + } +} +``` diff --git a/concepts/lambda/links.json b/concepts/lambda/links.json index 0d4f101c..1c69305a 100644 --- a/concepts/lambda/links.json +++ b/concepts/lambda/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-Lambda.html", + "description": "Haxe: Lambda class" + } ] diff --git a/concepts/lists/.meta/config.json b/concepts/lists/.meta/config.json index 2f6a3750..68e81e3c 100644 --- a/concepts/lists/.meta/config.json +++ b/concepts/lists/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for lists concept", - "authors": [], + "blurb": "Lists in Haxe are collections for storing elements.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/lists/about.md b/concepts/lists/about.md index 5f29e695..be63da08 100644 --- a/concepts/lists/about.md +++ b/concepts/lists/about.md @@ -1 +1,28 @@ -TODO about: lists \ No newline at end of file +# About + +A `List` is very similar to an [`Array`][array]. However, there are major differences that you don't wanna skip: + +1. A list cannot be indexed using square brackets, i.e. `[0]`. +2. A list cannot be initialized. +3. There are no list comprehensions. +4. A list can freely modify elemts while iterating over them. + +`List` is a member of the `haxe.ds` package, so everytime you want to use lists, you need to import its package: + +```haxe +import haxe.ds.List; + +class Main { + static function main() { + var myList = List(); + + for (i in 0...5) { + myList.add(i); + } + + trace(myList); // {0, 1, 2, 3, 4} + } +} +``` + +[array]: https://haxe.org/manual/std-Array.html diff --git a/concepts/lists/introduction.md b/concepts/lists/introduction.md index defa7de6..87a5a6eb 100644 --- a/concepts/lists/introduction.md +++ b/concepts/lists/introduction.md @@ -1 +1,26 @@ -TODO introduction: lists \ No newline at end of file +# Introduction + +A `List` is very similar to an `Array`. However, there are major differences that you don't wanna skip: + +1. A list cannot be indexed using square brackets, i.e. `[0]`. +2. A list cannot be initialized. +3. There are no list comprehensions. +4. A list can freely modify elemts while iterating over them. + +`List` is a member of the `haxe.ds` package, so everytime you want to use lists, you need to import its package: + +```haxe +import haxe.ds.List; + +class Main { + static function main() { + var myList = List(); + + for (i in 0...5) { + myList.add(i); + } + + trace(myList); // {0, 1, 2, 3, 4} + } +} +``` diff --git a/concepts/lists/links.json b/concepts/lists/links.json index 0d4f101c..40199c5f 100644 --- a/concepts/lists/links.json +++ b/concepts/lists/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-List.html", + "description": "Haxe: List" + } ] diff --git a/concepts/maps/.meta/config.json b/concepts/maps/.meta/config.json index bce91968..6defaac1 100644 --- a/concepts/maps/.meta/config.json +++ b/concepts/maps/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for maps concept", - "authors": [], + "blurb": "A Map is used to contain pairs of values.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/maps/about.md b/concepts/maps/about.md index dba8dae1..ffcd8420 100644 --- a/concepts/maps/about.md +++ b/concepts/maps/about.md @@ -1 +1,35 @@ -TODO about: maps \ No newline at end of file +# About + +A `Map` is used to store pairs of **key** and **value**. `Maps` are initialized just like an array, but use the map literal operator `=>`. They can also have their key-value types defined explicitly, or the types can be inferred. Keys must be unique, or else an error is thrown. + +```haxe +var map1:Map = [1 => "one", 2 => "two", 3 => "three"]; + +var map2 = ["one" => 1, "two" => 2, "three" => 3]; + +var map3 = [1 => "cat", 1 => "dog"]; // Error: Duplicate Key + +var map4 = ["h" => "Hello", "b" => "Bye"]; +trace(map4["h"]); // Hello +``` + +A `Map` can be iterated using a `for` loop. You can either iterate over the values or the keys: + +```haxe +for (value in map) { + // ... +} + +for (key in map.keys()) { + // ... +} +``` + +Under the hood, a `Map` is an abstract type. At compile time, it gets converted to one of several specialized types depending on the key type: + +- `String`: `haxe.ds.StringMap` +- `Int`: `haxe.ds.IntMap` +- `EnumValue`: `haxe.ds.EnumValueMap` +- `{}`: `haxe.ds.ObjectMap` + +The `Map` type does not exist at runtime and has been replaced with one of the above objects. diff --git a/concepts/maps/introduction.md b/concepts/maps/introduction.md index dc7e8ba1..0ed62d79 100644 --- a/concepts/maps/introduction.md +++ b/concepts/maps/introduction.md @@ -1 +1,26 @@ -TODO introduction: maps \ No newline at end of file +# Introduction + +A `Map` is used to store pairs of **key** and **value**. `Maps` are initialized just like an array, but use the map literal operator `=>`. They can also have their key-value types defined explicitly, or the types can be inferred. Keys must be unique, or else an error is thrown. + +```haxe +var map1:Map = [1 => "one", 2 => "two", 3 => "three"]; + +var map2 = ["one" => 1, "two" => 2, "three" => 3]; + +var map3 = [1 => "cat", 1 => "dog"]; // Error: Duplicate Key + +var map4 = ["h" => "Hello", "b" => "Bye"]; +trace(map4["h"]); // Hello +``` + +A `Map` can be iterated using a `for` loop. You can either iterate over the values or the keys: + +```haxe +for (value in map) { + // ... +} + +for (key in map.keys()) { + // ... +} +``` diff --git a/concepts/maps/links.json b/concepts/maps/links.json index 0d4f101c..a5d1b077 100644 --- a/concepts/maps/links.json +++ b/concepts/maps/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-Map.html", + "description": "Haxe: Map" + } ] diff --git a/concepts/nullability/.meta/config.json b/concepts/nullability/.meta/config.json index c7d2f0ba..35ea2666 100644 --- a/concepts/nullability/.meta/config.json +++ b/concepts/nullability/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for nullability concept", - "authors": [], + "blurb": "A nullable type is a type that allows for null values.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/nullability/about.md b/concepts/nullability/about.md index 2d9b7039..f96298e1 100644 --- a/concepts/nullability/about.md +++ b/concepts/nullability/about.md @@ -1 +1,18 @@ -TODO about: nullability \ No newline at end of file +# About + +The `null` value is used to denote the _absence_ of a value. A **nullable** type is a type that allows a variable to take the `null` value. To make any type nullable, we wrap it with `Null`: + +```haxe +var a:Int = null; // Error +var b:Null = null; // Allowed +``` + +To check if a value is currently `null`, simply use an `if` expression: + +```haxe +var a:Null = 10; + +if (a != null) { + trace("a is not null"); // a is not null +} +``` diff --git a/concepts/nullability/introduction.md b/concepts/nullability/introduction.md index 8290b544..932cc5ed 100644 --- a/concepts/nullability/introduction.md +++ b/concepts/nullability/introduction.md @@ -1 +1,18 @@ -TODO introduction: nullability \ No newline at end of file +# Introduction + +The `null` value is used to denote the _absence_ of a value. A **nullable** type is a type that allows a variable to take the `null` value. To make any type nullable, we wrap it with `Null`: + +```haxe +var a:Int = null; // Error +var b:Null = null; // Allowed +``` + +To check if a value is currently `null`, simply use an `if` expression: + +```haxe +var a:Null = 10; + +if (a != null) { + trace("a is not null"); // a is not null +} +``` diff --git a/concepts/nullability/links.json b/concepts/nullability/links.json index 0d4f101c..a916083c 100644 --- a/concepts/nullability/links.json +++ b/concepts/nullability/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-nullability.html", + "description": "Haxe: Nullability" + } ] diff --git a/concepts/numbers/.meta/config.json b/concepts/numbers/.meta/config.json index 0d51afc3..39c78795 100644 --- a/concepts/numbers/.meta/config.json +++ b/concepts/numbers/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for numbers concept", - "authors": [], + "blurb": "There are two types of numbers in Haxe - integers and floats.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/numbers/about.md b/concepts/numbers/about.md index 4d825fde..e4970917 100644 --- a/concepts/numbers/about.md +++ b/concepts/numbers/about.md @@ -1 +1,31 @@ -TODO about: numbers \ No newline at end of file +# About + +Haxe has two number types - integers and floats: + +- `Int`: Represents an integral number. +- `Float`: Represents a double-precision 64-bit floating point number. + +```haxe +var integer:Int = 10; +var floating:Float = 5.4; +``` + +While every `Int` can be used where a `Float` is expected (that is, `Int` **is assignable to** or **unifies with** `Float`), the reverse is not true: Assigning a `Float` to an `Int` might cause loss of precision and is therefore not allowed implicitly. + +## Comparison + +Numbers are equal if they have the same value. + +```haxe +1 == 1; // true + +1.2 == 1.2; // true + +1 == 1.0; // true + +0.2 + 0.1 == 0.3 // false +``` + +For the last case, see [0.30000000000000004.com][0.30000000000000004.com] for a brief explanation. + +[0.30000000000000004.com]: https://0.30000000000000004.com/ diff --git a/concepts/numbers/introduction.md b/concepts/numbers/introduction.md index 3ef127f7..def4a07c 100644 --- a/concepts/numbers/introduction.md +++ b/concepts/numbers/introduction.md @@ -1 +1,13 @@ -TODO introduction: numbers \ No newline at end of file +# Introduction + +Haxe has two number types - integers and floats: + +- `Int`: Represents an integral number. +- `Float`: Represents a double-precision 64-bit floating point number. + +```haxe +var integer:Int = 10; +var floating:Float = 5.4; +``` + +While every `Int` can be used where a `Float` is expected (that is, `Int` **is assignable to** or **unifies with** `Float`), the reverse is not true: Assigning a `Float` to an `Int` might cause loss of precision and is therefore not allowed implicitly. diff --git a/concepts/numbers/links.json b/concepts/numbers/links.json index 0d4f101c..f6446335 100644 --- a/concepts/numbers/links.json +++ b/concepts/numbers/links.json @@ -1,2 +1,14 @@ [ + { + "url": "https://haxe.org/manual/types-numeric-types.html", + "description": "Haxe: Numeric types" + }, + { + "url": "https://api.haxe.org/Float.html", + "description": "Haxe: Float numbers" + }, + { + "url": "https://api.haxe.org/Int.html", + "description": "Haxe: Integers" + } ] diff --git a/concepts/operator-overloading/.meta/config.json b/concepts/operator-overloading/.meta/config.json index c1b123c5..69fdd39a 100644 --- a/concepts/operator-overloading/.meta/config.json +++ b/concepts/operator-overloading/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for operator-overloading concept", - "authors": [], + "blurb": "Operator-overloading is the idea of adapting the principal arithmetic and comparison operators for use by your own classes and structs.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/operator-overloading/about.md b/concepts/operator-overloading/about.md index f141fa48..51a1d651 100644 --- a/concepts/operator-overloading/about.md +++ b/concepts/operator-overloading/about.md @@ -1 +1,28 @@ -TODO about: operator-overloading \ No newline at end of file +# About + +The principal arithmetic and comparison operators can be adapted for use by your own **abstract**. This is known as operator overloading. + +Use the `@:op()` metadata class field to overload an operator: + +```haxe +abstract MyAbstract(String) { + public inline function new(s:String) { + this = s; + } + + @:op(A * B) + public function repeat(rhs:Int):MyAbstract { + var s:StringBuf = new StringBuf(); + for (i in 0...rhs) + s.add(this); + return new MyAbstract(s.toString()); + } +} + +class Main { + static public function main() { + var a = new MyAbstract("foo"); + trace(a * 3); // foofoofoo + } +} +``` diff --git a/concepts/operator-overloading/introduction.md b/concepts/operator-overloading/introduction.md index a978498c..62199a23 100644 --- a/concepts/operator-overloading/introduction.md +++ b/concepts/operator-overloading/introduction.md @@ -1 +1,28 @@ -TODO introduction: operator-overloading \ No newline at end of file +# Introduction + +The principal arithmetic and comparison operators can be adapted for use by your own **abstract**. This is known as operator overloading. + +Use the `@:op()` metadata class field to overload an operator: + +```haxe +abstract MyAbstract(String) { + public inline function new(s:String) { + this = s; + } + + @:op(A * B) + public function repeat(rhs:Int):MyAbstract { + var s:StringBuf = new StringBuf(); + for (i in 0...rhs) + s.add(this); + return new MyAbstract(s.toString()); + } +} + +class Main { + static public function main() { + var a = new MyAbstract("foo"); + trace(a * 3); // foofoofoo + } +} +``` diff --git a/concepts/operator-overloading/links.json b/concepts/operator-overloading/links.json index 0d4f101c..05d186fd 100644 --- a/concepts/operator-overloading/links.json +++ b/concepts/operator-overloading/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/types-abstract-operator-overloading.html", + "description": "Haxe: Operator-Overloading" + } ] diff --git a/concepts/option-type/.meta/config.json b/concepts/option-type/.meta/config.json index bdba82a6..815446c0 100644 --- a/concepts/option-type/.meta/config.json +++ b/concepts/option-type/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for option type concept", - "authors": [], + "blurb": "Option is an enum in Haxe that is used to check valid returns.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/option-type/about.md b/concepts/option-type/about.md index bf05fe93..215987ec 100644 --- a/concepts/option-type/about.md +++ b/concepts/option-type/about.md @@ -1 +1,41 @@ -TODO about: option-type \ No newline at end of file +# About + +An [`Option`][option] is an [enum][enum] that is used to check the validity of function returns. It is defined as so: + +```haxe +enum Option { + Some(v:T); + None; +} +``` + +It is a part of the [`haxe.ds`][haxeDs] package: + +```haxe +import haxe.ds.Option; + +class Main { + static public function main() { + var result = trySomething(); + + switch (result) { + case None: + trace("Nothing"); + case Some(s): + trace("Got: " + s); + } + } + + static public function trySomething():Option { + if (Math.random() > 0.5) { + return None; + } else { + return Some("Success"); + } + } +} +``` + +[enum]: https://haxe.org/manual/types-enum-instance.html +[option]: https://api.haxe.org/haxe/ds/Option.html +[haxeDs]: https://api.haxe.org/haxe/ds/index.html diff --git a/concepts/option-type/introduction.md b/concepts/option-type/introduction.md index 8ec517b4..7557d528 100644 --- a/concepts/option-type/introduction.md +++ b/concepts/option-type/introduction.md @@ -1 +1,37 @@ -TODO introduction: option-type \ No newline at end of file +# Introduction + +An `Option` is an enum that is used to check the validity of function returns. It is defined as so: + +```haxe +enum Option { + Some(v:T); + None; +} +``` + +It is a part of the `haxe.ds` package: + +```haxe +import haxe.ds.Option; + +class Main { + static public function main() { + var result = trySomething(); + + switch (result) { + case None: + trace("Nothing"); + case Some(s): + trace("Got: " + s); + } + } + + static public function trySomething():Option { + if (Math.random() > 0.5) { + return None; + } else { + return Some("Success"); + } + } +} +``` diff --git a/concepts/option-type/links.json b/concepts/option-type/links.json index 0d4f101c..7d78b449 100644 --- a/concepts/option-type/links.json +++ b/concepts/option-type/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-Option.html", + "description": "Haxe: Option" + } ] diff --git a/concepts/optional-arguments/.meta/config.json b/concepts/optional-arguments/.meta/config.json index 8d6dbd4b..22453820 100644 --- a/concepts/optional-arguments/.meta/config.json +++ b/concepts/optional-arguments/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for optional-arguments concept", - "authors": [], + "blurb": "A method parameter can be made optional by assigning it a default value.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/optional-arguments/about.md b/concepts/optional-arguments/about.md index b46025bd..2672203b 100644 --- a/concepts/optional-arguments/about.md +++ b/concepts/optional-arguments/about.md @@ -1 +1,28 @@ -TODO about: optional-arguments \ No newline at end of file +# About + +A method parameter can be made optional by assigning it a default value. When calling a method with optional parameters, the caller is not required to pass a value for them. If no value is passed for an optional parameter, its default value will be used. + +Optional parameters must be at the end of the parameter list; they cannot be followed by non-optional parameters. + +```haxe +class Card { + static function newYear(year = 2021):String { + return "Happy " + year; + } +} + +Card.newYear(); // Happy 2020 +Card.newYear(1990); // Happy 1990 +``` + +The optional parameter can be set to `null` by using the `?` operator before the variable name: + +```haxe +function newYear(?year:Int) { + if (year != null) + return "It's " + year; + return "Year is null"; +} + +newYear(); // Year is null +``` diff --git a/concepts/optional-arguments/introduction.md b/concepts/optional-arguments/introduction.md index a8624117..7cda7b0d 100644 --- a/concepts/optional-arguments/introduction.md +++ b/concepts/optional-arguments/introduction.md @@ -1 +1,28 @@ -TODO introduction: optional-arguments \ No newline at end of file +# Introduction + +A method parameter can be made optional by assigning it a default value. When calling a method with optional parameters, the caller is not required to pass a value for them. If no value is passed for an optional parameter, its default value will be used. + +Optional parameters must be at the end of the parameter list; they cannot be followed by non-optional parameters. + +```haxe +class Card { + static function newYear(year = 2021):String { + return "Happy " + year; + } +} + +Card.newYear(); // Happy 2020 +Card.newYear(1990); // Happy 1990 +``` + +The optional parameter can be set to `null` by using the `?` operator before the variable name: + +```haxe +function newYear(?year:Int) { + if (year != null) + return "It's " + year; + return "Year is null"; +} + +newYear(); // Year is null +``` diff --git a/concepts/optional-arguments/links.json b/concepts/optional-arguments/links.json index 0d4f101c..cbdb6254 100644 --- a/concepts/optional-arguments/links.json +++ b/concepts/optional-arguments/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/types-function-optional-arguments.html", + "description": "Haxe: Optional arguments" + }, + { + "url": "https://haxe.org/manual/types-function-default-values.html", + "description": "Haxe: Default arguments" + } ] diff --git a/concepts/pattern-matching/.meta/config.json b/concepts/pattern-matching/.meta/config.json index 5c808ad7..b266fb1f 100644 --- a/concepts/pattern-matching/.meta/config.json +++ b/concepts/pattern-matching/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for pattern-matching concept", - "authors": [], + "blurb": "Pattern matching is the process of branching depending on a value matching given, possibly deep patterns.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/pattern-matching/about.md b/concepts/pattern-matching/about.md index 6f45ac9d..1d6957f7 100644 --- a/concepts/pattern-matching/about.md +++ b/concepts/pattern-matching/about.md @@ -1 +1,46 @@ -TODO about: pattern-matching \ No newline at end of file +# About + +Pattern matching is the process of branching depending on a value matching given, possibly deep patterns. In Haxe, **pattern matching** is done using `switch` expression and individual `case` expressions. + +Consider this data structre: + +```haxe +enum Tree { + Leaf(v:T); + Node(l:Tree, r:Tree); +} +``` + +- Patterns will always be matched from top to bottom. +- The topmost pattern that matches the input value has its expression executed. +- A `_` pattern matches anything, so `case _:` is equal to `default:` + +## Enum matching + +Enums can be matched by their constructor naturaly: + +```haxe +var myTree = Node(Leaf("foo"), Node(Leaf("bar"), Leaf("foobar"))); + +var match = switch (myTree) { + // Matches any Leaf + case Leaf(_): + "0"; + + // Matches any Node that has r = Leaf + case Node(_, Leaf(_)): + "1"; + + // Matches any Node that has + // r = another Node which has + // l = Leaf("bar") + case Node(_, Node(Leaf("bar", _))): + "2"; + + // Matches anything + case _: + "3"; +} + +trace(match); // 2 +``` diff --git a/concepts/pattern-matching/introduction.md b/concepts/pattern-matching/introduction.md index 721d38fc..82e6c779 100644 --- a/concepts/pattern-matching/introduction.md +++ b/concepts/pattern-matching/introduction.md @@ -1 +1,46 @@ -TODO introduction: pattern-matching \ No newline at end of file +# Introduction + +Pattern matching is the process of branching depending on a value matching given, possibly deep patterns. In Haxe, **pattern matching** is done using `switch` expression and individual `case` expressions. + +Consider this data structre: + +```haxe +enum Tree { + Leaf(v:T); + Node(l:Tree, r:Tree); +} +``` + +- Patterns will always be matched from top to bottom. +- The topmost pattern that matches the input value has its expression executed. +- A `_` pattern matches anything, so `case _:` is equal to `default:` + +## Enum matching + +Enums can be matched by their constructor naturaly: + +```haxe +var myTree = Node(Leaf("foo"), Node(Leaf("bar"), Leaf("foobar"))); + +var match = switch (myTree) { + // Matches any Leaf + case Leaf(_): + "0"; + + // Matches any Node that has r = Leaf + case Node(_, Leaf(_)): + "1"; + + // Matches any Node that has + // r = another Node which has + // l = Leaf("bar") + case Node(_, Node(Leaf("bar", _))): + "2"; + + // Matches anything + case _: + "3"; +} + +trace(match); // 2 +``` diff --git a/concepts/pattern-matching/links.json b/concepts/pattern-matching/links.json index 0d4f101c..0a4abc31 100644 --- a/concepts/pattern-matching/links.json +++ b/concepts/pattern-matching/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/lf-pattern-matching-introduction.html", + "description": "Haxe: Pattern matching introduction" + }, + { + "url": "https://haxe.org/manual/lf-pattern-matching-enums.html", + "description": "Haxe: Pattern matching enums" + } ] diff --git a/concepts/properties/.meta/config.json b/concepts/properties/.meta/config.json index 20a3e8bd..ae8f3ea0 100644 --- a/concepts/properties/.meta/config.json +++ b/concepts/properties/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for properties concept", - "authors": [], + "blurb": "A property is a member of a class that provides access to data within that class. Callers can set or retrieve (get) the data.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/properties/about.md b/concepts/properties/about.md index 0df6ded0..a6d8213f 100644 --- a/concepts/properties/about.md +++ b/concepts/properties/about.md @@ -1 +1,39 @@ -TODO about: properties \ No newline at end of file +# Introduction + +A property in Haxe is a member of a class that provides access to data within that class. Callers can set or retrieve (get) the data. They comprise a set accessor and/or a get accessor. + +Properties have access modifiers (public, private etc.) in the same way as other class members but the set accessor may have an access level independent of the retrieve (get) accessor and vice versa. A property doesn't have to have both accessors, it can have just one (either get or set). + +Read access and write access are directly reflected in the syntax, as the following example shows: + +```haxe +class Main { + public var x(default, null):Int; +} +``` + +Both `default` and `null` are special **access identifiers**. The access identifiers set the behavior for when the field is read (first identifier) and for when the field is written (second identifer). The accepted values are: + +- `default`: Allows normal field access if the field is public. +- `null`: Allows access only from within the defining class. +- `get/set`: Access is generated as a call to an accessor method (`get_x()`). +- `dynamic`: Same as `get/set` but the existance of an accessor method cannot be verified. +- `never`: Allows no access whatsoever. + +Here is a full example: + +```haxe +class Main { + public var x(default, set):Int; + + public function set_x(x:Int):Int { + return this.x = x + 2; + } + + public function main() { + trace(x); // null + x = 2; + trace(x); // 4 + } +} +``` diff --git a/concepts/properties/introduction.md b/concepts/properties/introduction.md index 867d749d..a6d8213f 100644 --- a/concepts/properties/introduction.md +++ b/concepts/properties/introduction.md @@ -1 +1,39 @@ -TODO introduction: properties \ No newline at end of file +# Introduction + +A property in Haxe is a member of a class that provides access to data within that class. Callers can set or retrieve (get) the data. They comprise a set accessor and/or a get accessor. + +Properties have access modifiers (public, private etc.) in the same way as other class members but the set accessor may have an access level independent of the retrieve (get) accessor and vice versa. A property doesn't have to have both accessors, it can have just one (either get or set). + +Read access and write access are directly reflected in the syntax, as the following example shows: + +```haxe +class Main { + public var x(default, null):Int; +} +``` + +Both `default` and `null` are special **access identifiers**. The access identifiers set the behavior for when the field is read (first identifier) and for when the field is written (second identifer). The accepted values are: + +- `default`: Allows normal field access if the field is public. +- `null`: Allows access only from within the defining class. +- `get/set`: Access is generated as a call to an accessor method (`get_x()`). +- `dynamic`: Same as `get/set` but the existance of an accessor method cannot be verified. +- `never`: Allows no access whatsoever. + +Here is a full example: + +```haxe +class Main { + public var x(default, set):Int; + + public function set_x(x:Int):Int { + return this.x = x + 2; + } + + public function main() { + trace(x); // null + x = 2; + trace(x); // 4 + } +} +``` diff --git a/concepts/properties/links.json b/concepts/properties/links.json index 0d4f101c..88bfb6cb 100644 --- a/concepts/properties/links.json +++ b/concepts/properties/links.json @@ -1,2 +1,10 @@ [ + { + "url": "https://haxe.org/manual/class-field-property.html", + "description": "Haxe: Field properties" + }, + { + "url": "https://haxe.org/manual/class-field-property-rules.html", + "description": "Haxe: Field property methods rules" + } ] diff --git a/concepts/randomness/.meta/config.json b/concepts/randomness/.meta/config.json index e4dc2f68..143b3152 100644 --- a/concepts/randomness/.meta/config.json +++ b/concepts/randomness/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for randomness concept", - "authors": [], + "blurb": "The Std.random method can be used to generate random numbers.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/randomness/about.md b/concepts/randomness/about.md index 680c47b1..3374d57d 100644 --- a/concepts/randomness/about.md +++ b/concepts/randomness/about.md @@ -1 +1,9 @@ -TODO about: randomness \ No newline at end of file +# About + +In Haxe, to generate a random number, you can use the `Std.random(x)` method. It generates a random number between 0 inclusive and `x` exclusive: + +```haxe +public function main() { + trace(Std.random(10)); // 0...9 +} +``` diff --git a/concepts/randomness/introduction.md b/concepts/randomness/introduction.md index 6bdd9374..5a9fe69e 100644 --- a/concepts/randomness/introduction.md +++ b/concepts/randomness/introduction.md @@ -1 +1,9 @@ -TODO introduction: randomness \ No newline at end of file +# Introduction + +In Haxe, to generate a random number, you can use the `Std.random(x)` method. It generates a random number between 0 inclusive and `x` exclusive: + +```haxe +public function main() { + trace(Std.random(10)); // 0...9 +} +``` diff --git a/concepts/randomness/links.json b/concepts/randomness/links.json index 0d4f101c..1effb7f9 100644 --- a/concepts/randomness/links.json +++ b/concepts/randomness/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/Std.html#random", + "description": "Haxe API: Random" + } ] diff --git a/concepts/reflection/.meta/config.json b/concepts/reflection/.meta/config.json index b32e2a8d..2a9eb3bc 100644 --- a/concepts/reflection/.meta/config.json +++ b/concepts/reflection/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for reflection concept", - "authors": [], + "blurb": "Haxe supports runtime reflection of types and fields.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/reflection/about.md b/concepts/reflection/about.md index e345a699..b55ba837 100644 --- a/concepts/reflection/about.md +++ b/concepts/reflection/about.md @@ -1 +1,26 @@ -TODO about: reflection \ No newline at end of file +# About + +Haxe supports runtime reflection of types and fields. In order to use reflection correctly, it is necessary to understand what kind of operations are supported and what is not. Given the dynamic nature of reflection, this can not always be determined at compile-time. + +The reflection API consists of two classes: + +- `Reflect`: A lightweight API which work best on anonymous structures, with limited support for classes. +- `Type`: A more robust API for working with classes and enums. + +The available methods are detailed in the API for [Reflect][reflect] and [Type][type]. + +For the following example, we are using the JavaScript target: + +```haxe +class Main { + public static function main() { + trace(Type.resolveClass("Main")); + } +} + +// This outputs +// class Test { static main() { console.log("Test.hx:3:",$hxClasses["Test"]); } } +``` + +[reflect]: https://api.haxe.org/Reflect.html +[type]: https://api.haxe.org/Type.html diff --git a/concepts/reflection/introduction.md b/concepts/reflection/introduction.md index c65e6acc..3df575e5 100644 --- a/concepts/reflection/introduction.md +++ b/concepts/reflection/introduction.md @@ -1 +1,21 @@ -TODO introduction: reflection \ No newline at end of file +# Introduction + +Haxe supports runtime reflection of types and fields. In order to use reflection correctly, it is necessary to understand what kind of operations are supported and what is not. Given the dynamic nature of reflection, this can not always be determined at compile-time. + +The reflection API consists of two classes: + +- `Reflect`: A lightweight API which work best on anonymous structures, with limited support for classes. +- `Type`: A more robust API for working with classes and enums. + +For the following example, we are using the JavaScript target: + +```haxe +class Main { + public static function main() { + trace(Type.resolveClass("Main")); + } +} + +// This outputs +// class Test { static main() { console.log("Test.hx:3:",$hxClasses["Test"]); } } +``` diff --git a/concepts/reflection/links.json b/concepts/reflection/links.json index 0d4f101c..cdd126f1 100644 --- a/concepts/reflection/links.json +++ b/concepts/reflection/links.json @@ -1,2 +1,14 @@ [ + { + "url": "https://haxe.org/manual/std-reflection.html", + "description": "Haxe: Reflection" + }, + { + "url": "https://api.haxe.org/Reflect.html", + "description": "Haxe API: Reflect" + }, + { + "url": "https://api.haxe.org/Type.html", + "description": "Haxe API: Type" + } ] diff --git a/concepts/regular-expressions/.meta/config.json b/concepts/regular-expressions/.meta/config.json index 10f622dc..828d1a74 100644 --- a/concepts/regular-expressions/.meta/config.json +++ b/concepts/regular-expressions/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for regular-expressions concept", - "authors": [], + "blurb": "A regular expression is a sequence of characters that specifies a search pattern.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/regular-expressions/about.md b/concepts/regular-expressions/about.md index 962395b1..ca181206 100644 --- a/concepts/regular-expressions/about.md +++ b/concepts/regular-expressions/about.md @@ -1 +1,27 @@ -TODO about: regular-expressions \ No newline at end of file +# About + +Haxe has built-in support for regular expressions. They can be used to verify the format of a string, transform a string or extract some regular data from a given text. + +To create a regular expression, type between `~/` and `/`: + +```haxe +var r = ~/haxe/i; +``` + +A different way to do this is by using the `EReg()` instance: + +```haxe +var r = new EReg("haxe", "i"); +``` + +Here the `i` is a flag that makes the pattern case insensitive. There are other flags including: + +- `g`: global replace. +- `m`: multiline matching + +Between `~/` and `/`, you type the regular expression patterns. For example, you want to look for a string that contains letters from A to Z. Here we can use the range pattern `[A-Z]`. There are many expression patterns including: + +- `.`: any character +- `*`: repeat zero or more +- `+`: repeat one or more +- `[A-Z0-9]`: character ranges diff --git a/concepts/regular-expressions/introduction.md b/concepts/regular-expressions/introduction.md index 8b0ebb9b..afb96b08 100644 --- a/concepts/regular-expressions/introduction.md +++ b/concepts/regular-expressions/introduction.md @@ -1 +1,27 @@ -TODO introduction: regular-expressions \ No newline at end of file +# Introduction + +Haxe has built-in support for regular expressions. They can be used to verify the format of a string, transform a string or extract some regular data from a given text. + +To create a regular expression, type between `~/` and `/`: + +```haxe +var r = ~/haxe/i; +``` + +A different way to do this is by using the `EReg()` instance: + +```haxe +var r = new EReg("haxe", "i"); +``` + +Here the `i` is a flag that makes the pattern case insensitive. There are other flags including: + +- `g`: global replace. +- `m`: multiline matching + +Between `~/` and `/`, you type the regular expression patterns. For example, you want to look for a string that contains letters from A to Z. Here we can use the range pattern `[A-Z]`. There are many expression patterns including: + +- `.`: any character +- `*`: repeat zero or more +- `+`: repeat one or more +- `[A-Z0-9]`: character ranges diff --git a/concepts/regular-expressions/links.json b/concepts/regular-expressions/links.json index 0d4f101c..80998111 100644 --- a/concepts/regular-expressions/links.json +++ b/concepts/regular-expressions/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-regex.html", + "description": "Haxe: Regular Expressions" + } ] diff --git a/concepts/rest-args/.meta/config.json b/concepts/rest-args/.meta/config.json index 63493717..7c41bb15 100644 --- a/concepts/rest-args/.meta/config.json +++ b/concepts/rest-args/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for rest args concept", - "authors": [], + "blurb": "Rest arguments are those with an indefinite number of elements.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/rest-args/about.md b/concepts/rest-args/about.md index 84192671..78baa6c7 100644 --- a/concepts/rest-args/about.md +++ b/concepts/rest-args/about.md @@ -1 +1,13 @@ -TODO about: rest-args \ No newline at end of file +# About + +The rest operator `...` is used to control arguments of an indefinite number of elements. It is put as the last argument of a function: + +```haxe +function f(...nums:Int) { + for (num in nums) { + trace(num); + } +} + +f(1, 2, 3, 4, 5); // Output is 1 2 3 4 5 +``` diff --git a/concepts/rest-args/introduction.md b/concepts/rest-args/introduction.md index 45b27d29..cd52e899 100644 --- a/concepts/rest-args/introduction.md +++ b/concepts/rest-args/introduction.md @@ -1 +1,13 @@ -TODO introduction: rest-args \ No newline at end of file +# Introduction + +The rest operator `...` is used to control arguments of an indefinite number of elements. It is put as the last argument of a function: + +```haxe +function f(...nums:Int) { + for (num in nums) { + trace(num); + } +} + +f(1, 2, 3, 4, 5); // Output is 1 2 3 4 5 +``` diff --git a/concepts/rest-args/links.json b/concepts/rest-args/links.json index 0d4f101c..04cb5ccc 100644 --- a/concepts/rest-args/links.json +++ b/concepts/rest-args/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/haxe/Rest.html", + "description": "Haxe API: Rest" + } ] diff --git a/concepts/string-buffer/.meta/config.json b/concepts/string-buffer/.meta/config.json index 613b1602..d5925898 100644 --- a/concepts/string-buffer/.meta/config.json +++ b/concepts/string-buffer/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for string-buffer concept", - "authors": [], + "blurb": "A String buffer is an efficient way to build a big string by appending small elements together.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/string-buffer/about.md b/concepts/string-buffer/about.md index 28981278..3c673403 100644 --- a/concepts/string-buffer/about.md +++ b/concepts/string-buffer/about.md @@ -1 +1,11 @@ -TODO about: string-buffer \ No newline at end of file +# About + +A String buffer is an efficient way to build a big string by appending small elements together. Unlike String, an instance of StringBuf is not immutable in the sense that it can be passed as argument to functions which modify it by appending more values. + +```haxe +var a = new StringBuf(); +a.add("Hello"); +trace(a.toString()); // Hello +a.add("Haxe!"); +trace(a.toString()); // HelloHaxe +``` diff --git a/concepts/string-buffer/introduction.md b/concepts/string-buffer/introduction.md index d8f813da..149bbbfa 100644 --- a/concepts/string-buffer/introduction.md +++ b/concepts/string-buffer/introduction.md @@ -1 +1,11 @@ -TODO introduction: string-buffer \ No newline at end of file +# Introduction + +A String buffer is an efficient way to build a big string by appending small elements together. Unlike String, an instance of StringBuf is not immutable in the sense that it can be passed as argument to functions which modify it by appending more values. + +```haxe +var a = new StringBuf(); +a.add("Hello"); +trace(a.toString()); // Hello +a.add("Haxe!"); +trace(a.toString()); // HelloHaxe +``` diff --git a/concepts/string-buffer/links.json b/concepts/string-buffer/links.json index 0d4f101c..3676eb60 100644 --- a/concepts/string-buffer/links.json +++ b/concepts/string-buffer/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/StringBuf.html", + "description": "Haxe API: StringBuf" + } ] diff --git a/concepts/string-interpolation/.meta/config.json b/concepts/string-interpolation/.meta/config.json index abdc5c64..69b1a960 100644 --- a/concepts/string-interpolation/.meta/config.json +++ b/concepts/string-interpolation/.meta/config.json @@ -1,5 +1,9 @@ { - "blurb": "TODO: add blurb for string-interpolation concept", - "authors": [], - "contributors": [] + "blurb": "String interpolation is used to insert variables in strings faster.", + "authors": [ + "mfoda" + ], + "contributors": [ + "midyHamdoun" + ] } diff --git a/concepts/string-interpolation/about.md b/concepts/string-interpolation/about.md index 59b4a127..a6d1361f 100644 --- a/concepts/string-interpolation/about.md +++ b/concepts/string-interpolation/about.md @@ -1,3 +1,5 @@ +# About + While manually concatenating strings in Haxe is possible, Haxe supports [string interpolation][interpolation], which provides a shorter and more convenient syntax: ```haxe diff --git a/concepts/string-interpolation/introduction.md b/concepts/string-interpolation/introduction.md index 2f8afd11..2837af73 100644 --- a/concepts/string-interpolation/introduction.md +++ b/concepts/string-interpolation/introduction.md @@ -1,3 +1,11 @@ +# Introduction + String interpolation is supported in Haxe by enclosing a string with single-quote (`'`) characters and using the dollar-sign (`$`) to trigger interpolation. It is also possible to include whole expressions by using `${expr}`, where `expr` is any valid Haxe expression. + +```haxe +var x = 10; +trace('They have $x apples, of which ${x - 4} are red.'); +// They have 10 apples of which 6 are red. +``` diff --git a/concepts/string-interpolation/links.json b/concepts/string-interpolation/links.json index 89bd0b7e..1c91c83b 100644 --- a/concepts/string-interpolation/links.json +++ b/concepts/string-interpolation/links.json @@ -1,10 +1,10 @@ [ { "url": "https://haxe.org/manual/std-String.html", - "description": "string" + "description": "Haxe: String" }, { "url": "https://haxe.org/manual/lf-string-interpolation.html", - "description": "String interpolation" + "description": "Haxe: String interpolation" } ] diff --git a/concepts/strings/.meta/config.json b/concepts/strings/.meta/config.json index 763d58ec..e323027a 100644 --- a/concepts/strings/.meta/config.json +++ b/concepts/strings/.meta/config.json @@ -1,7 +1,9 @@ { - "blurb": "TODO: add blurb for strings concept", + "blurb": "Strings are objects representing text as a sequence of Unicode characters.", "authors": [ "mfoda" ], - "contributors": [] + "contributors": [ + "midyHamdoun" + ] } diff --git a/concepts/strings/links.json b/concepts/strings/links.json index 561b6b3e..875433fb 100644 --- a/concepts/strings/links.json +++ b/concepts/strings/links.json @@ -1,18 +1,22 @@ [ { - "description": "string", - "url": "https://code.haxe.org/category/beginner/strings.html" + "url": "https://haxe.org/manual/std-String.html", + "description": "Haxe: String" }, { - "description": "String API", - "url": "https://api.haxe.org/String.html" + "url": "https://code.haxe.org/category/beginner/strings.html", + "description": "Haxe Cookbook: Strings" }, { - "description": "escaping", - "url": "https://haxe.org/manual/std-String-literals.html" + "url": "https://api.haxe.org/String.html", + "description": "Haxe API: String" }, { - "description": "plus-operator", - "url": "https://haxe.org/manual/expression-operators-binops.html#string-concatenation-operator" + "url": "https://haxe.org/manual/std-String-literals.html", + "description": "Haxe: Escaping strings" + }, + { + "url": "https://haxe.org/manual/expression-operators-binops.html#string-concatenation-operator", + "description": "Haxe: plus-operator" } ] diff --git a/concepts/switch-expressions/.meta/config.json b/concepts/switch-expressions/.meta/config.json index 4328a214..b2523f77 100644 --- a/concepts/switch-expressions/.meta/config.json +++ b/concepts/switch-expressions/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for switch-expressions concept", - "authors": [], + "blurb": "A switch is a selection statement that executes a single case from a list of cases based on a pattern match.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/switch-expressions/about.md b/concepts/switch-expressions/about.md index 27689c20..5a077938 100644 --- a/concepts/switch-expressions/about.md +++ b/concepts/switch-expressions/about.md @@ -1 +1,22 @@ -TODO about: switch-expressions \ No newline at end of file +# About + +Besides the `if` statement, there is also a `switch` statement to conditionally execute logic. It is used when a single variable needs to be compared to multiple variants. For some variable x, the switch statement in Haxe has the following syntax. + +```haxe +var a = 2; + +switch (a) { + case 0: + trace("a is 0"); + case 1: + trace("a is 1"); + case 2: + trace("a is 2"); + default: + trace("a is something else"); +} + +// a is 2 +``` + +The `default` case executes when no other cases match. diff --git a/concepts/switch-expressions/introduction.md b/concepts/switch-expressions/introduction.md index e694d7e0..c04d0403 100644 --- a/concepts/switch-expressions/introduction.md +++ b/concepts/switch-expressions/introduction.md @@ -1 +1,22 @@ -TODO introduction: switch-expressions \ No newline at end of file +# Introduction + +Besides the `if` statement, there is also a `switch` statement to conditionally execute logic. It is used when a single variable needs to be compared to multiple variants. For some variable x, the switch statement in Haxe has the following syntax. + +```haxe +var a = 2; + +switch (a) { + case 0: + trace("a is 0"); + case 1: + trace("a is 1"); + case 2: + trace("a is 2"); + default: + trace("a is something else"); +} + +// a is 2 +``` + +The `default` case executes when no other cases match. diff --git a/concepts/switch-expressions/links.json b/concepts/switch-expressions/links.json index 0d4f101c..dfe289ed 100644 --- a/concepts/switch-expressions/links.json +++ b/concepts/switch-expressions/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-switch.html", + "description": "Haxe: Switch" + } ] diff --git a/concepts/templates/.meta/config.json b/concepts/templates/.meta/config.json index 29e48e36..e78c0efd 100644 --- a/concepts/templates/.meta/config.json +++ b/concepts/templates/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for templates concept", - "authors": [], + "blurb": "A template is a string or a file that is used to produce any kind of string output depending on the input.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/templates/about.md b/concepts/templates/about.md index 227ecfbd..ddf9bbdc 100644 --- a/concepts/templates/about.md +++ b/concepts/templates/about.md @@ -1 +1,23 @@ -TODO about: templates \ No newline at end of file +# About + +A template is a string or a file that is used to produce any kind of string output depending on the input. + +```haxe +var sample = "My name is ::name::"; +var template = new haxe.Template(sample); +var myName = {name: "Joe"}; +var output = template.execute(myName); + +trace(output); // My name is Joe +``` + +Among other things, you can also use conditions to check inside the templates: + +```haxe +var sample = "::if isAwake:: I'm awake ::else:: Zzzzz ::end::"; +var template = new haxe.Template(sample); +var awake = {isAwake: false}; +var output = template.execute(awake); + +trace(output); // Zzzzz +``` diff --git a/concepts/templates/introduction.md b/concepts/templates/introduction.md index 223a2c3d..b0b70455 100644 --- a/concepts/templates/introduction.md +++ b/concepts/templates/introduction.md @@ -1 +1,23 @@ -TODO introduction: templates \ No newline at end of file +# Introduction + +A template is a string or a file that is used to produce any kind of string output depending on the input. + +```haxe +var sample = "My name is ::name::"; +var template = new haxe.Template(sample); +var myName = {name: "Joe"}; +var output = template.execute(myName); + +trace(output); // My name is Joe +``` + +Among other things, you can also use conditions to check inside the templates: + +```haxe +var sample = "::if isAwake:: I'm awake ::else:: Zzzzz ::end::"; +var template = new haxe.Template(sample); +var awake = {isAwake: false}; +var output = template.execute(awake); + +trace(output); // Zzzzz +``` diff --git a/concepts/templates/links.json b/concepts/templates/links.json index 0d4f101c..c60f20e8 100644 --- a/concepts/templates/links.json +++ b/concepts/templates/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/std-template.html", + "description": "Haxe: Templates" + } ] diff --git a/concepts/ternary-operators/.meta/config.json b/concepts/ternary-operators/.meta/config.json index 726aa606..e1d78465 100644 --- a/concepts/ternary-operators/.meta/config.json +++ b/concepts/ternary-operators/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for ternary-operators concept", - "authors": [], + "blurb": "Ternary operators allow if-conditions to be defined in expressions rather than statement blocks.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/ternary-operators/about.md b/concepts/ternary-operators/about.md index 629532d1..2a23fe4a 100644 --- a/concepts/ternary-operators/about.md +++ b/concepts/ternary-operators/about.md @@ -1 +1,10 @@ -TODO about: ternary-operators \ No newline at end of file +# About + +Ternary operators allow `if` conditions to be defined in expressions rather than statement blocks. This echoes functional programming approaches and can often make code more expressive and less error-prone. + +The ternary operator combines 3 expressions: a condition followed by an expression to be evaluated and returned if the condition is true (the `if` part, introduced by `?`) and an expression to be evaluated and returned if the condition is false (the `else` part, introduced by `:`). + +```haxe +trace(true ? "Haxe" : "Not Haxe"); // Haxe +trace(1 == 2 ? "Something is wrong" : "That's obvious"); // That's obvious +``` diff --git a/concepts/ternary-operators/introduction.md b/concepts/ternary-operators/introduction.md index c5b23ea0..747ca525 100644 --- a/concepts/ternary-operators/introduction.md +++ b/concepts/ternary-operators/introduction.md @@ -1 +1,10 @@ -TODO introduction: ternary-operators \ No newline at end of file +# Introduction + +Ternary operators allow `if` conditions to be defined in expressions rather than statement blocks. This echoes functional programming approaches and can often make code more expressive and less error-prone. + +The ternary operator combines 3 expressions: a condition followed by an expression to be evaluated and returned if the condition is true (the `if` part, introduced by `?`) and an expression to be evaluated and returned if the condition is false (the `else` part, introduced by `:`). + +```haxe +trace(true ? "Haxe" : "Not Haxe"); // Haxe +trace(1 == 2 ? "Something is wrong" : "That's obvious"); // That's obvious +``` diff --git a/concepts/ternary-operators/links.json b/concepts/ternary-operators/links.json index 0d4f101c..30691068 100644 --- a/concepts/ternary-operators/links.json +++ b/concepts/ternary-operators/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-operators-ternary.html", + "description": "Haxe: Ternary operator" + } ] diff --git a/concepts/throw-expressions/.meta/config.json b/concepts/throw-expressions/.meta/config.json index 76e32681..74fb374c 100644 --- a/concepts/throw-expressions/.meta/config.json +++ b/concepts/throw-expressions/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for throw-expressions concept", - "authors": [], + "blurb": "Throw expressions are an alternative to throw statements and in particular can add to the power of ternary and other compound expressions.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/throw-expressions/about.md b/concepts/throw-expressions/about.md index 68190242..0b3ea948 100644 --- a/concepts/throw-expressions/about.md +++ b/concepts/throw-expressions/about.md @@ -1 +1,7 @@ -TODO about: throw-expressions \ No newline at end of file +# About + +`throw` **expressions** are an alternative to `throw` _statements_ and in particular can add to the power of ternary and other compound expressions. + +```haxe +trace(true ? throw "This is an error" : "Everything is fine"); // ERROR: This is an error +``` diff --git a/concepts/throw-expressions/introduction.md b/concepts/throw-expressions/introduction.md index b2b43a3e..7a7858ee 100644 --- a/concepts/throw-expressions/introduction.md +++ b/concepts/throw-expressions/introduction.md @@ -1 +1,7 @@ -TODO introduction: throw-expressions \ No newline at end of file +# Introduction + +`throw` **expressions** are an alternative to `throw` _statements_ and in particular can add to the power of ternary and other compound expressions. + +```haxe +trace(true ? throw "This is an error" : "Everything is fine"); // ERROR: This is an error +``` diff --git a/concepts/throw-expressions/links.json b/concepts/throw-expressions/links.json index 0d4f101c..2c21d26d 100644 --- a/concepts/throw-expressions/links.json +++ b/concepts/throw-expressions/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-throw.html", + "description": "Haxe: Throw" + } ] diff --git a/concepts/time/.meta/config.json b/concepts/time/.meta/config.json index e88d847c..a831fe7d 100644 --- a/concepts/time/.meta/config.json +++ b/concepts/time/.meta/config.json @@ -1,5 +1,5 @@ { - "blurb": "TODO: add blurb for time concept", - "authors": [], + "blurb": "Datetimes are objects that contain date and time.", + "authors": ["midyHamdoun"], "contributors": [] } diff --git a/concepts/time/about.md b/concepts/time/about.md index e5070b2d..f259aab8 100644 --- a/concepts/time/about.md +++ b/concepts/time/about.md @@ -1 +1,7 @@ -TODO about: time \ No newline at end of file +# About + +A [`Date`][date] object in Haxe is and object that contains both _date_ and _time_. Its value cannot be mutated once the constructor has been called. + +The default format of the `Date` object is: `DAY MONTH day year hours:minutes:seconds timezone`. For example `Sat Jan 1 2022 10:30:43 GMT+0000 (Greenwich Mean Time)`. + +[date]: https://api.haxe.org/Date.html diff --git a/concepts/time/introduction.md b/concepts/time/introduction.md index a65ce498..c32c90b1 100644 --- a/concepts/time/introduction.md +++ b/concepts/time/introduction.md @@ -1 +1,5 @@ -TODO introduction: time \ No newline at end of file +# Introduction + +A `Date` object in Haxe is and object that contains both _date_ and _time_. Its value cannot be mutated once the constructor has been called. + +The default format of the `Date` object is: `DAY MONTH day year hours:minutes:seconds timezone`. For example `Sat Jan 1 2022 10:30:43 GMT+0000 (Greenwich Mean Time)`. diff --git a/concepts/time/links.json b/concepts/time/links.json index 0d4f101c..66c5eda1 100644 --- a/concepts/time/links.json +++ b/concepts/time/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://api.haxe.org/Date.html", + "description": "Haxe API: Date" + } ] diff --git a/concepts/typedefs/.meta/config.json b/concepts/typedefs/.meta/config.json index df7c4b6d..235b1bec 100644 --- a/concepts/typedefs/.meta/config.json +++ b/concepts/typedefs/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for typedefs concept", - "authors": [], + "blurb": "Typedefs are used to create new type structures.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/typedefs/about.md b/concepts/typedefs/about.md index 13a5544b..2166b70f 100644 --- a/concepts/typedefs/about.md +++ b/concepts/typedefs/about.md @@ -1 +1,16 @@ -TODO about: typedefs \ No newline at end of file +# About + +Typedefs can be used to shorten names of complex types: + +```haxe +typedef IA = Array; +``` + +You can also use typedefs to create a type structure: + +```haxe +typedef User = { + var name:String; + var age:Int; +} +``` diff --git a/concepts/typedefs/introduction.md b/concepts/typedefs/introduction.md index 351c12dd..1a5a6310 100644 --- a/concepts/typedefs/introduction.md +++ b/concepts/typedefs/introduction.md @@ -1 +1,16 @@ -TODO introduction: typedefs \ No newline at end of file +# Introduction + +Typedefs can be used to shorten names of complex types: + +```haxe +typedef IA = Array; +``` + +You can also use typedefs to create a type structure: + +```haxe +typedef User = { + var name:String; + var age:Int; +} +``` diff --git a/concepts/typedefs/links.json b/concepts/typedefs/links.json index 0d4f101c..820389f2 100644 --- a/concepts/typedefs/links.json +++ b/concepts/typedefs/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/type-system-typedef.html", + "description": "Haxe: Typedefs" + } ] diff --git a/concepts/using-statements/.meta/config.json b/concepts/using-statements/.meta/config.json index 5add8a15..c577c92d 100644 --- a/concepts/using-statements/.meta/config.json +++ b/concepts/using-statements/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for using statements concept", - "authors": [], + "blurb": "A static extension allows pseudo-extending existing types without modifying their source. That's achieved using the using statement.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/using-statements/about.md b/concepts/using-statements/about.md index 556771d1..7ce3dd14 100644 --- a/concepts/using-statements/about.md +++ b/concepts/using-statements/about.md @@ -1 +1,19 @@ -TODO about: using-statements \ No newline at end of file +# About + +A static extension allows pseudo-extending existing types without modifying their source. This is achieved by using the `using` statement. Static extensions can be a powerful tool which allows augmenting types without actually changing them. + +```haxe +using Main.IntExtender; + +class Main { + public static function main() { + trace(2.triple()); // 6 + } +} + +class IntExtender { + public static function triple(i:Int):Int { + return i * 3; + } +} +``` diff --git a/concepts/using-statements/introduction.md b/concepts/using-statements/introduction.md index ae14b91e..2c64a915 100644 --- a/concepts/using-statements/introduction.md +++ b/concepts/using-statements/introduction.md @@ -1 +1,19 @@ -TODO introduction: using-statements \ No newline at end of file +# Introduction + +A static extension allows pseudo-extending existing types without modifying their source. This is achieved by using the `using` statement. Static extensions can be a powerful tool which allows augmenting types without actually changing them. + +```haxe +using Main.IntExtender; + +class Main { + public static function main() { + trace(2.triple()); // 6 + } +} + +class IntExtender { + public static function triple(i:Int):Int { + return i * 3; + } +} +``` diff --git a/concepts/using-statements/links.json b/concepts/using-statements/links.json index 0d4f101c..d0525b81 100644 --- a/concepts/using-statements/links.json +++ b/concepts/using-statements/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/lf-static-extension.html", + "description": "Haxe: Static Extension" + } ] diff --git a/concepts/while-loops/.meta/config.json b/concepts/while-loops/.meta/config.json index bacac95d..e194e531 100644 --- a/concepts/while-loops/.meta/config.json +++ b/concepts/while-loops/.meta/config.json @@ -1,5 +1,7 @@ { - "blurb": "TODO: add blurb for while-loops concept", - "authors": [], + "blurb": "A while loop continues looping until a boolean condition evaluates to false.", + "authors": [ + "midyHamdoun" + ], "contributors": [] } diff --git a/concepts/while-loops/about.md b/concepts/while-loops/about.md index 20379975..0c70b0b4 100644 --- a/concepts/while-loops/about.md +++ b/concepts/while-loops/about.md @@ -1 +1,14 @@ -TODO about: while-loops \ No newline at end of file +# About + +A `while` loop continues looping until a boolean condition evaluates to false. + +```haxe +var i = 0; + +while (i < 10) { + trace(i); + i++; +} + +// Outputs from 0 to 9 +``` diff --git a/concepts/while-loops/introduction.md b/concepts/while-loops/introduction.md index 69e82d97..1d207739 100644 --- a/concepts/while-loops/introduction.md +++ b/concepts/while-loops/introduction.md @@ -1 +1,14 @@ -TODO introduction: while-loops \ No newline at end of file +# Introduction + +A `while` loop continues looping until a boolean condition evaluates to false. + +```haxe +var i = 0; + +while (i < 10) { + trace(i); + i++; +} + +// Outputs from 0 to 9 +``` diff --git a/concepts/while-loops/links.json b/concepts/while-loops/links.json index 0d4f101c..f84ea838 100644 --- a/concepts/while-loops/links.json +++ b/concepts/while-loops/links.json @@ -1,2 +1,6 @@ [ + { + "url": "https://haxe.org/manual/expression-while.html", + "description": "Haxe: While" + } ] diff --git a/config.json b/config.json index e948af80..3a1a34f0 100644 --- a/config.json +++ b/config.json @@ -8,7 +8,7 @@ "representer": false, "analyzer": false }, - "blurb": "Haxe is an open source high-level strictly-typed programming language with a fast optimizing cross-compiler. Haxe can build cross-platform applications targeting JavaScript, C++, C#, Java, JVM, Python, Lua, PHP, Flash, and allows access to each platform's native capabilities. Haxe has its own VMs (HashLink and NekoVM) but can also run in interpreted mode. Code written in Haxe can be compiled to any target Haxe supports.", + "blurb": "Haxe is an open source high-level strictly-typed programming language with a fast cross-compiler. Haxe can build cross-platform applications targeting JavaScript, C++, C#, Java, JVM, Python, and allows access to each platform's native capabilities. Haxe has its own VMs (HashLink and NekoVM) but can also run in interpreted mode. Code written in Haxe can be compiled to any target Haxe supports.", "version": 3, "online_editor": { "indent_style": "space", @@ -240,10 +240,7 @@ "practices": [ "strings" ], - "prerequisites": [ - "basics", - "strings" - ], + "prerequisites": [], "difficulty": 1 }, { diff --git a/docs/ABOUT.md b/docs/ABOUT.md new file mode 100644 index 00000000..ef8c0438 --- /dev/null +++ b/docs/ABOUT.md @@ -0,0 +1,33 @@ +# About + +Haxe is an open source high-level, strongly-types, cross-platform, object-oriented programming language and compiler that can produce applications and source code, for many different computing platforms from one code-base. + +Currently, there are nine supported target languages which allow for different use-cases: + +| Name | Main usages | +| ----------- | -------------------------------------- | +| JavaScript | Browser, Desktop, Mobile, Server | +| Neko | Desktop, Server, CLI | +| HashLink | Desktop, Mobile, Game consoles | +| PHP | Server | +| Python | Desktop, Server | +| Lua | Desktop, Scripting | +| C++ | Desktop, Mobile, Server, Game consoles | +| Flash | Desktop, Mobile | +| Java | Desktop, Mobile, Server | +| JVM | Desktop, Mobile, Server | +| C# | Desktop, Mobile, Server | + +[Types][types] introduces the seven different kinds of types in Haxe and how they interact with each other. The discussion of types is continued in [Type System][type-system], where features like unification, type parameters and type inference are explained. + +[Class Fields][class-fields] is all about the structure of Haxe classes and, among other topics, deals with properties, inline fields and generic functions. + +In [Expressions][expressions] we see how to actually get programs to do something by using expressions. + +[Language Features][language-features] concludes the Haxe language reference by describing some features in detail such as pattern matching, string interpolation and dead code elimination. + +[types]: https://haxe.org/manual/types.html +[type-system]: https://haxe.org/manual/type-system.html +[class-fields]: https://haxe.org/manual/class-field.html +[expressions]: https://haxe.org/manual/expression.html +[language-features]: https://haxe.org/manual/lf.html \ No newline at end of file diff --git a/docs/RESOURCES.md b/docs/RESOURCES.md new file mode 100644 index 00000000..6942f8a5 --- /dev/null +++ b/docs/RESOURCES.md @@ -0,0 +1,5 @@ +# Recommended References + +- [Haxe manual][haxe-manual] + +[haxe-manual]: https://haxe.org/manual/introduction.html \ No newline at end of file