Velid Documentation

Back to Home Page

velid Created by andrea sorato

Documentation Under maintenance.

Index
  1. Quick tutorials
    1. Hello, World!
    2. Print 10 times 'hello'
    3. Print numbers from 0 to 9
    4. Calculate rectangle area
  2. Print values
    1. -echoln
    2. -echo
  3. Variables / Objects / Values
    1. Declaration
    2. Assignment
    3. Assigment with declaration
    4. Strings
      1. Escapes
    5. Numbers
    6. Objects
    7. Vectors
    8. Constants
    9. References
    10. Structures
  4. Read input
  5. Comments
    1. Inline comments
    2. Multiple line comments
  6. Functions
    1. Function implementation
    2. Function calling
    3. Function reference
    4. Nested functions
    5. Anonymous functions
  7. Operators
    1. Default operator(??) (undefined fallback)
    2. Static initialization (&)
  8. For
  9. If
  10. Libraries
    1. Inclusion
    2. Import
  11. Counter Garbage-Collector *
    1. Functioning
  12. Macros & Pre-Preprocessor
    1. #include
    2. #filename
    3. #define
    4. #grid #text Layout
    5. #if #ifnot #endif
    6. #cite
  13. Error management
    1. Pseudo-Compilation
    2. Trust operator
    3. Runtime
    4. Stacktrace
  14. String library
    1. -string.repeat
    2. -string.serialize
  15. Namespaces
    1. Auto spacing
  16. Threads
    1. -join (thread join)
    2. Launch
      1. -launch (application launch)
      2. <launch (parallel application launch)

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:

.\velid.exe main.txt

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
hello
'this is a test ' 123 endl 'this was a new line' -echoln
this is a test 123
this was a new line

-echo

Printing content (no new line at the end)

'orange' -echo 'banana' -echoln
orangebanana

Variables

Declaration

Declaring an empty variable called x

*x

Assignment

Declaration and flush (assignment) afterwards

*x 
'simple value' >> x
x -echoln
simple value

Assignment with inline declaration

'foo' >> *x
x -echoln
foo

Strings

'this string ' "and also this " "go at\nnew line" -echoln
this string and also this got at
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
alfa

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
< 'alfa' 'beta' 'gamma' >

To push a new element in a object as vector use the method -push :

*v
'alfa' @v -push
'beta' @v -push
v -echoln
< 'alfa' 'beta' >

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 ^user
to 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
example: [Function 1:20]

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
test
{ $0 -echoln } 'test' -exec
test
			

Operators

Default operator (??) (undefined fallback)

 'beta' @b >> *x
 x.a ?? "sorry 'a' does not exist" -echoln
sorry 'a' does not exist

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 }
0 1 2 3 4 5 6 7 8 9

If

-string.repeat

0 ? { 'this does not happen' -echoln }
1 ? { 'this happens' -echoln }
this happens

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
this is foo

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
x.a! -echoln

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
alfaalfaalfa

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