From 0f9acba83cdd88f995d0082d1fe4abb1f462201f Mon Sep 17 00:00:00 2001 From: Ayush Somani Date: Sat, 18 May 2024 20:44:01 +0530 Subject: [PATCH] add doc --- book.toml | 2 +- src/1-setting-up-your-environment.md | 93 +++++++++++++++++++++++++++ src/2-basics-of-bend.md | 95 ++++++++++++++++++++++++++++ src/README.md | 55 +++++++++------- src/SUMMARY.md | 10 ++- src/chapter-1.md | 32 ---------- 6 files changed, 230 insertions(+), 57 deletions(-) create mode 100644 src/1-setting-up-your-environment.md create mode 100644 src/2-basics-of-bend.md delete mode 100644 src/chapter-1.md diff --git a/book.toml b/book.toml index d369cf1..b3088f2 100644 --- a/book.toml +++ b/book.toml @@ -1,5 +1,5 @@ [book] -title = "Bend Language Guide (Unofficial)" +title = "Bend Programming Language Guide (Unofficial)" authors = ["{{author}}"] language = "en" multilingual = false diff --git a/src/1-setting-up-your-environment.md b/src/1-setting-up-your-environment.md new file mode 100644 index 0000000..c5efba6 --- /dev/null +++ b/src/1-setting-up-your-environment.md @@ -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! \ No newline at end of file diff --git a/src/2-basics-of-bend.md b/src/2-basics-of-bend.md new file mode 100644 index 0000000..73d5932 --- /dev/null +++ b/src/2-basics-of-bend.md @@ -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. \ No newline at end of file diff --git a/src/README.md b/src/README.md index 3bc7d70..5e51a81 100644 --- a/src/README.md +++ b/src/README.md @@ -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. +> **Warning:** 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: +> **PS:** 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.* \ No newline at end of file diff --git a/src/SUMMARY.md b/src/SUMMARY.md index d76eecf..65ddd8a 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) + diff --git a/src/chapter-1.md b/src/chapter-1.md deleted file mode 100644 index 3d0191c..0000000 --- a/src/chapter-1.md +++ /dev/null @@ -1,32 +0,0 @@ -# Chapter 1 - -We then sought for Alexander, but were unable to find him. One of his neighbors, who did not seem to bear him any affection, said that he had gone away two days before, no one knew whither. This was corroborated by his landlord, who had received by messenger the key of the house together with the rent due, in English money. This had been between ten and eleven o'clock last night. We were at a standstill again. - -Whilst we were talking one came running and breathlessly gasped out that the body of Alexander had been found inside the wall of the churchyard of St. Peter, and that the throat had been torn open as if by some wild animal. Those we had been speaking with ran off to see the horror, the women crying out "This is the work of a Slovak!" We hurried away lest we should have been in some way drawn into the affair, and so detained. - -- This is an un-bulleted list item. -- This is another un-bulleted list item. -- And another! - -![A snowy mountain in Moena, Italy. Above the mountain is a sky filled with stars, fading from pink and purple to dark blue. Below the mountains, a forest surrounds.](https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1740&q=80) - -```rust -fn main() { - println!("Hello, world!"); -} -``` - - 1. This is the 1st item. - 1. This is a nested item. - 2. This is the 2nd item. - 3. This is the 3rd item. - 4. This is the 4th item. - -| First name | Last name | -| ---------- | --------- | -| Aaron | Swartz | -| Joan | Clarke | - -Is today's hectic lifestyle making you tense and impatient? Michelle, I don't regret this, but I both rue and lament it. I could if you hadn't turned on the light and shut off my stereo. For the last time, I don't like lilacs! Your 'first' wife was the one who liked lilacs! - -Well, then good news! It's a suppository. Oh Leela! You're the only person I could turn to; you're the only person who ever loved me. We can't compete with Mom! Her company is big and evil! Ours is small and neutral!