Your first program
A program is a list of instructions. You write them in a text file, and the computer follows them from top to bottom.
-
Create a file called
hello.fsigwith any text editor, such as Notepad or Visual Studio Code. Make sure it does not end in.txt. -
Type this program into it and save:
fn main() {print("Hello, world!")} -
Run it with the command-line tool:
Terminal window filascript-cli run hello.fsigThe computer prints:
Hello, world!
What each part means
Section titled “What each part means”fn main() { ... }makes a function calledmain. A function is a named group of instructions. The command-line tool always starts by runningmain.- The curly braces
{and}hold the instructions that belong to the function. print(...)shows a value. Here the value is the string"Hello, world!", which is text written between double quotes.
Make it your own
Section titled “Make it your own”Programs become interesting when they remember things. A variable is a name for a value. You create one by giving
it a value with =:
fn main() { name = "Steve" blocks = 64 print("Hello, " + name + "!") print(name + " has " + str(blocks) + " blocks.") blocks = blocks * 2 print("Now " + str(blocks) + ".")}Hello, Steve!Steve has 64 blocks.Now 128.+ joins two strings together. blocks holds a number, so str(blocks) turns it into text first. FilaScript never
turns numbers into text by itself, so you always know what happens.
When something is wrong
Section titled “When something is wrong”Change print to prnt and run the program again. Instead of running, the tool explains the problem:
hello.fsig:2:5: UNKNOWN_BINDING: No visible binding for this nameThat means: in hello.fsig, line 2, column 5, there is a name the program does not know. Fix the spelling and run
it again. Reading errors explains all the parts.
Next, learn about values and variables.