BEGINNERS

Welcome. This page is for you if you have never written a program before. You do not need to know anything about computers beyond opening an app and saving a file. We will go one small idea at a time, and every example is tiny.

Every example on this page has been run. The OUTPUT box under each one shows exactly what satl printed.

WHAT A PROGRAM IS

A program is a list of instructions for a computer. The computer follows them one at a time, from the top down, and does exactly what they say. It never guesses what you meant.

You write a satellite program in a plain text file whose name ends in .satl, such as hello.satl. Then you hand that file to satl, the program that reads satellite and carries out your instructions. Handing a file to satl is called running it.

WHAT YOU NEED

  • satl itself. The INSTALL page shows how to get it.
  • A plain text editor, such as the Text Editor that comes with your desktop. A word processor is the wrong tool: it saves more than the letters you typed.
  • A place to type commands. That is satl’s own console, or a terminal. Both are below; pick either one.

OPENING THE CONSOLE

SATL’S OWN CONSOLE

Once satl is installed, look in your applications menu for Satellite 004 and open it. A window appears: satl’s own console. Its last line is the prompt, the place where you type. The prompt ends in >>. Before that, in square brackets, it shows satellite, your user name, and the folder the console is working in. Remember that folder: it is where you will save your programs.

Type this at the prompt, exactly as it is, and press Enter:

TEXT Download
satellite.console.display("hi")

satl answers straight away:

OUTPUT
hi

The prompt also knows a few words of its own:

  • interpret hello.satl runs the program saved in hello.satl, in the folder the prompt shows. run hello.satl does the same thing.
  • exit or quit leaves the prompt. So does pressing Ctrl-D.

A TERMINAL

You can also use a terminal. Open Terminal from your applications menu, then type satl and the name of your program’s file:

BASH Download
Running a program from a terminal
satl hello.satl

A new terminal starts in your home folder, so save your programs there. If the terminal answers bash: satl: command not found, satl is installed but the terminal does not know its short name. Type its full address instead. The installer puts satl in ~/.satl unless you told it otherwise, and ~ means your home folder:

BASH Download
The same, with satl's full address
~/.satl/satl hello.satl

Typing satl --console in a terminal opens satl’s own console, the same one the applications menu opens.

When satl runs a program, it first prints a few lines about itself: its name, its version and how it was built. The OUTPUT boxes on this site leave those lines out and show only what your program printed.

YOUR FIRST PROGRAM

Open your text editor and type this program. Copying it is fine too. Save it as hello.satl in the folder you chose above.

hello.satlSATELLITE 004 Download
Your first program
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display("Hello, World!")
    satellite.return(satellite)
}

Now run it. At the console’s prompt, type interpret hello.satl. In a terminal, type satl hello.satl. You should see:

OUTPUT
Hello, World!

That is a working program, and you wrote it.

After it runs, you will find a second file beside yours, called hello.sate. It is satl’s own copy of your program, turned into numbers. satl writes it every time it runs your program, and you can leave it alone.

WHAT EACH LINE MEANS

Here is the program again, one line at a time.

  1. satellite.include(satellite) says “this file is a program”. Every program starts with it.
  2. satellite.capsule satellite.main() begins the main capsule. A capsule is a group of instructions with a name. satellite.main is the one every program starts in.
  3. { and } are the capsule’s walls. Everything between them belongs to it.
  4. satellite.console.display("Hello, World!") writes one line on the screen. The console is where your program talks to a person, and display is how it shows them something. The text between the double quotes is shown exactly as you wrote it.
  5. satellite.return(satellite) is the end. When the program reaches it, the program is finished.

Every program has those three parts: the include at the top, satellite.main, and satellite.return(satellite) as the last line of main. Leave one out and satl tells you which one, and what to type.

Notice that almost every word starts with satellite.. That is satellite’s one big rule: a dotted name that starts with satellite belongs to the language, and a plain name belongs to you. Read a dotted name from left to right, like an address: satellite.console.display is the language’s console, and on it, display. Soon you will make names of your own, like age or greet, and they will have no satellite. in front.

A few more things about how a program is written:

  • One instruction goes on each line.
  • The spaces at the start of a line are only there to make it easy to read. satl does not mind them.
  • A // starts a note for people, and satl skips the rest of that line. Inside quotes, // is just text.

MAKING AND FIXING A MISTAKE

Everybody makes mistakes, and satl is built to help you find them. Here is the first program with a mistake in it: the quotes around Hello are missing.

mistake.satlSATELLITE 004 Download
The quotes are missing
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display(Hello)
    satellite.return(satellite)
}

satl stops and prints an error report:

OUTPUT
--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S201: NAME_NOT_DECLARED
satl(check): in satellite.main, Hello has no satellite.variable line declaring
it

directory: mistake.satl:5
syntax: satellite.console.display(Hello)
        /\

this name was used and no satellite.variable line ever declared it. A name has
to be given a type before it can hold anything.
machine code 25 name_not_declared -- satl exits with this.

--------------------------------------------------------------------------------

It looks like a lot, but read it from the top and each part tells you one thing:

  • S201: NAME_NOT_DECLARED is the kind of problem, as a code and a name.
  • The next line says what went wrong, in words: Hello has no line declaring it.
  • directory: mistake.satl:5 is where: the file mistake.satl, line 5.
  • syntax: shows you that line.
  • The paragraph after it explains the problem more fully.

So what happened? Without quotes, Hello is not text any more. satl reads it as a name, and no name called Hello exists. Put the quotes back, save the file, and run it again. It works.

If you forget the last line, satellite.return(satellite), the report tells you exactly what to add. When you get an error report, do not worry. Read the line number, look at that line, and compare it with an example that works.

NAMES THAT HOLD VALUES

A program often needs to remember something. It keeps it in a variable: a name that holds a value.

You make one by writing its kind, then its name, then =, then the value it starts with:

names.satlSATELLITE 004 Download
Two names, and what they hold
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.string name = "Ada"
    satellite.variable.number age = 36
    satellite.console.display(name)
    satellite.console.display(age)
    satellite.return(satellite)
}
OUTPUT
Ada
36

Two kinds are enough to start with:

  • satellite.variable.string holds text. Text always goes between double quotes.
  • satellite.variable.number holds a whole number, like 36 or -7.

name and age are your own names, so they are plain words with no satellite. in front. You choose them. Short lowercase words, joined with _ when you need more than one, such as my_age, are easy to read.

A variable can change. Give it a new value with =, and leave the kind off this time, because satl already knows it:

birthday.satlSATELLITE 004 Download
Changing what a name holds
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number age = 36
    satellite.console.display(age)
    age = age + 1
    satellite.console.display(age)
    satellite.return(satellite)
}
OUTPUT
36
37

age = age + 1 means “work out age plus one, then put the answer back in age”.

DOING SUMS

satellite does arithmetic with these signs:

  • + adds and - subtracts.
  • * multiplies and / divides.
  • % gives the remainder after dividing.
  • ^ raises to a power, so 2 ^ 10 is ten 2s multiplied together, which is 1024.
sums.satlSATELLITE 004 Download
Sums
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display(2 + 3)
    satellite.console.display(10 - 4)
    satellite.console.display(6 * 7)
    satellite.console.display(7 / 2)
    satellite.console.display(7 % 2)
    satellite.console.display(7.0 / 2)
    satellite.console.display(2 + 3 * 4)
    satellite.console.display((2 + 3) * 4)
    satellite.console.display(2 ^ 100)
    satellite.return(satellite)
}
OUTPUT
5
6
42
3
1
3.5
14
20
1267650600228229401496703205376

Some of those deserve a second look:

  • 7 / 2 is 3, because dividing two whole numbers gives a whole number. The 1 left over is what 7 % 2 gives you.
  • 7.0 / 2 is 3.5. A number with a point in it keeps the part after the point.
  • 2 + 3 * 4 is 14, because * and / are done before + and -, as in school. Brackets change the order: (2 + 3) * 4 is 20.
  • 2 ^ 100 is a very big number, and satellite shows every digit. Its whole numbers have no size limit but your computer’s memory.

SPACES AROUND THE SIGNS

satellite has one rule here that is easy to forget: every maths sign has a space on both sides. 4 + 3 is right. 4+3 is refused:

no_spaces.satlSATELLITE 004 Download
4+3 without spaces
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.console.display(4+3)
    satellite.return(satellite)
}
OUTPUT
--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S110: LINE_NOT_UNDERSTOOD
satl(run): every math operation is written with a space on both sides of the
sign, and this + has none

directory: no_spaces.satl:5
syntax: satellite.console.display(4+3)
        /\

satellite has no scenario for this line -- it is spelled in a shape the language
does not have a meaning for.
machine code 13 satl_line_not_understood -- satl exits with this.

--------------------------------------------------------------------------------

TEXT AND NUMBERS TOGETHER

+ also joins two pieces of text into one, and a number added to some text joins it as its digits:

joining.satlSATELLITE 004 Download
Joining text, and a number joined to text
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.string name = "Ada"
    satellite.variable.number age = 36
    satellite.console.display("Hello, " + name)
    satellite.console.display(name + " is " + age)
    satellite.return(satellite)
}
OUTPUT
Hello, Ada
Ada is 36

The number can come first as well. When the text after it is a number too, like "2", + adds the two — and when it is any other text, + joins them:

number_first.satlSATELLITE 004 Download
A number first: text that is a number adds, other text joins
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number age = 36
    satellite.console.display(age + " is Ada's age")
    satellite.console.display(4 + "2")
    satellite.return(satellite)
}
OUTPUT
36 is Ada's age
6

4 + "2" is the number 6, not the text “42”: satellite reads the “2” as the number it spells. To join a number to text that is also a number, turn one of them into text yourself: 4.string + "2" is 42.

ASKING A QUESTION WITH IF

A program can ask a question and answer it with true or false. These signs compare two values:

  • == asks “are these equal?” and != asks “are these different?”
  • < is less than and > is more than.
  • <= is less than or equal, and >= is more than or equal.

Be careful with ==. Two equals signs ask a question. One equals sign gives a name a value.

satellite.statement.if runs the lines between its walls only when the answer is true. satellite.statement.else gives the lines to run when it is false:

weather.satlSATELLITE 004 Download
Deciding with if and else
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number temperature = 25
    satellite.console.display(temperature > 20)
    satellite.statement.if (temperature > 20)
    {
        satellite.console.display("It is warm today.")
    }
    satellite.statement.else
    {
        satellite.console.display("Take a coat.")
    }
    satellite.return(satellite)
}
OUTPUT
true
It is warm today.

Change 25 to 12, save and run it again, and the program takes a coat instead.

When there are more than two choices, put satellite.statement.else satellite.statement.if between them. satl tries each question in turn and runs the first one that is true:

three_ways.satlSATELLITE 004 Download
Three choices
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number temperature = 12
    satellite.statement.if (temperature < 0)
    {
        satellite.console.display("freezing")
    }
    satellite.statement.else satellite.statement.if (temperature < 15)
    {
        satellite.console.display("cool")
    }
    satellite.statement.else
    {
        satellite.console.display("mild or warm")
    }
    satellite.return(satellite)
}
OUTPUT
cool

Text can be compared too: satellite.statement.if (name == "Ada") asks whether name holds exactly Ada.

REPEATING WITH WHILE

Computers are good at doing something again and again. satellite.statement.while keeps running the lines between its walls for as long as its question is true:

counting.satlSATELLITE 004 Download
Counting to three
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.variable.number count = 1
    satellite.statement.while (count <= 3)
    {
        satellite.console.display(count)
        count = count + 1
    }
    satellite.console.display("done")
    satellite.return(satellite)
}
OUTPUT
1
2
3
done

Each time round, satl asks count <= 3. While the answer is true, it shows the count and adds one. When count reaches 4, the answer is false, and the program carries on after the closing }.

If you forget the line that changes count, the answer never becomes false, and the program runs forever. That does no harm. In a terminal, press Ctrl-C and the program stops.

REPEATING WITH FOR

Counting is so common that it has its own shorter form. satellite.statement.for takes three parts, with a ; between them:

  1. the name that counts, and where it starts;
  2. the question to ask before each time round;
  3. how the count moves after each time round.
for_loop.satlSATELLITE 004 Download
Counting with for
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.statement.for (satellite.variable.number i = 1; i <= 5; i + 1)
    {
        satellite.console.display(i)
    }
    satellite.return(satellite)
}
OUTPUT
1
2
3
4
5

The third part is written i + 1, without an =: satl knows it belongs to i. i++ means the same thing, and it can move by other amounts too. Here it counts down in threes:

countdown.satlSATELLITE 004 Download
Counting down in threes
satellite.include(satellite)

satellite.capsule satellite.main()
{
    satellite.statement.for (satellite.variable.number n = 10; n > 0; n - 3)
    {
        satellite.console.display(n)
    }
    satellite.console.display("lift off")
    satellite.return(satellite)
}
OUTPUT
10
7
4
1
lift off

MAKING YOUR OWN CAPSULE

You have been writing inside one capsule, satellite.main, all along. You can make your own too. A capsule gives a group of lines a name, and then you can run them whenever you like by writing that name. Running a capsule is called calling it.

say_hello.satlSATELLITE 004 Download
A capsule of your own
satellite.include(satellite)

satellite.capsule say_hello()
{
    satellite.console.display("Hello!")
    satellite.console.display("Nice to see you.")
}

satellite.capsule satellite.main()
{
    say_hello()
    say_hello()
    satellite.return(satellite)
}
OUTPUT
Hello!
Nice to see you.
Hello!
Nice to see you.

say_hello is your own name, so it has no satellite. in front. It is written outside main, and main calls it twice.

A capsule can be handed values to work with. They go between its brackets, written the same way as a variable: the kind, then a name. And a capsule can hand an answer back, with satellite.return(...):

greet.satlSATELLITE 004 Download
Handing a capsule values, and getting an answer back
satellite.include(satellite)

satellite.capsule greet(satellite.variable.string who)
{
    satellite.console.display("Hello, " + who + "!")
}

satellite.capsule double(satellite.variable.number n)
{
    satellite.return(n * 2)
}

satellite.capsule satellite.main()
{
    greet("Ada")
    greet("Grace")
    satellite.console.display(double(21))
    satellite.variable.number big = double(double(5))
    satellite.console.display(big)
    satellite.return(satellite)
}
OUTPUT
Hello, Ada!
Hello, Grace!
42
20

A capsule lives in a room of its own. It cannot see the names in main, so everything it needs, you hand it between the brackets. That keeps each capsule simple to understand: what goes in is all it has, and what it returns is all it gives back.

PUTTING IT TOGETHER

Here is everything on this page in one small program: two capsules, a question, and two loops.

together.satlSATELLITE 004 Download
Everything together
satellite.include(satellite)

satellite.capsule even_or_odd(satellite.variable.number n)
{
    satellite.statement.if (n % 2 == 0)
    {
        satellite.return("even")
    }
    satellite.return("odd")
}

satellite.capsule times_table(satellite.variable.number which)
{
    satellite.statement.for (satellite.variable.number i = 1; i <= 5; i + 1)
    {
        satellite.console.display(i.string + " x " + which.string + " = " + (i * which).string)
    }
}

satellite.capsule satellite.main()
{
    satellite.statement.for (satellite.variable.number n = 1; n <= 4; n + 1)
    {
        satellite.console.display(n.string + " is " + even_or_odd(n))
    }
    times_table(3)
    satellite.return(satellite)
}
OUTPUT
1 is odd
2 is even
3 is odd
4 is even
1 x 3 = 3
2 x 3 = 6
3 x 3 = 9
4 x 3 = 12
5 x 3 = 15

n % 2 == 0 asks whether n divides by 2 with nothing left over, which is what makes a number even. satellite.return ends a capsule wherever it stands, so an even number never reaches the "odd" line.

Try changing it. Show the times table for 7, or count to 10. Break it on purpose and read what satl says. That is how programmers learn.

WHERE TO GO NEXT