Basics of Bend
2.1 Hello, World! in Bend
Starting with the traditional βHello, World!β program, we will write a simple Bend script that outputs this greeting.
To run this program, save it in a file named hello_world.bend
. Then, execute it using the following command in your terminal:
You should see the output βHello, World!β in your console.
2.2 Understanding Syntax Variants: Imp vs. Fun
Bend offers two syntax variants, Imp and Fun. Imp is imperative and resembles languages like Python, while Fun is functional and similar to Haskell or ML. You can use either syntax or even mix both in the same project. However, in this guide, weβll primarily focus on the Imp syntax for its simplicity and readability for beginners.
2.3 Variables and Basic Data Types
In Bend, variables are immutable, meaning once a value is assigned to a variable, it cannot be changed.
Bend supports several basic data types:
Integers (u24, i24): Unsigned and signed 24-bit integers.
Floats (f24): 24-bit floating-point numbers.
Booleans: Represented as
true
orfalse
.Characters: Single unicode characters like
'A'
or'π'
.Strings: Sequences of characters like
"Hello"
.Lists: Collections of items like
[1, 2, 3]
.
2.4 Control Flow: If, Switch, and Match
Control flow in Bend allows you to make decisions in your code. The if
statement is used to execute code conditionally.
The switch
statement is used for matching against multiple values of a u24 number.
The match
statement is used for pattern matching against data types.
In the next chapter, we will delve deeper into functions, exploring how to define and use them effectively in Bend.
Last updated