Skip to content

Commit

Permalink
Merge pull request #399 from dictu-lang/develop
Browse files Browse the repository at this point in the history
Release 0.18.0
  • Loading branch information
Jason2605 authored Apr 7, 2021
2 parents ed73c0e + 1bb4c4d commit ccb121d
Show file tree
Hide file tree
Showing 53 changed files with 704 additions and 230 deletions.
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Dictu

*What is Dictu?*
Dictu is a very simple dynamically typed programming language
built upon the [craftinginterpreters tutorial](http://www.craftinginterpreters.com/contents.html).
*What is Dictu?*

Dictu is a high-level dynamically typed, multi-paradigm, interpreted programming language. Dictu has a very familiar
C-style syntax along with taking inspiration from the family of languages surrounding it, such as Python and JavaScript.

*What does Dictu mean?*

*What does Dictu mean?*
Dictu means `simplistic` in Latin.

### Dictu documentation
Expand All @@ -13,6 +15,39 @@ Documentation for Dictu can be found [here](https://dictu-lang.com/)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ab84059049bd4ba7b7b8c1fcfaac4ea5)](https://app.codacy.com/manual/jasonhall96686/Dictu?utm_source=github.com&utm_medium=referral&utm_content=Jason2605/Dictu&utm_campaign=Badge_Grade_Dashboard)
[![CI](https://github.com/Jason2605/Dictu/workflows/CI/badge.svg)](https://github.com/Jason2605/Dictu/actions)

## Example programs
```js
const guess = 10;

while {
const userInput = input("Input your guess: ").toNumber().unwrap();
if (userInput == guess) {
print("Well done!");
break;
} else if (userInput < guess) {
print("Too low!");
} else {
print("Too high!");
}

System.sleep(1);
}
```

```js
def fibonacci(num) {
if (num < 2) {
return num;
}

return fibonacci(num - 2) + fibonacci(num - 1);
}

print(fibonacci(10));
```

More [here.](https://github.com/Jason2605/Dictu/tree/develop/examples)

## Running Dictu
Dictu requires that you have CMake installed and it is at least version 3.16.3.

Expand Down Expand Up @@ -54,25 +89,11 @@ $ ./build/Dictu

Refer to [Dictu Docker](https://github.com/dictu-lang/Dictu/blob/develop/Docker/README.md)

## Extensions

## Example program
```js
var userInput;
var guess = 10;
Dictu has a Visual Studio Code extension [here](https://marketplace.visualstudio.com/items?itemName=Dictu.dictuvsc) with the implementation located
in the [DictuVSC repo](https://github.com/dictu-lang/DictuVSC).

while {
userInput = input("Input your guess: ").toNumber().unwrap();
if (userInput == guess) {
print("Well done!");
break;
} else if (userInput < guess) {
print("Too low!");
} else {
print("Too high!");
}
## Credits

System.sleep(1);
}
```

More [here.](https://github.com/Jason2605/Dictu/tree/develop/examples)
This language was initially based on the very good [craftinginterpreters book](http://www.craftinginterpreters.com/contents.html), along with inspiration from [Wren](https://github.com/wren-lang/wren).
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.17.0"
version: "0.18.0"
github_username: dictu-lang
search_enabled: true

Expand Down
23 changes: 23 additions & 0 deletions docs/docs/collections/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ myList.pop(0); // 1
print(myList); // [2]
```

### list.reverse()

To reverse a list we use `.reverse()`, this will reverse a list *in-place* (modifying the list) rather than generating a new list.

```cs
const myList = [1, 2, 3, 4];
myList.reverse();

print(myList); // [4, 3, 2, 1]
```

### Copying lists
#### list.copy()

Expand Down Expand Up @@ -272,4 +283,16 @@ By default the initial value for `.reduce()` is 0, however we can change this to

```cs
print(["Dictu ", "is", " great!"].reduce(def (accumulate, element) => accumulate + element, "")); // 'Dictu is great!'
```

### list.find(func)

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.

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

```cs
print([1, 2, 3].find(def (item) => item == 2)); // 2
```
43 changes: 43 additions & 0 deletions docs/docs/enum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
layout: default
title: Enums
nav_order: 10
---

# Enums
{: .no_toc }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

---

## 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.

```cs
enum Test {
a = 0,
b = 1,
c = 2
}

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

Enums in Dictu also do not care about the value being stored within the enum, so
if you wanted to create a heterogeneous enum, Dictu will not stop you.

```cs
enum HeterogeneousEnum {
a = 0,
b = "string",
c = def () => 10
}
```
2 changes: 1 addition & 1 deletion docs/docs/error-handling.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Error Handling
nav_order: 12
nav_order: 14
---

# Error Handling
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/files.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Files
nav_order: 10
nav_order: 11
---

# Files
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/modules.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Modules
nav_order: 11
nav_order: 12
---

# Modules
Expand Down
34 changes: 32 additions & 2 deletions docs/docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ nav_order: 6
---

# Operators
{: .no_toc }

## Table of contents
{: .no_toc .text-delta }

1. TOC
{:toc}

---
## Operators

| Operator | Description | Example |
|:-------------|:---------------------------------------------------------------|:---------------------------|
Expand All @@ -30,7 +40,7 @@ nav_order: 6
| ? | Ternary operator - See below | true ? 'value' : 'other' |
| ?. | Optional chaining - See [classes](/docs/classes/#optional-chaining) | object?.someMethod() |

## Ternary Operator
### Ternary Operator

The ternary operator is an operator which takes 3 operands and returns either the second or third depending on whether the first operand is truthy.

Expand All @@ -40,4 +50,24 @@ print(value); // 'true!'
var otherValue = 0 ? 'true!' : 'false!';
print(otherValue); // 'false!'
```
```

## Precedence

Precedence table from highest to lowest, with all operators having a left-to-right associativity.

| Operators |
| . () [] |
| ?. |
| ! - |
| \*\* |
| * / |
| \+ \- |
| & |
| ^ |
| \| |
| < > <= >= |
| == != |
| and |
| or |
| \= |
2 changes: 1 addition & 1 deletion docs/docs/standard-lib.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: default
title: Standard Library
nav_order: 13
nav_order: 15
has_children: true
---

Expand Down
12 changes: 7 additions & 5 deletions docs/docs/standard-lib/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,34 @@ To make use of the HTTP module an import is required.
import HTTP;
```

### HTTP.get(string, number: timeout -> optional)
### HTTP.get(string, list: headers -> optional, number: timeout -> optional)

Sends a HTTP GET request to a given URL. Timeout is given in seconds.
Returns a Result and unwraps to a dictionary upon success.

```cs
HTTP.get("https://httpbin.org/get");
HTTP.get("https://httpbin.org/get", 1);
HTTP.get("https://httpbin.org/get", ["Content-Type: application/json"]);
HTTP.get("https://httpbin.org/get", ["Content-Type: application/json"], 1);

{"content": "...", "headers": ["...", "..."], "statusCode": 200}
```

### HTTP.post(string, dictionary: postArgs -> optional, number: timeout -> optional)
### HTTP.post(string, dictionary: postArgs -> optional, list: headers -> optional, number: timeout -> optional)

Sends a HTTP POST request to a given URL.Timeout is given in seconds.
Returns a Result and unwraps to a dictionary upon success.

```cs
HTTP.post("https://httpbin.org/post");
HTTP.post("https://httpbin.org/post", {"test": 10});
HTTP.post("https://httpbin.org/post", {"test": 10}, 1);
HTTP.post("https://httpbin.org/post", {"test": 10}, ["Content-Type: application/json"]);
HTTP.post("https://httpbin.org/post", {"test": 10}, ["Content-Type: application/json"], 1);
```

### Response

Both HTTP.get() and HTTP.post() return a dictionary, or nil on error.
Both HTTP.get() and HTTP.post() return a Result that unwraps a dictionary on success, or nil on error.
The dictionary returned has 3 keys, "content", "headers" and "statusCode". "content" is the actual content returned from the
HTTP request as a string, "headers" is a list of all the response headers and "statusCode" is a number denoting the status code from
the response
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/standard-lib/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Math.min([1, 2, 3]); // 1
Return the largest number within the iterable

```cs
Math.min(1, 2, 3); // 3
Math.min([1, 2, 3]); // 3
Math.max(1, 2, 3); // 3
Math.max([1, 2, 3]); // 3
```

### Math.average(iterable)
Expand Down
18 changes: 9 additions & 9 deletions docs/docs/standard-lib/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ import Path;

### Path.basename(string)

Returns the basename of string.
Returns the basename of the path.

```cs
Path.basename("/usr/bin"); // 'bin'
```

### Path.dirname(string)

Returns the directory name of string.
Returns the directory name of the path.

```cs
Path.dirname("/usr/bin"); // '/usr'
```

### Path.extname(string)

Returns the extension portion of string, including the dot.
Returns the extension portion of the path, including the dot.

```cs
Path.extname("/tmp/t.ext"); // '.ext'
Expand All @@ -58,7 +58,7 @@ Path.extname("/tmp/t"); // ''

### Path.isAbsolute(string)

Returns true if string is an absolute path or false otherwise.
Returns true if path is absolute, false otherwise.

```cs
Path.isAbsolute("/usr"); // true
Expand All @@ -83,22 +83,22 @@ Returns a boolean whether a file exists at a given path.
Path.exists("some/path/to/a/file.du"); // true
```

### Path.isdir(string)
### Path.isDir(string)

Checks whether a given path points to a directory or not.

**Note:** This is not available on windows systems yet.
**Note:** This is not available on windows systems.

```cs
Path.isdir("/usr/bin/"); //true
Path.isDir("/usr/bin/"); //true
```

### Path.listdir(string)
### Path.listDir(string)

Returns a list of strings containing the contents of the input path.

**Note:** This function does not guarantee any ordering of the returned list.

```js
Path.listdir("/"); // ["bin", "dev", "home", "lib", ...]
Path.listDir("/"); // ["bin", "dev", "home", "lib", ...]
```
Loading

0 comments on commit ccb121d

Please sign in to comment.