Getting started: build your first RiX program
Run exact calculations, make decisions, and build FizzBuzz from small pieces.
In this lesson you will label the numbers from 1 to 15: multiples of three become Fizz, multiples of five become Buzz, and multiples of both become FizzBuzz. Other numbers stay numbers. You will build and test each piece before running the complete program.
Run a calculation
Press Run cell below. The result appears immediately beneath the editor. RiX keeps integer division exact: the answer is 1/2, not a rounded decimal. The final expression supplies the result; the semicolon ends the statement.
Change 1 / 6 to 1 / 3, predict the answer, and press Re-Run Cell. See Expressions and Number notation for more exact calculations.
Give inputs names
The := sign gives a fresh value a name. Lowercase names such as first and second hold values. The last line uses both names and displays 1/2.
Change second to 1 / 3 and run this cell again. The plain = sign has a different job in RiX; Cells and assignment explains it when you need shared state.
Ask a question and choose a result
FizzBuzz needs to ask whether a number is divisible by three. % gives the remainder, while == asks whether two values are equal. The result below is [1, _]: 1 means true and _ means false or null in this setting.
Write the whole comparison. Zero itself is truthy in RiX, so a bare n % 3 is not a divisibility test. See Operators and precedence for more comparisons.
Choose between two answers
condition ?: yes ?_ no chooses one value. Quotation marks make "Fizz" a text value. This cell returns Fizz; changing n to 7 makes it return 7.
See Ternaries and cases for more decisions and Tuples and strings for text. Comparisons involving uncertain values can also return ?; exact integer inputs here give decided answers.
Give the rule a name
An uppercase name can define a callable. In Fizz(n) -> ..., n is the parameter, and the expression after -> is the body. Fizz(6) calls it with the argument 6.
Try Fizz(7) in the last line. The Define and call lesson develops functions further.
Add the overlapping rules
Test the combined case first. Otherwise 15 would match the three rule and return Fizz before reaching Buzz. This cell checks four useful cases: 2, 3, 5 and 15.
The expected result is [2, Fizz, Buzz, FizzBuzz]. The array display omits quotation marks around strings; Fizz, Buzz and FizzBuzz are still text values.
Apply the rule to several numbers
Square brackets make an array. RiX arrays start at index 1, so the second item of [2, 3, 5, 15] is 3.
The map pipe |>> applies a callback to every item. (n) -> FizzBuzz(n) describes what to do with each input. This cell has all its own setup because this topic begins with a fresh context.
See Arrays for indexing and Pipes for mapping and filtering.
Make the input list
[1 |+ 1 |; 15] starts at 1, adds 1 each time and produces 15 values in total. The starting value counts as the first result. The last item is 15. This is a finite, eager array, so you can inspect it at once.
See Generators for other finite patterns. Lazy generators are a later option when you want values on demand.
Run the complete program
This cell stands on its own. It defines the rule, names the output count, builds the inputs and transforms them. The final expression displays the answer; no printing function is needed in the tutorial.
Read the result from left to right: 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz. Change limit to 30 and rerun. There should be 30 items, with FizzBuzz at positions 15 and 30.
If a cell reports an error, check the spelling and capitalization of names, whether its setup is inside the current topic, and whether you used := to name a value or == to compare. Editing an earlier cell changes the source replayed with later cells in the same level-two topic; rerun the later cell to see the new result.
Continue with Expressions and exact values for the short beginner route. Recipe scaling is a mathematical follow-up after you have met intervals. FizzBuzz in four languages revisits this program from the comparison section, and the JavaScript-to-RiX gotchas page is optional help for experienced programmers.