Table of contents
echo, the smart print()
In our Hello world example we had to print a text, and we used the echo
identifier, that is automatically imported (and it’s part of the system module).
echo
will automatically convert the arguments to string, and will add a new line at the end. In the following example we print strings (surrounded by double quotes), a string variable, an integer (returned from the len()
function) and even a sequence (list):
var
package = "samtools"
versions = @[0.19, 1.0, 1.4]
echo "We have ", len(versions), " versions of ", package, ": ", versions
The output would be:
We have 3 versions of samtools: @[0.19, 1.0, 1.4]
Converting to string
The $
operator will convert to string it’s operand. echo
effectively uses this operator when receiving its typed arguments (in other words, trying to print a type that does not have an overloaded $
will fail).
In the following example we use the concatenation operator (&
, see strings) and the conversion to string to produce to produce a string, called packageString, having as content “samtools 0.19”:
var
package = "samtools"
versions = @[0.19, 1.0, 1.4]
packageString = package & " " & $versions[0]
echo packageString
Print to standard error and standard output
stdout.writeLine
and stderr.writeLine
will print, respectively, to the standard output and to the standard error. They will not add a newline.