Documentation Under maintenance.
- Quick tutorials
- Print values
- Variables / Objects / Values
- Read input
- Comments
- Functions
- Operators
- For
- If
- Libraries
- Counter Garbage-Collector *
- Macros & Pre-Preprocessor
- Error management
- Pseudo-Compilation
- Trust operator
- Runtime
- Stacktrace
- String library
- Namespaces
- Auto spacing
- Threads
Quick Tutorials
Hello, World!
'Hello, world!' -echoln
Place the code in a 'main.txt' file and run velid.exe in the cmd passing the main.txt file as paramether:
Print 10 times 'hello'
10 -for { 'hello' -echoln }
Print numbers from 0 to 9
10 -for { $it -echoln }
Calculate rectangle area
'Insert base: ' -echo *base base -read 'Insert height: ' -echo *height height -read base height -prod >> *area 'The area is ' area -echoln
Printing values
-echoln
Printing a value, a number or a variable (new line at the end):
'hello' -echoln
'this is a test ' 123 endl 'this was a new line' -echoln
this was a new line
-echo
Printing content (no new line at the end)
'orange' -echo 'banana' -echoln
Variables
Declaration
Declaring an empty variable called x
*x
Assignment
Declaration and flush (assignment) afterwards
*x
'simple value' >> x
x -echoln
Assignment with inline declaration
'foo' >> *x
x -echoln
Strings
'this string ' "and also this " "go at\nnew line" -echoln
new line
Escapes supported:
\n
\t
\'
\"
\`
Numbers
Numbers are supported as integer or decimal (max 15 dec places)
Decimal notation like 2. as 2.0 is supported
Objects
Objects are actually maps: key-value is required
'alfa' @a 'beta' @b >> *x
x -echoln
'alfa' @a
'beta' @b
>
To access sub objects just refer their name with a point. In the previous example, to access the a sub-object (of value 'alfa') inside x, just type:
x.a -echoln
If the element does not exist a undefined value is returned
Vectors
To vectorize a list of subjects, use the -v method
Vectors are actually maps, where the keys are indexes.
'alfa' 'beta' 'gamma' -v -echoln
To push a new element in a object as vector use the method -push :
*v
'alfa' @v -push
'beta' @v -push
v -echoln
Constants
TBA
References
Simple values (strings and numbers) are flushed by copy by default. Objects and Functors are flushed by reference by default.
All objects are passed by reference.
Structures
A variable can implement a structure. To declare a structure type just use functions (in velid functions = objects = structures = classes)
The symbol used is: ^
user: *username *password tokens: *list *timestamp :tokens :user *x ^userto access x's timestamp just write:
x.tokens.timestamp
Read input
Read user input
*x
x -read
Comments
Inline comment
Comment at the end of one line is marked with a semicolumn ;
'hello' -echoln ;this is a comment
Multiple line comment
Multiple line comment is marked with parenthesis ( )
'hello' -echoln (this
is a mutiple line
comment
Functions
Function implementation
To implement a function called 'foo':
foo:
'this is a function' -echoln
:foo
Function calling
To call a function just put an hyphen in front of the function name:
-foo
Function reference
To refer a function just use its name:
'example: ' foo -echoln
Nested function
Implementing a function inside a function is simple:
foo:
'this is foo' -echoln
faa:
'this is faa' -echoln
:faa
:foo
-foo ;calling foo
-foo.faa ;calling faa (which is inside foo)
Anonymous functions
{ 'test' -echoln } -exec
{ $0 -echoln } 'test' -exec
Operators
Default operator (??) (undefined fallback)
'beta' @b >> *x
x.a ?? "sorry 'a' does not exist" -echoln
Static Initialization (&)
To declare a variable "static" add & before the declaration.
& *x
To run soon after the build phase an instruction, add & before.
& 'alfa' >> *x
The variable x will be statically created, accessible only in the local environment and with the value 'alfa' since the beginning.
For
-for
Print 10 times 'hello'
10 -for { 'hello' -echoln }
Print numbers from 0 to 9
10 -for { 'Number: ' $it ' ' -echo }
If
-string.repeat
0 ? { 'this does not happen' -echoln }
1 ? { 'this happens' -echoln }
Libraries
Inclusion
Include a library to build it together with the main
'mylibrary.txt' #include
The library must containt the #filename token for the uuid of the library
#filename 'lib1'
Its content can be then accessible in the space 'lib1':
LIB1
#filename 'lib1'
foo:
'this is foo' -echoln
:foo
main.txt
'mylibrary.txt' #include
-lib1
String Library
#include
'string.vld' #include
or to automatically add .vld extension:
'string' #include
#define
PI 3.1415
substitute in the current imported bundle all 'PI' tokens with '3.1415'
#grid #text
rearrange tokens with a transpostion after #grid, normal after #text
#grid 'alfa' 'beta' 'gamma' @a @b @c #text -echoln
#if #ifnot #endif
#if:foo
#ifnot:foo
#endif:foo
Error management
Trust Operator
The trust operator had a different meaning in the first releases of velid. Then it was deprecated. Now it has a new meaning: force the compiler to check the existence of an object during compilation.
x: & 'test' >> *a :x
In the compilation it is ensured that a already exist, and its not a dynamic object like in. Otherwise a compilation error is shown.
'test' @a >> *x
String Library
-string.repeat
Repeat a string n times
'alfa' @3 -string.repeat
Threads
To start a thread with the function foo:
<foo
To join a thread:
<foo >> *t t -join
Launch
To launch an external velid application:
'rootfile' -launch
To launch an external velid application as thread (in parallel):
'rootfile' <launch