Debugging tips and tricks
printLn(toString(...)) to query variables on the command line and in the
In a live environment, the `etch` compiler will strip out `printLn()` statements.
Our compiler is very strict. It will complain about:
- Unknown and unsupported symbols, operators, and indexes.
- Lack of types for variables and parameters.
nullto primitive types.
- Incorrect, incompatible, and uninferrable types in statements and functions.
- Duplicate variables, parameters, and functions.
- Incomparable types in boolean tests.
- Unmatched and unexpected beginnings, middles, and endings in selections, iterations, statements, and blocks.
- Incorrectly formed statements.
- Incorrect amount, or lack of, operands in boolean tests.
- Non-functions, unmatched functions, and functions that do not return a value.
- Local function definitions.
nullor no value from functions.
- Attempts to construct primitives and unmatched constructors.
- Mismatches between type and instance functions.
- Member access support issues with dot operator.
continue, variables, and expressions declared at topmost scope.
System.Argv() give access to compiler argument count and values. The following code prints the number of compiler arguments, then lists their values.
function main() var message : String; printLn("System args: " + toString(System.Argc())); // print the argument values for(i in 0:System.Argc()) message = toString(i) + " = " + System.Argv(i); printLn(message); endfor endfunction
Running the code from the command line with zero flags
-- sends arguments to the
For example, run the code snippet above with zero flags
-- and an example argument
hello like this:
./etch sysargs-examples.etch -- hello
You should see the following output:
F E ╱ etch v0.1.0-30-g557389e0 T C Copyright 2018-2019 (c) Fetch AI Ltd. H System args: 2 0 = ./etch 1 = hello
etch features like this are useful for experimentation and debugging in a development environment. For example, the system arguments can load machine learning training data into a script.
For smart contracts, there are flags, such as
-data, which do specific things. We explain coding, compiling, contract flags, and all about
etch smart contracts here.