AI prompts
base on Borgo is a statically typed language that compiles to Go. # The Borgo Programming Language
![Borgo sits between Go and Rust](https://raw.githubusercontent.com/borgo-lang/borgo-lang.github.io/main/borgo.jpg)
---
![build](https://github.com/borgo-lang/borgo/actions/workflows/ci.yml/badge.svg)
I want a language for writing applications that is more expressive than Go but
less complex than Rust.
Go is simple and straightforward, but I often wish it offered more type safety.
Rust is very nice to work with (at least for single threaded code) but it's too
broad and complex, sometimes painfully so.
**Borgo is a new language that transpiles to Go**. It's fully compatible with
existing Go packages.
Borgo syntax is similar to Rust, with optional semi-colons.
# Tutorial
Check out the **[online playground](https://borgo-lang.github.io/)** for a tour
of the language.
You can also take a look at test files for working Borgo code:
- [codegen-emit.md](compiler/test/codegen-emit.md)
- [infer-expr.md](compiler/test/infer-expr.md)
- [infer-file.md](compiler/test/infer-file.md)
# Features
## Algebraic data types and pattern matching
```rust
use fmt
enum NetworkState {
Loading,
Failed(int),
Success(string),
}
let msg = match state {
NetworkState.Loading => "still loading",
NetworkState.Failed(code) => fmt.Sprintf("Got error code: %d", code),
NetworkState.Success(res) => res,
}
```
---
## `Option<T>` instead of `nil`
```rust
// import packages from Go stdlib
use fmt
use os
let key = os.LookupEnv("HOME")
match key {
Some(s) => fmt.Println("home dir:", s),
None => fmt.Println("Not found in env"),
}
```
---
## `Result<T, E>` instead of multiple return values
```rust
use fmt
use net.http
fn makeRequest() -> Result<int, error> {
let request = http.Get("http://example.com")
match request {
Ok(resp) => Ok(resp.StatusCode),
Err(err) => Err(fmt.Errorf("failed http request %w", err))
}
}
```
---
## Error handling with `?` operator
```rust
use fmt
use io
use os
fn copyFile(src: string, dst: string) -> Result<(), error> {
let stat = os.Stat(src)?
if !stat.Mode().IsRegular() {
return Err(fmt.Errorf("%s is not a regular file", src))
}
let source = os.Open(src)?
defer source.Close()
let destination = os.Create(dst)?
defer destination.Close()
// ignore number of bytes copied
let _ = io.Copy(destination, source)?
Ok(())
}
```
---
## Guessing game example
Small game from the Rust book, implemented in Borgo.
Things to note:
- import packages from Go stdlib
- `strconv.Atoi` returns an `Option<int>`
- `Reader.ReadString` returns a `Result<string, error>` (which can be unwrapped)
```rust
use bufio
use fmt
use math.rand
use os
use strconv
use strings
fn main() {
let reader = bufio.NewReader(os.Stdin)
let secret = rand.Intn(100) + 1
loop {
fmt.Println("Please input your guess.")
let text = reader.ReadString('\n').Unwrap()
let text = strings.TrimSpace(text)
let guess = match strconv.Atoi(text) {
Ok(n) => n,
Err(_) => continue,
}
fmt.Println("You guessed: ", guess)
if guess < secret {
fmt.Println("Too small!")
} else if guess > secret {
fmt.Println("Too big!")
} else {
fmt.Println("Correct!")
break
}
}
}
```
## Running locally
Borgo is written in Rust, so you'll need `cargo`.
To compile all `.brg` files in the current folder:
```bash
$ cargo run -- build
```
The compiler will generate `.go` files, which you can run as normal:
```bash
# generate a go.mod file if needed
# $ go mod init foo
$ go run .
```
", Assign "at most 3 tags" to the expected json: {"id":"9827","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"