fble-0.5 (2025-07-13,fble-0.4-212-ga8f8ad0f)
In this tutorial you'll write and run a traditional hello world program that prints out the string "hello, world".
In your favorite text editor, start a new file called HelloWorld.fble
.
The .fble
extension is used for fble programs; it is required for the
fble interpreter and compiler to be able to locate your code.
The following is a complete hello world program in fble:
# Import string type and literal from the core library. @ String@ = /Core/String%.String@; % Str = /Core/String%.Str; # Specify the output string. String@ output = Str|'hello, world'; # Call the helper function for a main function # that outputs a single string value. /Core/Stdio/StringO%.Run(output);
We'll break this down piece by piece in the following sections.
Comments in fble start with the #
character and continue to the end of
the line. For example:
# Import string type and literal from the core library.
The first few lines of code of the hello world program import the
String@
type and Str
string literal function from the core library.
@ String@ = /Core/String%.String@; % Str = /Core/String%.Str;
Names ending in the @
character are types. Names without @
are
values. In this case String@
is a type and Str
is a value.
Names ending in %
are names of modules. /Core/String%
is a module
from the core library that defines the string type and related functions.
Modules are located by searching module directories of the package search
path. The source code for module /Core/String%
will be in a file
Core/String.fble
. You can see the default package search path
for your installation by running fble-stdio --help
, or set your own
package search path using the FBLE_PACKAGE_PATH environment variable and/or
-I
and -p
options to fble-stdio
.
Next we declare a variable called output
whose value is the string
literal for hello, world
.
String@ output = Str|'hello, world';
The last thing we do is specify the /HelloWorld%
module value,
which will be used as the main function for the program.
/Core/Stdio/StringO%.Run(output);
This uses a helper function from the /Core/Stdio/StringO%
module which
defines a main function that outputs a single string when run. The Run
function returns a main function that can be run by the fble-stdio
program.
We use the fble-stdio
program to run our HelloWorld.fble
program:
fble-stdio -p core -I . -m /HelloWorld%
If all goes well, this should output the string hello, world
.
The -p
option to fble-stdio
says our program relies on modules from
the core
package. The -I
option says to look for your
HelloWorld.fble
file in the current directory, and the -m
option says
to execute code from the /HelloWorld%
module you just defined.
An important motivation for the hello world program is to show you how to
print things to the output, so you can see the results of trying
different things in subsequent tutorials. Fble doesn't have a printf
function or format strings. Instead, many of the types defined in
the core library define a Show
function to convert them to strings. You
can concatenate strings directly together using the /Core/String%.Strs
function or join them as separate lines using the /Core/String%.Lines
function.
For example, try updating your hello world program to print some of the following different types of values.
@ Bool@ = /Core/Bool%.Bool@; Bool@ True = /Core/Bool%.True; Bool@ False = /Core/Bool%.False; String@ output = Strs[Str|'A boolean: ', /Core/Bool/Show%.Show(True)];
@ Char@ = /Core/Char%.Char@; % Chars = /Core/Char%.Chars; Char@ c = Chars.A; String@ output = Strs[Str|'A character: ', c];
String@ output = Strs[Str|'A list: ', /Core/List/Show%.Show(/Core/Bool/Show%.Show)[True, False, True]];
@ Int@ = /Core/Int%.Int@; % Int = /Core/Int/Lit%.Int; Int@ x = Int|42; String@ output = Strs[Str|'An integer: ', x];
Update your hello world program to output all of the different types shown
above in a single string. Compare your hello world program with the sample
one in at tutorials/HelloWorld/HelloWorld.fble
included with this
tutorial.
Sometimes we import values from other modules, other times we use them
directly. It's your choice. Try removing the import for String@
and using
the value directly from the /Core/String%
module. Try importing the
/Core/Stdio/StringO%.Run
function before using it.
String literals are introduced using Str|
, not from single quotes. If
you have a string without spaces or other punctuation characters, you don't
need single quotes. Try printing hello
using a string literal without
single quotes.
Now you know how to write and run your own fble program and print some
different types of values. The next step is to do a deep dive, starting with
the basics of fble: structs, unions, and functions. Head over to the
Basics
tutorial to learn more.