Discuss Scratch

Redstone1080
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

If it's written in Gleam, then you can run it in the browser, because Gleam can compile to JavaScript, right? If so I'm going to write a Splatoon 3 custom weapon+kit maker in Bella :D
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

Redstone1080 wrote:

If it's written in Gleam, then you can run it in the browser, because Gleam can compile to JavaScript, right? If so I'm going to write a Splatoon 3 custom weapon+kit maker in Bella :D
It uses some Deno APIs, but it wouldn't be hard to port to the browser.
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

I opted for `first` and `rest` builtins for the head and tail of a list instead of adding new syntax. I also added another overload to `+` for combining two lists together.
let
mylist =
[1, 2, 3, 4, 5, 6, 7, 8, 9]

map =
list -> fn ->
if (list == [])
[]
else
[first(list) |> fn] + map(rest(list), fn)

reduce =
list -> acc -> fn ->
if (list == [])
acc
else
reduce(rest(list), fn(first(list), acc), fn)

fold =
list -> fn ->
reduce(rest(list), first(list), fn)
in
(
; Squares
map(mylist, x -> x * x) |> print

; Sum
fold(mylist, x -> a -> x + a) |> print

; Length
reduce(mylist, 0, x -> a -> a + 1) |> print
)
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

This has existed for a while (forgot to post it here), but you can import other modules when inside a project.

src/my_project.bella
import thing1
import folder/thing2
import thing3 as another_thing

print(thing1 + thing2 + another_thing)
; Outputs the number 6

src/thing1.bella
1

src/folder/thing2.bella
2

src/thing3.bella
3
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

I'm kind of stuck on ideas for the moment (other than pattern matching, which I can't seem to get out of my head ). Does anyone have something they want added to Bella?

Last edited by NFlex23 (June 19, 2023 11:44:18)

WojtekGame
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

NFlex23 wrote:

I'm kind of stuck on ideas for the moment (other than pattern matching, which I can't seem to get out of my head ). Does anyone have something they want added to Bella?
is there Regex in Bella?
and DOCS?
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

WojtekGame wrote:

NFlex23 wrote:

I'm kind of stuck on ideas for the moment (other than pattern matching, which I can't seem to get out of my head ). Does anyone have something they want added to Bella?
is there Regex in Bella?
and DOCS?
Sorry for the late reply!
Bella doesn't have regex yet, but that would be a great addition to the builtin functions! I might add that in the future. As for documentation, examples are what I've got so far: https://github.com/MystPi/bella/tree/main/examples
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

I've been working on VS Code syntax highlighting for Bella. Here's what it looks like so far:



There isn't a language server or anything, just a bunch of clever regexes… including this abomination:
{
  "name": "entity.name.function",
  "match": "\\b[a-zA-Z_]\\w*\\b(?=\\s*\\()|(?<=\\|>\\s*(?:(?:[a-zA-Z_]\\w*\\s*\\.\\s*)*)?)\\b[a-zA-Z_]\\w*\\b(?!\\s*\\.)"
}
rdococ
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

A dynamically typed functional lang… intriguing. Most of the time I've spent in the programming world is with OOP languages, so it would be interesting to try this and see how it differs.

However, I feel like I should point out that ‘print’ is a side effect
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

rdococ wrote:

A dynamically typed functional lang… intriguing. Most of the time I've spent in the programming world is with OOP languages, so it would be interesting to try this and see how it differs.

However, I feel like I should point out that ‘print’ is a side effect
Yeah, it's not entirely free from side effects (nor is the language I made it in, Gleam). I'm still hoping to add some sort of type system eventually, but right now that would be a ton of work.
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

I'm also working on improving runtime error messages with positions:
✕ error: runtime error
┌─ examples/test.bella:9:15

9 │ Io.println(me.namee)
│ ~~~~~


? Record has no `namee` field
✕ error: runtime error
┌─ examples/test.bella:1:7

1 │ 5 / 2 * "Hi"
│ ~


? Operands of * must be numbers
✕ error: runtime error
┌─ examples/test.bella:1:7

1 │ "blah"()
│ ~~


? `"blah"` cannot be called
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

The VS Code extension is now available to install: https://marketplace.visualstudio.com/items?itemName=mystpi.bella-lang
W1-F1
Scratcher
100+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

NFlex23 wrote:

The VS Code extension is now available to install: https://marketplace.visualstudio.com/items?itemName=mystpi.bella-lang
That's really cool! Nice job!
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

W1-F1 wrote:

NFlex23 wrote:

The VS Code extension is now available to install: https://marketplace.visualstudio.com/items?itemName=mystpi.bella-lang
That's really cool! Nice job!
Thank you!
uwv
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

would it be possible to add some form of ffi? im not sure if that already exists or how you do builtins or anything. just a thought
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

uwv wrote:

would it be possible to add some form of ffi? im not sure if that already exists or how you do builtins or anything. just a thought
I've been thinking about how to do that for a while now. Haven't come up with anything great yet unfortunately.
ajskateboarder
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

NFlex23 wrote:

uwv wrote:

would it be possible to add some form of ffi? im not sure if that already exists or how you do builtins or anything. just a thought
I've been thinking about how to do that for a while now. Haven't come up with anything great yet unfortunately.
You could add support for a JS FFI-ish by including JavaScript in Bella code and compiling said Bella code to JavaScript at runtime
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

ajskateboarder wrote:

NFlex23 wrote:

uwv wrote:

would it be possible to add some form of ffi? im not sure if that already exists or how you do builtins or anything. just a thought
I've been thinking about how to do that for a while now. Haven't come up with anything great yet unfortunately.
You could add support for a JS FFI-ish by including JavaScript in Bella code and compiling said Bella code to JavaScript at runtime
Bella is interpreted, not compiled. However, since Gleam compiles to JavaScript I could dynamically import JavaScript files during runtime (via something like `await import`). I'm just trying to think of the best way to do this.
W1-F1
Scratcher
100+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

My text adventure game! Took me 10 minutes to make.

Io.println("Hello, " + Io.readline("What is your name?"))
Io.println("You need to find your way home, you can go left or right.")
if (Io.readline("Enter your option:") == "left")
Io.println("You fell and broke your leg. Game over.")

else if (Io.readline("Enter your option:") == "right")
Io.println("You made it home! Congrats!")
else (
Io.println("Please enter a valid option!")
)
NFlex23
Scratcher
1000+ posts

Bella ⌁ A simple functional programming language ⌁ Written in Gleam!

W1-F1 wrote:

My text adventure game! Took me 10 minutes to make.

Io.println("Hello, " + Io.readline("What is your name?"))
Io.println("You need to find your way home, you can go left or right.")
if (Io.readline("Enter your option:") == "left")
Io.println("You fell and broke your leg. Game over.")

else if (Io.readline("Enter your option:") == "right")
Io.println("You made it home! Congrats!")
else (
Io.println("Please enter a valid option!")
)
Very nice!

As a side note, you don't need the parenthesis after the final `else`.

Powered by DjangoBB