Skip to content

Commit

Permalink
Merge pull request #478 from dictu-lang/develop
Browse files Browse the repository at this point in the history
Release 0.22.0
  • Loading branch information
Jason2605 committed Oct 24, 2021
2 parents 82da2ce + b0df3b9 commit 1195662
Show file tree
Hide file tree
Showing 71 changed files with 661 additions and 89 deletions.
26 changes: 10 additions & 16 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,19 @@

<!-- Explain what you have done !-->

I worked on the .....

#

### Context of the change :

<!-- Make sure to answer to these questions !-->

- Why is this change required ?

<!-- Link the issue below if you are resolving an issue !-->

- Does it solve a problem ? (please link the issue)
Resolves:

#

### Type of change :
### Type of change:

<!-- Please select relevant options -->

<!-- add a x in [ ] if true !-->
<!-- Add an x in [ ] if true !-->

<!-- Delete options that aren't relevant!-->

Expand All @@ -43,11 +35,13 @@

#

### Preview (Screenshots) :
### Housekeeping

<!-- If adding a new test file, remember to include it in the relevant import file -->
- [ ] Tests have been updated to reflect the changes done within this PR (if applicable).

<!-- While providing screenshots, delete the text below !-->
- [ ] Documentation has been updated to reflect the changes done within this PR (if applicable).

<!-- try as much as possible to explain each change in each screenshot !-->
### Preview (Screenshots) :

<p align="center">If it is possible, please link screenshots of your changes preview !
</p>
<!-- If applicable attempt to explain the screenshots !-->
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
cmake -DCMAKE_BUILD_TYPE=Debug -DDISABLE_HTTP=1 -B ./build
cmake --build ./build
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total memory usage: 0'
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total bytes lost: 0'
- name: Remove build directory
run: |
rm -rf build
Expand All @@ -30,7 +30,7 @@ jobs:
sudo apt-get install -y libcurl4-openssl-dev
cmake -DCMAKE_BUILD_TYPE=Debug -B ./build
cmake --build ./build
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total memory usage: 0'
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total bytes lost: 0'
test-mac-cmake:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -44,15 +44,15 @@ jobs:
run: |
cmake -DCMAKE_BUILD_TYPE=Debug -DDISABLE_HTTP=1 -B ./build
cmake --build ./build
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total memory usage: 0'
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total bytes lost: 0'
- name: Remove build directory
run: |
rm -rf build
- name: Make dictu and run tests
run: |
cmake -DCMAKE_BUILD_TYPE=Debug -B ./build
cmake --build ./build
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total memory usage: 0'
./dictu tests/runTests.du | tee /dev/stderr | grep -q 'Total bytes lost: 0'
test-windows-cmake:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -78,4 +78,4 @@ jobs:
sudo apt-get install -y libcurl4-openssl-dev
cmake -DCMAKE_BUILD_TYPE=Debug -B ./build
cmake --build ./build
./dictu examples/runExamples.du | tee /dev/stderr | grep -q 'Total memory usage: 0'
./dictu examples/runExamples.du | tee /dev/stderr | grep -q 'Total bytes lost: 0'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Documentation for Dictu can be found [here](https://dictu-lang.com/)

## Example programs
```js
import System;

const guess = 10;

while {
Expand Down
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
color_scheme: "dictu" # Custom theme
logo: "/assets/images/dictu-logo/dictu-wordmark.svg"

version: "0.21.0"
version: "0.22.0"
github_username: dictu-lang
search_enabled: true

Expand Down
22 changes: 22 additions & 0 deletions docs/docs/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ print(TestOverload().toString()); // 'Testing object'
```

### methods

Sometimes we need to programmatically access methods that are stored within a class, this can be aided through the use of `.methods()`. This
will return a list of strings, where the strings are the names of all public methods stored within a class.

Note: The order of the list is not the same order the methods are defined.

```cs
class Test {
init() {

}

someOther() {

}
}

print(Test.methods()); // ["someOther", "init"]
print(Test().methods()); // Works on instances too - ["someOther", "init"]
```

## This

`this` is a variable which is passed to all methods which are not marked as static. `this` is a reference to the object you are currently accessing. `this` allows you to modify instance variables of a particular object.
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/collections/dictionaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,19 @@ const myDict = {"key": 1, "key1": 2};
myDict.forEach(def (key, value) => {
print("Key: {} Value: {}".format(key, value));
});
```

### dict.merge(anotherDict)

To merge two dicts together we use `.merge`. This operation will take a shallow copy of the dict the `.merge` method
was called on and add any items from the dictionary passed into the method. If there are keys that exist in both dictionaries
the value from the passed in dictionary is the one that will be used.

```cs
const dictOne = {"key": 1, "key1": 2, "key2": 3};
const dictTwo = {"key3": 4,"key1":0};

const mergedDict = dictOne.merge(dictTwo);

mergedDict; //{"key2": 3, "key": 1, "key3": 4, "key1": 0}
```
20 changes: 18 additions & 2 deletions docs/docs/collections/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,30 @@ By default the initial value for `.reduce()` is 0, however we can change this to
print(["Dictu ", "is", " great!"].reduce(def (accumulate, element) => accumulate + element, "")); // 'Dictu is great!'
```

### list.find(func)
### list.find(func, number: start -> optional, number: end -> optional)

To find a single item within a list we use `.find()`. Find will search through each item in the list and as soon as the
callback returns a truthy value, the item that satisfied the callback is returned, if none of the items satisfy the callback
function then `nil` is returned.
function then `nil` is returned. The optional start and end parameters change the points at which the list will be searched.

Note: The first item to satisfy the callback is returned.

```cs
print([1, 2, 3].find(def (item) => item == 2)); // 2
print([1, 2, 3, 4, 5, 6].find(def (item) => item % 2 == 0, 2)); // 4
print([1, 2, 3, 4, 5, 6].find(def (item) => item % 2 == 0, 2, 3)); // nil
```

### list.findIndex(func, number: start -> optional, number: end -> optional)

To find a single item within a list we use `.findIndex()`. Find will search through each item in the list and as soon as the
callback returns a truthy value, the index at which the item that satisfied the callback is returned, if none of the items satisfy the callback
function then `nil` is returned. The optional start and end parameters change the points at which the list will be searched.

Note: The first item to satisfy the callback is returned.

```cs
print([1, 2, 3].findIndex(def (item) => item == 2)); // 1
print([1, 2, 3, 4, 5, 6].findIndex(def (item) => item % 2 == 0, 2)); // 3
print([1, 2, 3, 4, 5, 6].findIndex(def (item) => item % 2 == 0, 2, 3)); // nil
```
8 changes: 4 additions & 4 deletions docs/docs/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (x == 6) {
var i = 0;
while (i < 10) {
print(i);
++i;
i += 1;
}
```

Expand All @@ -68,7 +68,7 @@ while {

```cs
// For loop
for (var i = 0; i < 10; ++i) {
for (var i = 0; i < 10; i += 1) {
print(i);
}
```
Expand All @@ -79,7 +79,7 @@ Continue allows execution of a loop to restart prematurely.

```cs
// For loop
for (var i = 0; i < 10; ++i) {
for (var i = 0; i < 10; i += 1) {
if (i % 2 == 0)
continue; // Skip all even numbers
Expand All @@ -93,7 +93,7 @@ Break allows execution of a loop to stop prematurely.

```cs
// For loop
for (var i = 0; i < 10; ++i) {
for (var i = 0; i < 10; i += 1) {
if (i > 5)
break; // Exit the loop here
Expand Down
21 changes: 15 additions & 6 deletions docs/docs/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,26 @@ nav_order: 10
## Enums

Enums are a collection of constants which can be accessed via a name rather than
an index to document intent. Unlike other languages, enums in Dictu must be assigned
to a value when declaring the enum and no automatic value will be generated.
an index to document intent. Unlike other languages, enums in Dictu do not generate a value
based on the previous entry, instead if no value is assigned it will be given it's position
within the enum, 0-based, as a value.

```cs
enum MyEnum {
a, // 0
b, // 1
c // 2
}

print(MyEnum.a); // 0
enum Test {
a = 0,
b = 1,
c = 2
a = 10, // 10
b, // 1
c // 2
}

print(Test.a); // 0
print(Test.a); // 10
```

Enums in Dictu also do not care about the value being stored within the enum, so
Expand Down
20 changes: 19 additions & 1 deletion docs/docs/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,22 @@ var number = "number".toNumber().match(
);

print(number);
```
```

### .matchWrap(func: success, func: error)

`.matchWrap` is exactly the same as `.wrap` however, the value returned from either callback
function is implicitly wrapped back up into a Result object. This allows us to easily deal
with the error at a different call site and avoids the necessity for explicit wrapping.

```cs
var response = HTTP.get("https://some/endpoint").matchWrap(
def (data) => JSON.parse(data).unwrap(),
def (error) => error
);

print(response); // <Result Suc>
```

In the above example we can handle the case that we need to do some data transformation, however, we
also need to ensure that a Result object is returned in case we hit the error callback.
5 changes: 4 additions & 1 deletion docs/docs/standard-lib/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ To make use of the Env module an import is required.
import Env;
```

### Env.get(string)
### Env.get(string, string: defaultValue -> optional)

Get an environment variable. `.get()` will return a string if a valid environment variable is found otherwise nil.

If default value is passed that will be returned if the specified environment variable could not be found.

```cs
Env.get("bad key!"); // nil
Env.get("valid key"); // "value"
Env.get("bad key!", "default value!!!"); // "default value!!!"
```

### Env.set(string, value)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/standard-lib/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Math;

| Constant | Description |
|--------------|--------------------------------------------------------|
| Math.PI | The mathematical constant: 3.14159265358979 |
| Math.pi | The mathematical constant: 3.14159265358979 |
| Math.e | The mathematical constant: 2.71828182845905 |

### Math.min(iterable)
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/standard-lib/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ parent: Standard Library
---

## System
To make use of the System module an import is required.

```js
import System;
```

### Constants

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ string[0]; // D
string[-1]; // u
string[100]; // String index out of bounds.
for (var i = 0; i < x.len(); ++i) {
for (var i = 0; i < x.len(); i += 1) {
print(string[i]);
}
// D
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ var amount = input("Enter a number: ").toNumber();
var num = 1;

if (amount > 0) {
for (var i = 1; i < amount + 1; ++i) {
for (var i = 1; i < amount + 1; i += 1) {
num *= i;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/design-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class DogHandler < BaseHandler {
def businessLogic(handler) {
var food = ["Nut", "Banana", "Coffee"];

for (var i = 0; i < food.len(); ++i) {
for (var i = 0; i < food.len(); i += 1) {
print("Who wants a: {}".format(food[i]));

var response = handler.handle(food[i]);
Expand Down Expand Up @@ -199,7 +199,7 @@ class Publisher {
* Notify all subscribed observers
*/
notify() {
for (var i = 0; i < this.observers.len(); ++i) {
for (var i = 0; i < this.observers.len(); i += 1) {
this.observers[i].update();
}
}
Expand Down
2 changes: 2 additions & 0 deletions examples/factorial.du
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import System;

var amount;

/**
Expand Down
1 change: 1 addition & 0 deletions examples/guessingGame.du
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Random;
import System;

const guess = 10;
var maxGuesses = 5;
Expand Down

0 comments on commit 1195662

Please sign in to comment.