etch language was initially integrated with the Fetch.AI C++ ledger project. It is designed to run on a number of platforms.
etch is inspired by Rust, C++, and Python, but it also has some idiosyncrasies.
etch language is extremely restrictive to avoid costly errors on the ledger. See Smart Contract section for more information.
etch is a statically typed language and static typing is enforced by the compiler.
Blocks of code require no delimiters. White space is ignored. Indentation is recommended.
You can extend and customise
etch in C++. We show you how to do that here.
Let's take a closer look at
Explicitly declare the type:
function main() var myvariable : String; endfunction
In some cases, type can be inferred:
function main() var myvariable = "hello"; endfunction
Assign a value like this:
function main() var myvariable : String = "hello"; endfunction
For multivariate types, all the types must be declared:
var multitype-variable-name : Type<Type<Type>>();
Not declaring the variable type and inferrable value results in a compilation error:
function main() var myVariable; endfunction Failed to compile. line 3: error at ';', expected ':' or '=' Failed to compile.
Initially, all our code snippets execute inside the
function main() // stuff endfunction
Here is a current list of
Both line and block comments are possible:
// a single comment inside a function /* ..lines of commented out stuff inside and outside functions */
etch code for smart contracts includes annotated functions. These are more like
Java method annotations and not at all like
@initis a constructor method that initialises the contract.
@actionis a function which defines transactions on the ledger that change state.
@queryis a function that allows you to query data residing on the ledger.
We tell you all about these functions in the section on smart contracts.