-
Book Overview & Buying
-
Table Of Contents
Learn Bosque Programming
By :
Bosque allows us to define immutable or constant variables that will maintain a single value throughout the execution life cycle. For this purpose, unlike mutable variables, Bosque provides the reserved word let; it is recommended to use these variables when variables don't have to be updated during our programs' execution.
A constant must always be initialized, but the type can be omitted since the type could be inferred from the assigned value.
The following code block shows some constant declarations:
let x: Int = 3;
let y = 5;
let x, y = 3, 5;
let {i=x, j=y} = {f=3, g=5};
If we try to change the value of a constant through a second assignment, we will get an error message.
It is also possible to have variables and constants within the same declaration, which allows us to simplify our code. This can done in the following way:
[var x, let y] = [3, 5];
In this piece of code, the variable x is assigned with a value of 3 and the type Int...