Home /Examples/lib/examples/sleela/LEARNER-PATH.md

LEARNER-PATH.md

lib/examples/sleela/LEARNER-PATH.md · 71 line(s) · markdown

A friendly first path through SLeeLa

This path is designed for a first-time learner. You do not need to understand the whole language at once. Read one lesson, predict what the program will print, run it, and then make one small change.

Before you begin

Build the repository toolchain from the repository root:

make -C impl

Check the supported syntax range:

./impl/build/sleela version

The compiler source currently defines the supported syntax range as 1.0–2.8 in impl/frontend/version.h. The first lessons use syntax 1.7; the advanced examples use 2.1, and the newest integer lessons use 2.7 and 2.8.

The eleven first lessons

StepFileWhat to learn
1CLASSIC-hello-world.sleelaA class, the main method, and printing text
2ORIGINAL-fizz-buzz.sleelaNumbers, a for loop, if, and the remainder operator
3USED-methods-and-return-values.sleelaGive a method a value and get an answer back
4USED-switch-selection.sleelaChoose one path from several cases
5USED-short-circuit-guards.sleelaCombine conditions without unnecessary checks
6NEW-dynamic-arrays.sleelaStore a list of values and add another one
7NEW-struct-record.sleelaKeep related data together
8NEW-nested-classes.sleelaPut a helper type inside the class that uses it
9NEW-native-financial-import.sleelaImport a library and call its functions
10NEW-signed-wide-integers-2.7.sleelaMeet the newer signed integer widths
11NEW-unsigned-wide-integers-2.8.sleelaMeet positive-only unsigned integer widths

How to run each lesson

Replace the filename with the lesson you want to try:

./impl/build/sleela check lib/examples/sleela/CLASSIC-hello-world.sleela
./impl/build/sleela run lib/examples/sleela/CLASSIC-hello-world.sleela

You can also create a reusable runnable artifact:

./impl/build/sleela compile lib/examples/sleela/CLASSIC-hello-world.sleela -o /tmp/hello.sleela
./impl/build/sleela validate-artifact /tmp/hello.sleela
./impl/build/sleela run /tmp/hello.sleela

Three habits for learning

  1. Predict first. Read the program and write down what you think it will print.
  2. Change one thing. Change one number or one word, then run it again.
  3. Keep the example working. If a change causes an error, undo just that change and try a smaller one.

A small challenge

Write a program that stores three scores in an array, calculates their total, and prints the total. Then add a fourth score with arrayPush and print the new array length.

Where to go next

After the first lessons, open the advanced feature catalogue. Try the pipe, time, or struct-transport example next. Network examples use loopback only; read each source comment before running it.

Important distinction

The examples in this directory are intended to be language demonstrations. Some examples in other subsystem folders are explicitly labelled as simulations, checklists, policy tests, or draft API vocabulary. Their README files explain which ones require native bridges, external services, or hardware.