Hello, world!
Let’s run our first Vine program!
// hello_world.vi pub fn main(&io: &IO) { io.println("Hello, world!"); }
We can run this with:
vine run hello_world.vi
You should see something like the following:
Hello, world! Interactions Total 341 Annihilate 180 Commute 0 Copy 23 Erase 47 Expand 36 Call 41 Branch 14 Memory Heap 640 B Allocated 7_216 B Freed 7_216 B Performance Time 0 ms Speed 10_740_157 IPS
At the top, notice that it successfully printed Hello, world!.
At the bottom, you’ll also see several statistics printed out. You don’t need to worry about them for now. If you want to disable them, you can use --no-stats.
Let’s break down what just happened.
-
fn main: declares a function, namedmainpub: makes it public-
(&io: &IO): it takes a single parameter:&IO: of type&IO&io: to be dereferenced and bound to the variableio
-
{ ... }: in the function bodyio.println: uses theprintlnmethod onIO("Hello, world!"): calls it with the stringHello, world!
We’ll go into this in more detail in future chapters.
Every Vine program must contain a pub fn main(&io: &IO) { ... } (“a public function main that takes a reference to IO”).