Book Image

Learn Bosque Programming

By : Sebastian Kaczmarek, Joel Ibaceta
Book Image

Learn Bosque Programming

By: Sebastian Kaczmarek, Joel Ibaceta

Overview of this book

Bosque is a new high-level programming language inspired by the impact of structured programming in the 1970s. It adopts the TypeScript syntax and ML semantics and is designed for writing code that is easy to reason about for humans and machines. With this book, you'll understand how Bosque supports high productivity and cloud-first development by removing sources of accidental complexity and introducing novel features. This short book covers all the language features that you need to know to work with Bosque programming. You'll learn about basic data types, variables, functions, operators, statements, and expressions in Bosque and become familiar with advanced features such as typed strings, bulk algebraic data operations, namespace declarations, and concept and entity declarations. This Bosque book provides a complete language reference for learning to program with Bosque and understanding the regularized programming paradigm. You'll also explore real-world examples that will help you to reinforce the knowledge you've acquired. Additionally, you'll discover more advanced topics such as the Bosque project structure and contributing to the project. By the end of this book, you'll have learned how to configure the Bosque environment and build better and reliable software with this exciting new open-source language.
Table of Contents (22 chapters)
1
Section 1: Introduction
5
Section 2: The Bosque Language Overview
10
Section 3: Practicing Bosque
15
Section 4: Exploring Advanced Features

Passing arguments and returning values

When we design programs, it is customary to think about allowing users to define input variables and choose what to receive in response; that is why Bosque allows including parameters and specifying a return type in the definition of a custom entrypoint.

As we can see in the following script, we have a function that receives two integer parameters which will be multiplied and divided, returning a float value:

entrypoint function triangleArea(base: Int, height: Int): Float64 {
	 return ( base * height ) / 2;
}

The structure of a custom entry point can be summarized in the following graphic:

Figure 4.2 – Custom entrypoint structure

Let's see an example. We will write a program that calculates the number in the nth position in the Fibonacci series using a recursive function.

First, we have to write a simple Fibonacci generator function:

recursive function fibonacciNumber(n: Int): Int { ...