Skip to content

Comparison with Vessel

Nate Ferrero edited this page Oct 25, 2015 · 2 revisions

Vessel Programming Language Specification

Cat eats Dog Example

Animal: {
  name: @it
  tummy: []

  eats: {
    @it tummy.push
  }
}

cat: 'Kitty Cat' Animal
dog: 'Gruffy'    Animal

dog cat.eats

Classes and Functions Examples

Material: {

}

Material: {
  getName: {
    name
  }
}

Material: {
  getName: {
    name
  }
  setName: {
    name: @it
  }
}

Tree: Material {

}

Pine: Material Tree {

}

Arrays Examples

x: [] {8: 22}

x 8 @Console.log

# 22

Objects Examples

Cat: {
  name @String.isInstanceOf || 'name' @TypeError ^
  born @Date.isInstanceOf   || 'born' @TypeError ^

  meow get: {
    `Meow! I, ${name}, was born on ${born}.` @Console.log
  }
}

{} Cat

# TypeError: name

kitty: {name: 'Kitty', born: '2015-01-01' @Date} Cat

kitty.meow

# Meow! I, Kitty was born on Thu Jan 01 2015 00:00:00 GMT-0500 (EST).

Imports Examples

Service: '../service' @system.import

Scope Injection Examples

App: {
  run: {
    @Service
  }
}

{@Service get: {'wow' @Console.log}} ({} App).run

# wow

Logic Examples

success && ( ... ) || ( ... )

Looping Examples

[1, 2, 3].each {

}

{
  alive @Console.log
}.while {
  alive
}

{
  alive @Console.log
}.until {
  !alive
}

Try / Catch Examples

'error' ^
= {
  `event raised: ${@it}` @Console.log
}

= @TypeError {
  'got a type error'
}

'wow' ^
'wow' @TypeError ^

# event raised: wow
# event raised: TypeError: wow
# got a type error