amber-lang / amber-lang/amber

[Feature] Support for user-defined types

Abierto
#583 3 comentarios 0 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Rust
Estrellas
5.2k
Forks
145
Merge medio
5 d 3 h
PR fusionados (30 d)
7

Descripción

**Problem description.**
Bash is quite useful in sequential data processing until there are complex data structures
**Solution**
We can improve this in Amber by adding user-defined types that will be converted by compiler to a format compatible with tools like sort, tee and awk. For example
```rust
struct TimeStamp{
hours: Int
minutes: Int
seconds: Int
}

struct Coords{
x: Float
y: Float
s: TimeStamp
}

let t1 = {12, 18, 50} : TimeStamp
let c1 = {50.0, 30.2, t1} : Coords
```
Converts to:
```bash
Coords.x Coords.y Coords.TimeStamp.hours Coords.TimeStamp.minutes Coords.TimeStamp.seconds
50.0 30.2 12 18 50
```

Using a list of UserTypes we can define some data processing functions that will be converted to sequence of bash commands behind the scene.
```rust
let t2 = {12, 43, 10} : TimeStamp
let c2 = {40.0, 50.1, t2} : Coords
let coordsArr = [c1, c2]
```
Lets find the coord with max X coordinate
```rust
let coord = max(Coords.x, coordsArr)
```
Will be converted to
```bash
echo "data in format above" | sort -n | tail -1
```

**Alternatives**
[This](https://github.com/amber-lang/amber/issues/80) issue suggests another way of solving the problem, though I think sequential data processing will be a more common usage in Amber. That's why I would like to propose this format for user-defined types

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.