[Feature] Support for user-defined types
- Vorherrschende Sprache
- Rust
- Sterne
- 5.2k
- Forks
- 145
- Ø Merge
- 5 T. 3 Std.
- Gemergte PRs (30 T.)
- 7
Beschreibung
**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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.