Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

"Hello, World!" Example

The classic first example:

This example shows two of Fuzion's most fundamental concepts: feature declarations and feature calls. The code for this small example is wrapped in a feature called hello_world, which is introduced in the first line. This feature is a routine that is implemented by a code block following the keyword is. The code block may alternatively be surrounded by braces { }, in which case the is is optional.

The code itself performs one call to the feature say. This call receives an argument, which is a constant String "Hello, World!". Arguments to a call are written directly following the call and are separated by spaces. Parentheses around the arguments may be needed in nested calls. Here is an example where parentheses are necessary: say ("hello".count "l")

Effects

Fuzion uses effects to model interaction with the outside world, which allows Fuzion features to be pure functions. The effects required are determined automatically by static analysis. Click the Effects! button to see which effects are needed by the code.

You will see that the example above uses the effect io.out. The reason is that say uses io.out to output its argument. So we could create the equivalent application using io.out.println instead of say

This version behaves the same as the previous one and uses the same effect, io.out.

When we print text to the standard error stream instead as in the following code:

the analysis of effects will show that this code uses a different effect: io.err.

If we use both, standard output and error, the analysis of effects will show both: io.out and io.err.

The next example adds a random number of exclamation marks to the output:

The effects reported by this example now include random since the random number generator is also implemented as an effect in Fuzion. Furthermore, we see that the code uses the effect time.nano. The reason for this is that the default random number generator is initialized using the nanosecond timer.

Effects play a major role in Fuzion code, they can be used to understand what dependencies code has, but they also permit code to be executed with particular implementations of the effects it depends on. E.g., one might want to ensure that a security library that requires a source of randomness would not run with a random number generator using a time based seed, but with a cryptographically strong source of entropy.

International

Fuzion uses Unicode characters, all sources must be UTF-8 encoded. It is hence possible to use international characters as in this example: