Merge branch 'main' of github.com:HigherOrderCo/bend

This commit is contained in:
Victor Taelin 2024-05-16 18:34:23 -03:00
commit 0e23b8bfb2
5 changed files with 20 additions and 14 deletions

2
Cargo.lock generated
View File

@ -83,7 +83,7 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bend-lang"
version = "0.2.4"
version = "0.2.5"
dependencies = [
"TSPL 0.0.12",
"clap",

View File

@ -2,8 +2,9 @@
name = "bend-lang"
description = "A high-level, massively parallel programming language"
license = "MIT"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
exclude = ["media/", "tests/snapshots/"]
[lib]
name = "bend"

View File

@ -6,7 +6,7 @@ feels like Python, but scales like CUDA. It runs on CPUs and GPUs, and you don't
have to do anything to make it parallel: as long as your code isn't "helplessly
sequential", it **will** use 1000's of threads!
While cool, Bend far from perfect. In absolute terms it is still not so fast.
While cool, Bend is far from perfect. In absolute terms it is still not so fast.
Compared to SOTA compilers like GCC or GHC, our code gen is still embarrassingly
bad, and there is a lot to improve. And, of course, in this beginning, there
will be tons of instability and bugs. That said, it does what it promises:
@ -252,7 +252,7 @@ def main:
return is_even(7)
```
Which is immutable. If that's sound annoying, that's because **it is**. Don't
Which is immutable. If that sounds annoying, that's because **it is**. Don't
let anyone tell you otherwise. We are aware of that, and we have many ideas on
how to improve this, making Bend feel even more Python-like. For now, we have to
live with it. But, wait... if variables are immutable... how do we even do
@ -268,7 +268,7 @@ def sum(x):
Here, the entire way the algorithm works is by mutating the `total` variable.
Without mutability, loops don't make sense. The good news is Bend has *something
else* that is equally as - actually, mode - powerful. And learning it is really
else* that is equally as - actually, more - powerful. And learning it is really
worth your time. Let's do it!
Folds and Bends
@ -313,8 +313,8 @@ As usual, for now, we'll live with the longer version.
Now, here's a question: how do we *sum* the elements of a tree? In Python, we
could just use a loop. In Bend, we don't have loops. Fortunately, there is
another construct we can use: is called `fold`, and it works like a *search and
replace* for datatypes. For example, consider the code below:
another construct we can use: it's called `fold`, and it works like a *search
and replace* for datatypes. For example, consider the code below:
```python
@ -395,6 +395,7 @@ exercise, use `fold` to implement a "reverse" algorithm for lists:
```python
def reverse(list):
# exercise
?
def main:
@ -491,7 +492,7 @@ for i in range(8):
sum += i
```
Is actually just a short way to write:
Is actually just a similar way to write:
```python
sum = (0 + (1 + (2 + (3 + (4 + (5 + (6 + 7)))))))
@ -533,7 +534,7 @@ So, how do you write a parallel program in Bend?
**Just write algorithms that aren't helplessly sequential.**
That's all there is to it. As long as you write programs like that one, and
That's all there is to it. As long as you write programs like that one, then
unlike the former one, they will run in parallel. And that's why `bend` and
`fold` are core features: they're, essentially, parallelizable loops. For
example, to add numbers in parallel, we can write:
@ -570,8 +571,8 @@ That's **18x faster**! Can we do better? Sure: let's use the **C compiler** now:
bend gen-c main.bend >> main.c
```
This command converts your `bend` file in a small, dependency-free C file that
does the same computation much faster. You can compile it to an executable:
This command converts your `bend` file into a small, dependency-free C file
that does the same computation much faster. You can compile it to an executable:
```
gcc main.c -o main -O2 -lm -lpthread # if you're on Linux
@ -754,7 +755,7 @@ has an entire "secret" Haskell-like syntax that is compatible with old HVM1. For
example,
[here](https://gist.github.com/VictorTaelin/9cbb43e2b1f39006bae01238f99ff224) is
an implementation of the Bitonic Sort with Haskell-like equations. We'll
document it syntax here soon!
document its syntax here soon!
Community
---------

View File

@ -90,7 +90,7 @@ allocate an immutable tree on each frame:
def render(depth, shader):
bend d = 0, i = 0:
when d < depth:
color = (go(d+1, i*2+0), go(d+1, i*2+1))
color = (fork(d+1, i*2+0), fork(d+1, i*2+1))
else:
width = depth / 2
color = demo_shader(i % width, i / width)
@ -101,7 +101,7 @@ def render(depth, shader):
def demo_shader(x, y):
bend i = 0:
when i < 100000:
color = go(i + 1)
color = fork(i + 1)
else:
color = 0x000001
return color

View File

@ -10,6 +10,7 @@
"behaviour",
"bitand",
"Bitonic",
"bsort",
"builtins",
"callcc",
"chumsky",
@ -53,6 +54,7 @@
"linearizing",
"lnet",
"lnil",
"lpthread",
"mult",
"namegen",
"nams",
@ -71,6 +73,7 @@
"powi",
"prec",
"quadtree",
"quadtrees",
"readback",
"recursively",
"redex",
@ -84,6 +87,7 @@
"scons",
"scopeless",
"scrutinee",
"sequentialism",
"snil",
"SOTA",
"stdext",