Updated readme
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
bb072ae434
commit
336313867d
|
@ -0,0 +1,101 @@
|
|||
|
||||
* Scripting
|
||||
** Everything is an expression
|
||||
Everything can be evaulated as an experession. This means variables can be set to if blocks, loops, or anything else;
|
||||
#+begin_src rust
|
||||
let x = if y == "test" { 1 } else { 2 };
|
||||
#+end_src
|
||||
|
||||
** Returning output
|
||||
Output is rendered based on the returned value of a block. The final value of the block is automatically returned. The return keyword is only needed if an early return is preferable.
|
||||
#+begin_src rust
|
||||
if x == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if x > 10 {
|
||||
// note the lack of a semicolon here
|
||||
x / 5
|
||||
} else {
|
||||
// note the lack of a semicolon here
|
||||
x / 10
|
||||
}
|
||||
#+end_src
|
||||
|
||||
|
||||
** Variables
|
||||
Variables can be assigned using the let keyword. Variables are dynamically typed and globally mutable:
|
||||
#+begin_src rust
|
||||
let pulse_rate = 0.8;
|
||||
let time = 3.2;
|
||||
|
||||
time / pulse_rate
|
||||
#+end_src
|
||||
|
||||
** Functions
|
||||
Functions can be defined using the fn keyword. Return types and arguments are dynamic and do not require typing.
|
||||
#+begin_src rust
|
||||
fn add_one(x) {
|
||||
x + 1;
|
||||
}
|
||||
|
||||
add_one(2)
|
||||
#+end_src
|
||||
|
||||
** Object maps
|
||||
Dictionary style data maps are possible and can be index or accessed by a property notation. Dictionaries are defined using a special syntax wrapper: #{}.
|
||||
#+begin_src rust
|
||||
let account = #{ first_name: "Alice", last_name: "Allison", balance: 150.32 };
|
||||
// Access via property notation
|
||||
account.balance += 10;
|
||||
// Access via indexing
|
||||
account["last_name"] = "Test";
|
||||
account
|
||||
#+end_src
|
||||
|
||||
** Series
|
||||
A series provides a powerful way to perform calculations on an array of data. Operations performedon the series are performed against all of its member values. Serieses are constructed using the series fucntion and passing an array of values.
|
||||
#+begin_src rust
|
||||
let s = series([1,2,3,4]);
|
||||
// Return an array of values calculated from the series
|
||||
[ s + 10, s * s ]
|
||||
#+end_src
|
||||
|
||||
** Dataframes
|
||||
Dataframes provide an object for working with tabular data made up of several series. Dataframes are initialzied using the dataframe constructor function and passing in an object map container name/array pairs.
|
||||
|
||||
Dataframe series can be accessed via indexing or property notation just like object maps.
|
||||
#+begin_src rust
|
||||
let df = dataframe(#{
|
||||
name: ["Alice", "Bob", "Charles"],
|
||||
rate: [18,20,20],
|
||||
hours: [22,40,55]
|
||||
});
|
||||
df.balance = df.rate * df.hours;
|
||||
df
|
||||
#+end_src
|
||||
|
||||
*** Filtering
|
||||
Dataframes are more powerful than object maps and can be filtered. Filtering requires two parts:
|
||||
|
||||
1. Selecting the columns to be included
|
||||
2. providing a predicate to filter a column's value
|
||||
|
||||
The filtering syntax is FROM <dataframe> <column array> : <array of predicates>
|
||||
|
||||
Predicates consist of a quoted name for the series/column an operator and a value. Valid operators are: gt, gte, lt, lte.
|
||||
|
||||
Filtering returns a new dataframe with the extracted values.
|
||||
|
||||
#+begin_src rust
|
||||
let df = dataframe(#{
|
||||
name: ["Alice", "Bob", "Charles"],
|
||||
rate: [18,20,20],
|
||||
hours: [22,40,55]
|
||||
});
|
||||
let high_rates = from df ["name", "rate", "hours"] : ["rate" gte 20];
|
||||
high_rates.balance = high_rates.rate * high_rates.hours;
|
||||
high_rates
|
||||
#+end_src
|
||||
|
||||
|
Loading…
Reference in New Issue