SATELLITE.LIBRARY
Some values are part of how a program is set up rather than something it works out: the oven temperature in a recipe, the number of players in a game, the name of a file to save to. You want to write them once, near the top where they are easy to find and change, and read them anywhere. In satellite that is satellite.library.
Writing values at the top of a file
A library value is one line, outside every capsule: satellite.library., a name of your choosing, =, and a value. Every capsule in the file can then read it as satellite.library. and that name, anywhere a value can go: in a line, a condition, a loop, or a capsule inside a namespace.
(satellite)
satellite.library.oven = 180
satellite.library.minutes = 23
satellite.library.cake = "lemon drizzle"
satellite.library.sugar = 1/3
satellite.library.tip = 15%
satellite.library.icing = satellite.bool.true
satellite.namespace timer
{
satellite.capsule countdown()
{
satellite.variable.number left = satellite.library.minutes
satellite.statement.while (left > 20)
{
satellite.console.display(left.to_string() + " minutes left")
left = left - 1
}
}
}
satellite.capsule satellite.main()
{
satellite.console.display("baking a " + satellite.library.cake + " at " + satellite.library.oven.to_string())
satellite.console.display(satellite.library.sugar)
satellite.console.display(satellite.library.tip)
satellite.statement.if (satellite.library.icing)
{
satellite.console.display("with icing")
}
timer.countdown()
satellite.return(satellite)
}baking a lemon drizzle at 180
1/3
15%
with icing
23 minutes left
22 minutes left
21 minutes leftA library value can be any value you can write down: a number, a float, text, a binary, a hex, a percentage, a fraction, or satellite.bool.true or satellite.bool.false, with a minus sign in front if it has one. A colour is written as the hex it holds, such as x1E2A3A.
Notice the name. satellite.library.oven starts with satellite, because the library is part of the language, and ends with oven, which is yours. Each name is written once in a file. Writing the same one twice is refused.
Values, not variables
A library value never changes. That is the whole point: a value that any capsule could change would be a global, and a global can be changed by any part of a program at any time, which makes a program hard to follow. satellite has no globals.
To work with a library value, copy it into a variable of your own. The variable changes; the library value does not. A library value can also be a spacesuit field’s first value.
(satellite)
satellite.library.players = 4
satellite.library.start_lives = 3
satellite.spacesuit player()
{
satellite.protected
{
satellite.variable.number lives = satellite.library.start_lives
}
satellite.public
{
satellite.capsule lose_one()
{
lives = lives - 1
}
satellite.capsule call_lives()
{
satellite.return(lives)
}
}
}
satellite.capsule satellite.main()
{
satellite.variable.number seats = satellite.library.players
seats = seats + 1
satellite.console.display(seats)
satellite.console.display(satellite.library.players)
player ann
ann.lose_one()
satellite.console.display(ann.call_lives())
satellite.console.display(satellite.library.start_lives)
satellite.return(satellite)
}5
4
2
3Changing a library value from inside a capsule is refused before anything runs, and the report says what to do instead:
(satellite)
satellite.library.oven = 180
satellite.capsule satellite.main()
{
satellite.library.oven = 200
satellite.return(satellite)
}--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S250: LIBRARY_VALUE_IS_FIXED
satl(check): in satellite.main, satellite.library.oven is written at the top of
its file and never changes -- a value every capsule could change would be a
global, and satellite has none. Copy it into a variable of your own and change
that
directory: hotter.satl:7
syntax: satellite.library.oven = 200
/\
a satellite.library value is written down at the top of its file -- one number,
text or other literal -- and nothing works it out or changes it afterwards. A
value every capsule could change would be a global, and satellite has none.
machine code 54 library_value_is_fixed -- satl exits with this.
--------------------------------------------------------------------------------Written down, never worked out
Nothing runs outside a capsule, so there is no moment when 90 * 2 could be worked out at the top of a file. A library value must be written as the value itself:
(satellite)
satellite.library.oven = 90 * 2
satellite.capsule satellite.main()
{
satellite.return(satellite)
}--------------------------------------------------------------------------------
SATELLITE CRITICAL ERROR REPORT
--------------------------------------------------------------------------------
S250: LIBRARY_VALUE_IS_FIXED
satl(check): satellite.library.oven is given something to work out, and a
satellite.library value is written down: one number, float, text, binary, hex,
percentage or fraction, or satellite.bool.true or .false. Nothing runs outside a
capsule, so there is no moment for it to be worked out in -- work it out in the
capsule that needs it
directory: worked_out.satl:3
syntax: satellite.library.oven = 90 * 2
/\
a satellite.library value is written down at the top of its file -- one number,
text or other literal -- and nothing works it out or changes it afterwards. A
value every capsule could change would be a global, and satellite has none.
machine code 54 library_value_is_fixed -- satl exits with this.
--------------------------------------------------------------------------------Another file’s values
Library values are handy for a settings file. A program that includes settings.satl reads that file’s values through the file’s name: a value written in settings.satl as satellite.library.players = 4 is read by the program as satellite.library.settings.players. The capsules inside settings.satl itself still read it as satellite.library.players. A file reaches the values of the files it includes itself, and no others, the same way it reaches their capsules.
Where next
The FULL REFERENCE has the complete rules. Including a settings file is covered in INCLUDING FILES AND NAMESPACES, and the settings satl itself runs with are in THE ARGUMENTS VARIABLE.
