Chapter 04: Values, Literals, and Inspection

Why this chapter matters

A stack is only useful if you know what kinds of values are sitting on it. This chapter introduces Ricochet’s everyday value families and gives you two tools, type and inspect, for checking your assumptions.

What you will build

You will build a value tour that prints and inspects representative Ricochet values.

Concepts in plain English

A literal is a value written directly in source code, such as 42, 3.5, true, false, nil, or "Ada". Collections, blocks, results, regexes, capabilities, and tasks are also values, but you will learn those gradually.

nil is its own value. It is not the same thing as false, an empty string, or an empty collection.

Words introduced

Guided example

Run the value tour:

bashrco run examples/learn/04-values/value-tour.rco

The example prints the runtime kind of common values:

ricochet"true type:" print
true type println

"integer type:" print
42 type println

"float type:" print
3.5 type println

How to read the code

This line leaves a value, then transforms it into a type name:

ricochettrue type println

Read it as: put true on the stack, ask for its type, print the type string.

This inspection pattern is slightly different:

ricochet$values inspect println drop

inspect leaves the original value in place and pushes a debug string above it. println consumes the debug string. drop removes the original value so the final stack stays clean.

Try it

Add these lines to the example and compare the printed values:

ricochet"text" empty? println
"" empty? println
nil nil? println
false nil? println

Then try:

ricochet42 inspect println drop

Check your understanding

Common mistakes

What you know now

You can recognize basic values, inspect a value without losing it, and separate nil, booleans, strings, numbers, and collections in your head.