Skip to content

Commit

Permalink
Add all concepts and fix CI (#199)
Browse files Browse the repository at this point in the history
Add all concepts and fix CI
  • Loading branch information
midyh authored Jan 19, 2022
1 parent 4d42903 commit f932cb5
Show file tree
Hide file tree
Showing 204 changed files with 2,597 additions and 233 deletions.
4 changes: 2 additions & 2 deletions concepts/abstract-types/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
34 changes: 33 additions & 1 deletion concepts/abstract-types/about.md
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
TODO about: abstract-types
# 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
23 changes: 22 additions & 1 deletion concepts/abstract-types/introduction.md
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
TODO introduction: abstract-types
# 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
}
}
```
4 changes: 4 additions & 0 deletions concepts/abstract-types/links.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[
{
"url": "https://haxe.org/manual/types-abstract.html",
"description": "Haxe: Abstract types"
}
]
4 changes: 2 additions & 2 deletions concepts/array-comprehension/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
43 changes: 42 additions & 1 deletion concepts/array-comprehension/about.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
TODO about: array-comprehension
# 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]
}
```
28 changes: 27 additions & 1 deletion concepts/array-comprehension/introduction.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
TODO introduction: array-comprehension
# 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]
}
```
4 changes: 4 additions & 0 deletions concepts/array-comprehension/links.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[
{
"url": "https://haxe.org/manual/lf-array-comprehension.html",
"description": "Haxe: Array comprehension"
}
]
4 changes: 2 additions & 2 deletions concepts/arrays/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
47 changes: 46 additions & 1 deletion concepts/arrays/about.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
TODO about: arrays
# 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<Int> = [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<Dynamic> = [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
```
28 changes: 27 additions & 1 deletion concepts/arrays/introduction.md
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
TODO introduction: arrays
# 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<Int> = [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<Dynamic> = [10, "Bob", true]
```
8 changes: 8 additions & 0 deletions concepts/arrays/links.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
4 changes: 2 additions & 2 deletions concepts/basics/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blurb": "TODO: add blurb for basics concept",
"authors": [],
"blurb": "Learn about Haxe basics like functions and variables.",
"authors": ["midyHamdoun"],
"contributors": []
}
39 changes: 38 additions & 1 deletion concepts/basics/about.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
TODO about: basics
# 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
41 changes: 40 additions & 1 deletion concepts/basics/introduction.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
TODO introduction: basics
# 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 `*/`.
8 changes: 8 additions & 0 deletions concepts/basics/links.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
4 changes: 2 additions & 2 deletions concepts/bit-manipulation/.meta/config.json
Original file line number Diff line number Diff line change
@@ -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": []
}
15 changes: 14 additions & 1 deletion concepts/bit-manipulation/about.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
TODO about: bit-manipulation
# 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
Loading

0 comments on commit f932cb5

Please sign in to comment.