Skip to content

The Basics

Vihan edited this page Mar 4, 2018 · 2 revisions

VSL is a new programming language deriving inspiration and features from existing popular languages such as Swift, JavaScript, C, and Java. This means you might find some parts of VSL familiar and other parts new.

VSL has various standard data types, this include Bool, Int, Double, String, and more. If you come from a C background, all primitive data types are seamless from their C counterparts (except for String, more on that in the 'C Interoperability' section). VSL is compatible with the C calling convention meaning you can use a C header file with VSL and directly link your C programs to VSL.

VSL is a statically typed language. This means that VSL will make sure that you don't attempt to add two Animals together or make an Int bark. That said, VSL is a modern language and uses type inference to determine what type a variable must be when you write an expression. An example is:

let a = 1 + 1    // a is an `Int`
let b = Animal() // b is an `Animal`

Another part of VSL that may be new is that it uses optionals. This means if you say "here's an Animal" that means there is an animal. This is in contrast to other languages, in C, types can be NULL, in Java there is null (causing the infamous NullPointerException). VSL avoids headaches caused by undefined values by ensuring that values exist where they are specified to exist. This is done by explicitly marking all values that can be a 'null' value and explicitly unwrapping them. VSL identifies null values using nil:

let a: Int? = nil
print(a + 1) // Oops! You can't add `nil` to a number!

VSL will catch this error in contrast to existing programming languages which will happily compile this code and then throw an error at runtime.


Now that you are familiar with some of the basic concepts behind VSL, let's take a look at specific features in the next few section, along with how you can write your first program.