Skip to content

Commit

Permalink
add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
geekyayush committed May 18, 2024
1 parent 9805866 commit 0f9acba
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 57 deletions.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[book]
title = "Bend Language Guide (Unofficial)"
title = "Bend Programming Language Guide (Unofficial)"
authors = ["{{author}}"]
language = "en"
multilingual = false
Expand Down
93 changes: 93 additions & 0 deletions src/1-setting-up-your-environment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Chapter 1: Setting Up Your Environment

Welcome to the first chapter of "The Unofficial Bend Programming Language Handbook." This chapter will guide you through setting up your development environment to start coding in Bend. By the end of this chapter, you'll have the tools you need to write, compile, and run Bend programs on your machine.

## Installing Bend

Before we can start writing Bend code, we need to install the Bend compiler and its runtime environment. Bend is built on top of Rust, so you'll need to have Rust installed on your system. Here's how you can get everything set up:

### Step 1: Install Rust

Bend requires the Rust programming language's nightly version. To install Rust, follow these steps:

1. Visit the Rust website at [https://www.rust-lang.org/](https://www.rust-lang.org/).
2. Follow the instructions to download and install `rustup`, which is Rust's installation and version management tool.
3. Once `rustup` is installed, open a terminal and run the following command to install the nightly version of Rust:

```sh
rustup install nightly
```

4. Make Rust nightly your default version by running:

```sh
rustup default nightly
```

### Step 2: Install Bend

With Rust set up, you can now install Bend. Open a terminal and run the following commands:

```sh
cargo +nightly install hvm
cargo +nightly install bend-lang
```

This will install both the HVM2 runtime and Bend language compiler.

### Step 3: Verify Installation

To ensure that Bend has been installed correctly, run:

```sh
bend --help
```

You should see a list of available commands and options for the Bend compiler.

## Editor and IDE Recommendations

While you can write Bend code in any text editor, using an editor with Rust support will make your life easier due to syntax highlighting and other helpful features. Here are some recommendations:

- Visual Studio Code with the Rust extension
- IntelliJ IDEA with the Rust plugin
- Sublime Text with Rust Enhanced package

## Setting Up Your First Project

Create a new directory for your Bend project and navigate into it:

```sh
mkdir bend_project
cd bend_project
```

Inside this directory, create a new file named `main.hvm` which will be our entry point for Bend programs.

```sh
touch main.hvm
```

Open `main.hvm` in your text editor and type in the following code:

```python
# main.hvm
def main():
return "Hello, Bend!"
```

## Compiling and Running Your Code

To compile and run your Bend program, you'll use the `bend` command followed by the `run` subcommand and the file name:

```sh
bend run main.hvm
```

You should see the output `Hello, Bend!` in your terminal.

Congratulations! You've successfully set up your Bend development environment, written a simple program, and executed it. In the next chapter, we'll dive into the basics of the Bend programming language and start writing some real code.

---

This concludes Chapter 1 of the guide. Make sure to follow each step carefully to ensure a smooth setup process. Happy coding in Bend!
95 changes: 95 additions & 0 deletions src/2-basics-of-bend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Chapter 2: Basics of Bend

Welcome to Chapter 2 of the Unofficial Bend Programming Language Handbook. This chapter is designed to introduce you to the fundamental concepts of the Bend programming language. We will cover the basics, from writing your first program to understanding the core data types and control flow mechanisms in 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.

```python
def main():
return "Hello, World!"
```

To run this program, save it in a file named `hello_world.hvm`. Then, execute it using the following command in your terminal:

```sh
bend run hello_world.hvm
```

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.

```python
def main():
message = "Hello, Bend!"
return message
```

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` or `false`.
- **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.

```python
def is_even(number):
if number % 2 == 0:
return true
else:
return false

def main():
return is_even(10)
```

The `switch` statement is used for matching against multiple values of a u24 number.

```python
def classify_number(number):
switch number:
case 0:
return "zero"
case 1:
return "one"
case _:
return "other"

def main():
return classify_number(1)
```

The `match` statement is used for pattern matching against data types.

```python
type Option:
Some { value }
None

def get_option_value(option):
match option:
case Option/Some:
return option.value
case Option/None:
return "No value"

def main():
my_option = Option/Some { value: "Bend is great!" }
return get_option_value(my_option)
```

In the next chapter, we will delve deeper into functions, exploring how to define and use them effectively in Bend.
55 changes: 32 additions & 23 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
# Introduction to Markdown and mdBook
# Introduction to Bend

Welcome to your documentation site! This site is built using:
Welcome to the fascinating world of Bend, a high-level, massively parallel programming language designed to make parallel programming both approachable and efficient. In this guide, we'll explore the ins and outs of Bend, from its basic syntax and constructs to its advanced features that allow you to harness the power of parallel hardware like GPUs.

- **Markdown**: a lightweight markup language for formatting plaintext.
- **mdBook**: a static site generator for Markdown files, created by Rust.
> <font color="red">**Warning:**</font> This doc is still WORK-IN-PROGRESS. Feel free to contribute by clicking on the GitHub icon at the top-right corner.
In this repository, you'll see these files:
> <font color="blue">**PS:**</font> AI may have been used to improve this doc.
```txt
src/
├── README.md
├── SUMMARY.md
└── chapter-1.md
```
## What is Bend?

- `README.md`: This file is the introduction to your book.
- `SUMMARY.md`: This file lists all the chapters in your books. You can have sub-chapters using sub-bullets.
- `chapter-1.md`: This is an example Markdown file.
Bend is a programming language unlike any other. Built on top of Rust, it carries the ambition of making parallel programming not just possible but inherently simple. Bend achieves this by removing the traditional barriers associated with parallel programming—such as thread management and explicit synchronization primitives—and instead, promises that "Everything that **can** run in parallel, **will** run in parallel."

## Examples
This promise is rooted in Bend's design philosophy, which combines the expressive power of languages like Python and Haskell with the performance capabilities of low-level languages like CUDA. Whether you're managing fast object allocations, utilizing higher-order functions, or dealing with recursion, Bend handles the complexity behind the scenes, allowing you to write code that scales almost linearly with the number of cores available.

Looking for inspiration of other documentation sites built using mdBook? Try these (not affiliated):
## Why Bend?

- [The Rust Reference](https://doc.rust-lang.org/reference/): An informal handbook describing the syntax, language constructs, and idioms of the Rust programming language.
- [The Rust Programming Guide](https://doc.rust-lang.org/book/): A detailed guide to learning how to write Rust code.
- [Rust by Example](https://doc.rust-lang.org/stable/rust-by-example/): A guide of learning how to write Rust, using examples.
- [Learn Rust With Entirely Too Many Linked Lists](https://rust-unofficial.github.io/too-many-lists/): A different approach to learning Rust and it's memory-safety using a data structure known as a *linked list*.
- [Rust and WebAssembly](https://rustwasm.github.io/docs/book/): A guide on how to write Rust code for the WebAssembly runtime.
The world of computing is increasingly moving towards parallelism, with modern CPUs and GPUs offering more cores than ever before. However, traditional programming languages often require developers to manually manage the complexities of parallel execution. Bend is here to change that narrative:

- [Amethyst](https://book.amethyst.rs/book/stable/): A game engine written in Rust, developed by the Amethyst team and open-source community.
- [Void Linux Handbook](https://docs.voidlinux.org/): A guide on how to use the Void Linux operating system.
- **Simplicity in Design**: Write high-level code without worrying about the low-level details of parallel execution.
- **Performance**: Bend's programs are designed to run on multi-core and many-core architectures, squeezing out nearly every bit of performance from the hardware.
- **Safety**: Powered by Rust, Bend inherits strong safety guarantees, helping to prevent common parallel programming bugs like race conditions.
- **Open Source**: Bend is open source, inviting collaboration and innovation from developers around the world.

## How to Use This Guide

This guide is structured to provide a step-by-step journey through the features and capabilities of Bend. Whether you're new to programming or an experienced developer looking to expand your skill set, you'll find value in the following pages.

Here's how to get the most out of this guide:

- **Sequential Learning**: If you're new to Bend, it's recommended to go through the guide chapter by chapter, as each section builds upon the knowledge of the previous one.
- **Practical Application**: Throughout the guide, you'll encounter code snippets and examples. Type them out and run them to solidify your understanding.
- **Exercises and Challenges**: At the end of each chapter, take time to work through the exercises to test your knowledge.
- **Feedback Loop**: Use the community resources to ask questions, clarify doubts, and connect with other Bend enthusiasts.

By the end of this guide, you'll have a solid foundation in Bend, equipped with the knowledge to start building your own parallel applications. So, open up your editor, roll up your sleeves, and let's dive into the world of Bend programming!

In the next chapter, we'll walk through setting up your development environment and write our first Bend program. Stay tuned!

---

*Note: This guide assumes that you have a basic understanding of programming concepts. If you're completely new to programming, it might be helpful to familiarize yourself with fundamental concepts in a language like Python or Rust before diving into Bend.*
10 changes: 9 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@

# Chapters

- [Chapter 1](chapter-1.md)
- [Setting Up Your Environment](1-setting-up-your-environment.md)
- [Basics of Bend](2-basics-of-bend.md)
<!-- - [Functions in Bend](3-functions-in-bend.md)
- [Advanced Functions](4-advanced-functions.md)
- [Data Structures](5-data-structures.md)
- [Pattern Matching](6-pattern-matching.md)
- [Parallelism in Bend](7-parallelism-in-bend.md)
- [Error Handling](8-error-handling.md)
- [Memory Management](9-memory-management.md) -->
32 changes: 0 additions & 32 deletions src/chapter-1.md

This file was deleted.

0 comments on commit 0f9acba

Please sign in to comment.