1
0

Write README

This commit is contained in:
Jeff 2023-08-23 00:38:51 -04:00
parent e7e8c4f9e5
commit bca4bded1b

215
README.md
View File

@ -1,6 +1,22 @@
# Dust # Dust
Dust is a data-oriented programming language and interactive shell. The command-line interface can also be run as a singular command or it can run a file. Dust is minimal, easy to read and easy to learn by example. Your code will always do exactly what it looks like it's going to do. <!--toc:start-->
- [Dust](#dust)
- [Features](#features)
- [Usage](#usage)
- [Installation](#installation)
- [The Dust Programming Language](#the-dust-programming-language)
- [Variables and Data Types](#variables-and-data-types)
- [Commands](#commands)
- [Lists](#lists)
- [Maps](#maps)
- [Tables](#tables)
- [The Yield Operator](#the-yield-operator)
- [Functions](#functions)
- [Time](#time)
<!--toc:end-->
Dust is a data-oriented programming language and interactive shell. Dust can be used as a replacement for a traditional command line shell, as a scripting language and as a tool create or manage data. Dust is expression-based, has first-class functions, lexical scope and lightweight syntax.
A basic dust program: A basic dust program:
@ -8,107 +24,33 @@ A basic dust program:
output "Hello world!" output "Hello world!"
``` ```
Dust can do two things at the same time: Dust can do two (or more) things at the same time with effortless concurrency:
```dust ```dust
async ( run(
'output "will this one finish first?"', 'output "will this one finish first?"',
'output "or will this one?"' 'output "or will this one?"'
) )
``` ```
Display CSV data as a line plot in a GUI window: Dust can do amazing things with data. To load CSV data, isolate a column and render it as a line plot in a GUI window:
```dust ```dust
read("examples/assets/faithful.csv") read("examples/assets/faithful.csv")
-> from_csv(input) -> from_csv(input)
-> get_rows(input) -> get_rows(input)
-> transform(input, 'input:get(1)') -> transform(input, 'input.1')
-> plot(input) -> plot(input)
``` ```
## Features ## Features
### Data Visualization - Data visualization: GUI (not TUI) plots, graphs and charts are available from directly within dust. No external tools are needed.
- Powerful tooling: Built-in commands reduce complex tasks to plain, simple code. You can even partition disks or install software.
Aside from downloading and processing data, dust is able to display it. Unfortunately the command line is a text interface that struggles to render data in the form of charts and graphs. That's why dust is able to instantly spin up GUI windows with beautifully rendered data. Plots, graphs and charts are available from directly within dust. No external tools are needed. - Pipelines: Like a pipe in bash, dust features the yield `->` operator.
- Format conversion: Effortlessly convert between dust and formats like JSON, CSV and TOML.
[bar_graph_demo.webm](https://github.com/solaeus/whale/assets/112188538/deba6e3c-35d4-47e9-9db9-2045ff2e7c9c) - Structured data: Dust can represent data with more than just strings. Lists, maps and tables are easy to make and manage.
- Developer tools: Dust has a complete tree sitter grammar, allowing syntax highlighting and completion in most code editors.
### Powerful Tooling
Built-in tools called **macros** reduce complex tasks to plain, simple code.
```whale
download "https://api.sampleapis.com/futurama/cast"
```
### Pipelines
Like a pipe in bash, zsh or fish, the yield operator `->` evaluates the expression on the left and passes it as input to the expression on the right. That input is always assigned to the **`input` variable** for that context. These expressions may simply contain a value or they can call a macro or function that returns a value.
```whale
download "https://api.sampleapis.com/futurama/cast" -> output(input)
```
### Format conversion
Effortlessly convert between whale and formats like JSON, CSV and TOML.
```whale
download "https://api.sampleapis.com/futurama/cast"
-> from_json(input)
-> to_csv(input)
```
### Structured data
Unlike a traditional command line shell, whale can represent data with more than just strings. Lists, maps and tables are everywhere in whale. When you pull in external data, it is easy to deserialize it into whale.
```whale
download "https://api.sampleapis.com/futurama/cast"
-> input:from_json()
-> input:get(0)
-> input.name
```
### Disk Management
Whale scripts are clear and easy-to-maintain. You can manage disks with sets of key-value pairs instead of remembering positional arguments.
```
new_disk.name = "My Files"
new_disk.filesystem = "btrfs";
new_disk.path = "/dev/sdb";
new_disk.label = "gpt";
new_disk.range = (0, 8000);
new_disk:partition();
```
### First-Class Functions
Assign custom functions to variables. Functions can return any value or none at all. Use functions to build structured data or automate tasks.
```whale
User = '
this.name = input.0;
this.age = input.1;
this
';
user_0 = User("bob", "44");
user_1 = User("mary", "77");
```
This "fetch" function will download JSON data and parse it.
```
fetch = '
raw_data = download(input);
from_json(raw_data)
';
```
## Usage ## Usage
@ -118,9 +60,11 @@ Dust is an experimental project under active development. At this stage, feature
You must have the default rust toolchain installed and up-to-date. Clone the repository and run `cargo run` to start the interactive shell. To see other command line options, use `cargo run -- --help`. You must have the default rust toolchain installed and up-to-date. Clone the repository and run `cargo run` to start the interactive shell. To see other command line options, use `cargo run -- --help`.
## The Whale Programming Language ## The Dust Programming Language
Dust is a hard fork of [evalexpr]; a simple expression language. Dust's core language features maintain this simplicity. But it can manage large, complex sets of data and perform complicated tasks through macros. It should not take long for a new user to learn the language, especially with the assistance of the shell. Dust is a hard fork of [evalexpr]; a simple expression language. Dust's core language features maintain this simplicity. But it can manage large, complex sets of data and perform complicated tasks through commands. It should not take long for a new user to learn the language, especially with the assistance of the shell.
If your editor supports tree sitter, you can use [tree-sitter-dust] for syntax highlighting and completion support.
### Variables and Data Types ### Variables and Data Types
@ -139,49 +83,47 @@ Variables have two parts: a key and a value. The key is always a text string. Th
Here are some examples of variables in dust. Here are some examples of variables in dust.
```whale ```dust
x = 1; string = "The answer is 42.";
y = "hello, it is " + now().time; integer = 42;
z = "42.42"; float = 42.42;
list = (1, 2, string, integer, float);
list = (3, 2, x); map.key = "value";
big_list = (x, y, z, list) empty = ();
map.x = "foobar";
function = 'output "I'm a function"';
``` ```
### Macros ### Commands
**Macros** are dust's built-in tools. Some of them can reconfigure your whole system while others are do very little. They may accept different inputs, or none at all. Macros in the `random` group can be run without input, but the `random_integer` macro can optionally take two numbers as in inclusive range. **Commands** are dust's built-in tools. Some of them can reconfigure your whole system while others are do very little. They may accept different inputs, or none at all. commands in the `random` group can be run without input, but the `random_integer` command can optionally take two numbers as in inclusive range.
```whale ```dust
die_roll = random_integer(1, 6); die_roll = random_integer(1, 6);
d20_roll = random_integer(1, 20); d20_roll = random_integer(1, 20);
coin_flip = random_boolean(); coin_flip = random_boolean();
``` ```
Other macros can be found by pressing TAB in the interactive shell. Other commands can be found by pressing TAB in the interactive shell.
```whale ```dust
message = "I hate dust."; message = "I hate dust.";
replace(message, "hate", "love"); replace(message, "hate", "love");
``` ```
### Lists ### Lists
Lists are sequential collections. They can be built by grouping values with parentheses and separating them with commas. Values can be indexed by their position to access their contents. Lists are used to represent rows in tables and most macros take a list as an argument. Lists are sequential collections. They can be built by grouping values with parentheses and separating them with commas. Values can be indexed by their position to access their contents. Lists are used to represent rows in tables and most commands take a list as an argument.
```whale ```dust
list = (true, 42, "Ok"); list = (true, 42, "Ok");
assert_eq(get(list, 0), true); assert_eq(list.0, true);
``` ```
### Maps ### Maps
Maps are flexible collections with arbitrary key-value pairs, similar to JSON objects. Under the hood, all of dust's runtime variables are stored in a map, so, as with variables, the key is always a string. Maps are flexible collections with arbitrary key-value pairs, similar to JSON objects. Under the hood, all of dust's runtime variables are stored in a map, so, as with variables, the key is always a string.
```whale ```dust
reminder.message = "Buy milk"; reminder.message = "Buy milk";
reminder.tags = ("groceries", "home"); reminder.tags = ("groceries", "home");
@ -191,42 +133,53 @@ append_to_file(json, "info.txt");
### Tables ### Tables
Tables are strict collections, each row must have a value for each column. Empty cells must be explicitly set to an empty value. Querying a table is similar to SQL. Tables are strict collections, each row must have a value for each column. Empty cells must be explicitly set to an empty value.
```whale ```dust
animals.all = create_table ( animals = create_table (
("name", "species", "age"), ("name", "species", "age"),
("rover", "cat", 14), (
("spot", "snake", 9), ("rover", "cat", 14),
("bob", "giraffe", 2), ("spot", "snake", 9),
("bob", "giraffe", 2),
)
); );
``` ```
The macros `create_table` and `insert` make sure that all of the memory used to hold the rows is allocated at once, so it is good practice to group your rows together instead of using a call for each row. Querying a table is similar to SQL.
```whale ```dust
animals.all:insert( names = select(animals, "name");
youngins = where(animals, 'age < 5');
old_species = select_where(animals, "species", 'age > 5')
```
The commands `create_table` and `insert` make sure that all of the memory used to hold the rows is allocated at once, so it is good practice to group your rows together instead of using a call for each row.
```dust
insert(
animals,
("eliza", "ostrich", 4), ("eliza", "ostrich", 4),
("pat", "white rhino", 7), ("pat", "white rhino", 7),
("jim", "walrus", 9) ("jim", "walrus", 9)
); );
assert_eq(animals:length(), 6); assert_eq(length(animals.all), 6);
animals.by_name = animals:sort_by("name"); animals.by_name = sort_by(animals.all, "name");
``` ```
### The Yield Operator ### The Yield Operator
Like a pipe in bash, zsh or fish, the yield operator evaluates the expression on the left and passes it as input to the expression on the right. That input is always assigned to the **`input` variable** for that context. These expressions may simply contain a value or they can call a macro or function that returns a value. Like a pipe in bash, zsh or fish, the yield operator evaluates the expression on the left and passes it as input to the expression on the right. That input is always assigned to the **`input` variable** for that context. These expressions may simply contain a value or they can call a command or function that returns a value.
```whale ```dust
"Hello dust!" -> output(input) "Hello dust!" -> output(input)
``` ```
This can be useful when working on the command line but to make a script easier to read or to avoid fetching the same resource multiple times, we can also declare variables. You should use `->` and variables together to write short, elegant scripts. This can be useful when working on the command line but to make a script easier to read or to avoid fetching the same resource multiple times, we can also declare variables. You should use `->` and variables together to write efficient, elegant scripts.
```whale ```dust
json = download("https://api.sampleapis.com/futurama/characters"); json = download("https://api.sampleapis.com/futurama/characters");
from_json(json) from_json(json)
-> select(input, "name"); -> select(input, "name");
@ -235,28 +188,28 @@ from_json(json)
### Functions ### Functions
Functions are first-class values in dust, so they are assigned to variables like any other value. The function body is wrapped in single parentheses. To call a function, it's just like calling a macro: simply pass it an argument or use an empty set of parentheses to pass an empty value. Functions are first-class values in dust, so they are assigned to variables like any other value. The function body is wrapped in single parentheses. To call a function, it's just like calling a command: simply pass it an argument or use an empty set of parentheses to pass an empty value.
In the function bod, the **`input` variable** represents whatever value is passed to the function when called. In the function bod, the **`input` variable** represents whatever value is passed to the function when called.
```whale ```dust
say_hi = 'output "hi"'; say_hi = 'output "hi"';
add_one = 'input + 1'; add_one = 'input + 1';
assert_eq(add_one(3), 4);
say_hi(); say_hi();
assert_eq(add_one(3), 4);
``` ```
This function simply passes the input to the shell's standard output. This function simply passes the input to the shell's standard output.
```whale ```dust
print = 'output(input)'; print = 'output(input)';
``` ```
Because functions are stored in variables, we can use collections like maps to Because functions are stored in variables, we can use collections like maps to
organize them. organize them.
```whale ```dust
math.add = 'input.0 + input.1'; math.add = 'input.0 + input.1';
math.subtract = 'input.0 - input.1'; math.subtract = 'input.0 - input.1';
@ -266,20 +219,20 @@ assert_eq(math.subtract(100, 1), 99);
### Time ### Time
Whale can record, parse and convert time values. Whale can parse TOML datetime Dust can record, parse and convert time values. Dust can parse TOML datetime
values or can create time values using macros. values or can create time values using commands.
```whale ```dust
dob = from_toml("1979-05-27T07:32:00-08:00") dob = from_toml("1979-05-27T07:32:00-08:00")
output "Date of birth = " + local(dob); output "Date of birth = " + local(dob);
``` ```
```whale ```dust
time = now(); time = now();
output "Universal time is " + time:utc(); output "Universal time is " + utc(time);
output "Local time is " + time:local(); output "Local time is " + local(time);
``` ```
[dnf]: https://dnf.readthedocs.io/en/latest/index.html [dnf]: https://dnf.readthedocs.io/en/latest/index.html