Syntax
Vectors
In Vapour vectors are declared with parenthesis, without the need for c
prefix.
- Vapour
- R
let x: int = (1, 2, 3)
x = c(1, 2, 3)
Range
The :
is used to define types in Vapour, so we use ..
for ranges.
- Vapour
- R
let x: int = 1..10
x = 1:10
For loop
The iterator needs to be declared with let
.
- Vapour
- R
for(let i: int in 1..10) {
print(i)
}
for(i in 1:10) {
print(i)
}
Return
In Vapour return
is a keyword, not a function.
- Vapour
- R
func addOne(x: int): int {
return x + 1
}
printIt <- function(x) {
return(x + 1)
}
Defer
Vapour adds the defer
keyword which translates to on.exit
,
defer
expects an anonymous function.
- Vapour
- R
func addOne(x: int): int {
defer (): null => {
print("second!")
}
print("first")
return x + 1
}
addOne <- function(x) {
on.exit((function(){
print("second!")
})())
print("first")
return x + 1
}
Declaration & assignment
In Vapour assignment is always done with the =
sign,
<-
is used for something else (see next section).
You also have to declare mutable variables with let
, this
avoids shooting yourself in the foot overriding variables
that you should not.
- Vapour
- R
let x: char = "hello"
x = "hello"
Assign parent
In Vapour <-
is used to assign to a parent variable,
where one would use <<-
in R.
- Vapour
- R
let x: char = "hello"
if(x == "world") {
x <- "it's world!"
}
x = "hello"
if(x == "world") {
x <<- "it's world!"
}
Constants
We have constants!
This is only checked in Vapour, we do not lock the binding in the transpiled code.
- Vapour
- R
const x: char = "a constant!"
x = "a constant!"
Booleans
Booleans are denoted with true
and false
.
- Vapour
- R
const x: bool = true
x = TRUE
Assignments
Vapour supports addition (+=
) and substitution assignments (-=
).
- Vapour
- R
let x: int = 40
x += 2
x = 40
x = x + 2