Write README
This commit is contained in:
parent
507082209f
commit
e57d3f6e60
77
README.md
77
README.md
@ -5,26 +5,26 @@ Dust is a general purpose programming language that emphasises concurrency and c
|
|||||||
A basic dust program:
|
A basic dust program:
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
(output "Hello world!")
|
output("Hello world!")
|
||||||
```
|
```
|
||||||
|
|
||||||
Dust can do two (or more) things at the same time with effortless concurrency:
|
Dust can do two (or more) things at the same time with effortless concurrency:
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
async {
|
async {
|
||||||
(output 'will this one finish first?')
|
output('will this one finish first?')
|
||||||
(output 'or will this one?')
|
output('or will this one?')
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can make *any* block, i.e. `{}`, run its statements in parallel by changing it to `async {}`.
|
You can make *any* block, i.e. `{}`, run its statements in parallel by changing it to `async {}`.
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
if (random_boolean) {
|
if random_boolean() {
|
||||||
(output "Do something...")
|
output("Do something...")
|
||||||
} else async {
|
} else async {
|
||||||
(output "Do something else instead...")
|
output("Do something else instead...")
|
||||||
(output "And another thing at the same time...")
|
output("And another thing at the same time...")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -43,6 +43,7 @@ Dust is an interpreted, strictly typed language with first class functions. It e
|
|||||||
- [Maps](#maps)
|
- [Maps](#maps)
|
||||||
- [Loops](#loops)
|
- [Loops](#loops)
|
||||||
- [Functions](#functions)
|
- [Functions](#functions)
|
||||||
|
- [Option](#option)
|
||||||
- [Concurrency](#concurrency)
|
- [Concurrency](#concurrency)
|
||||||
- [Acknowledgements](#acknowledgements)
|
- [Acknowledgements](#acknowledgements)
|
||||||
<!--toc:end-->
|
<!--toc:end-->
|
||||||
@ -61,7 +62,24 @@ Dust is an experimental project under active development. At this stage, feature
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
cargo install dust-lang
|
cargo install dust-lang
|
||||||
dust -c "(output 'Hello world!')"
|
dust -c "output('Hello world!')"
|
||||||
|
```
|
||||||
|
|
||||||
|
```txt
|
||||||
|
General purpose programming language
|
||||||
|
|
||||||
|
Usage: dust [OPTIONS] [PATH]
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
[PATH] Location of the file to run
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --command <COMMAND> Dust source code to evaluate
|
||||||
|
-i, --input <INPUT> Data to assign to the "input" variable
|
||||||
|
-p, --input-path <INPUT_PATH> A path to file whose contents will be assigned to the "input" variable
|
||||||
|
-t, --tree Show the syntax tree
|
||||||
|
-h, --help Print help
|
||||||
|
-V, --version Print version
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -159,7 +177,7 @@ Note that strings can be wrapped with any kind of quote: single, double or backt
|
|||||||
Dust enforces strict type checking, but you don't usually need to write the type, dust can figure it out on its own. The **number** and **any** types are special types that allow you to relax the type bounds.
|
Dust enforces strict type checking, but you don't usually need to write the type, dust can figure it out on its own. The **number** and **any** types are special types that allow you to relax the type bounds.
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
string <string> = "foobar"
|
string <str> = "foobar"
|
||||||
integer <int> = 42
|
integer <int> = 42
|
||||||
float <float> = 42.42
|
float <float> = 42.42
|
||||||
|
|
||||||
@ -175,12 +193,11 @@ Lists are sequential collections. They can be built by grouping values with squa
|
|||||||
```dust
|
```dust
|
||||||
list = [true 41 "Ok"]
|
list = [true 41 "Ok"]
|
||||||
|
|
||||||
(assert_equal list:0 true)
|
assert_equal(list:0 true)
|
||||||
|
|
||||||
the_answer = list:1 + 1
|
the_answer = list:1 + 1
|
||||||
|
|
||||||
(assert_equal the_answer, 42) # You can also use commas when passing values to
|
assert_equal(the_answer, 42) # You can use commas when passing values a function.
|
||||||
# a function.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Maps
|
### Maps
|
||||||
@ -193,7 +210,7 @@ reminder = {
|
|||||||
tags = ["groceries", "home"]
|
tags = ["groceries", "home"]
|
||||||
}
|
}
|
||||||
|
|
||||||
(output reminder:message)
|
output(reminder:message)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Loops
|
### Loops
|
||||||
@ -203,7 +220,7 @@ A **while** loop continues until a predicate is false.
|
|||||||
```dust
|
```dust
|
||||||
i = 0
|
i = 0
|
||||||
while i < 10 {
|
while i < 10 {
|
||||||
(output i)
|
output(i)
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -214,7 +231,7 @@ A **for** loop operates on a list without mutating it or the items inside. It do
|
|||||||
list = [ 1, 2, 3 ]
|
list = [ 1, 2, 3 ]
|
||||||
|
|
||||||
for number in list {
|
for number in list {
|
||||||
(output number + 1)
|
output(number + 1)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -224,8 +241,8 @@ Functions are first-class values in dust, so they are assigned to variables like
|
|||||||
|
|
||||||
```dust
|
```dust
|
||||||
# This simple function has no arguments and no return value.
|
# This simple function has no arguments and no return value.
|
||||||
say_hi = (fn) {
|
say_hi = () <none> {
|
||||||
(output "hi")
|
output("hi")
|
||||||
}
|
}
|
||||||
|
|
||||||
# This function has one argument and will return a value.
|
# This function has one argument and will return a value.
|
||||||
@ -233,25 +250,25 @@ add_one = (fn number <num>) <num> {
|
|||||||
number + 1
|
number + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
(say_hi)
|
say_hi()
|
||||||
(assert_equal (add_one 3), 4)
|
assert_equal(add_one(3), 4)
|
||||||
```
|
```
|
||||||
|
|
||||||
You don't need commas when listing arguments and you don't need to add whitespace inside the function body but doing so may make your code easier to read.
|
You don't need commas when listing arguments and you don't need to add whitespace inside the function body but doing so may make your code easier to read.
|
||||||
|
|
||||||
### Option
|
### Option
|
||||||
|
|
||||||
The **option** type represents a value that may not be present. It has two variants: **some** and **none**. Dust includes built-in functions to work with option values: `is_none`, `is_some` and `either_or`.
|
An **option** represents a value that may not be present. It has two variants: **some** and **none**. Dust includes built-in functions to work with option values: `is_none`, `is_some` and `either_or`.
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
say_something = (fn message <option(str)>) <str> {
|
say_something = (message <option(str)>) <str> {
|
||||||
(either_or message, "hiya")
|
either_or(message, "hiya")
|
||||||
}
|
}
|
||||||
|
|
||||||
(say_something some("goodbye"))
|
say_something(some("goodbye"))
|
||||||
# goodbye
|
# goodbye
|
||||||
|
|
||||||
(say_something none)
|
say_something(none)
|
||||||
# hiya
|
# hiya
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -262,20 +279,20 @@ Dust features effortless concurrency anywhere in your code. Any block of code ca
|
|||||||
```dust
|
```dust
|
||||||
# An async block will run each statement in its own thread.
|
# An async block will run each statement in its own thread.
|
||||||
async {
|
async {
|
||||||
(output (random_integer))
|
output(random_integer())
|
||||||
(output (random_float))
|
output(random_float())
|
||||||
(output (random_boolean))
|
output(random_boolean())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```dust
|
```dust
|
||||||
data = async {
|
data = async {
|
||||||
(output "Reading a file...")
|
output("Reading a file...")
|
||||||
(read "examples/assets/faithful.csv")
|
read("examples/assets/faithful.csv")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
Dust began as a fork of [evalexpr]. Some of the original code is still in place but the project has dramatically changed and no longer uses any of its parsing or interpreting.
|
Dust began as a fork of [evalexpr]. Some of the original code is still in place but the project has dramatically changed and no longer uses any of its parsing or interpreting.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user