Chapter 01: Your First Program

Why this chapter matters

A first program should prove only one thing: you can run Ricochet code and see a result. This chapter keeps the program tiny so you can focus on the reading order.

The most important line is this:

ricochet"Hello, Ricochet!" println

The value comes first. The word comes second.

What you will build

You will write and run a one-line script that prints a greeting.

Concepts in plain English

A Ricochet source file usually ends in .rco. A string is text wrapped in quotes. A word is an operation such as println. A comment is text for humans that Ricochet should ignore.

Ricochet comments use this shape:

ricochet(( this is a comment ))

Words introduced

Guided example

Create a file named hello.rco:

ricochet(( My first Ricochet program. ))
"Hello, Ricochet!" println

Run it:

bashrco run hello.rco

You should see the greeting:

textHello, Ricochet!
[]

The final [] is the remaining stack after the program finishes. println consumed the string, so the stack is empty.

You can also run the chapter example from the guide examples:

bashrco run examples/learn/01-hello-world/main.rco

How to read the code

Trace the one useful line from left to right:

Step Token What happens Stack after
1 "Hello, Ricochet!" Put the string on the stack. ["Hello, Ricochet!"]
2 println Consume the string and print it. []

Nothing magical happens before println. Ricochet does not read this as println("Hello"). The value waits first, then the word uses it.

Try it

Change the string and run the file again:

ricochet"stack first, word second" println

Then try the same line in the REPL:

bashrco repl

At the prompt, enter:

ricochet"stack first, word second" println

Check your understanding

Common mistakes

What you know now

You can run a Ricochet file, recognize a string, read one postfix expression, and explain why the final stack is empty.