r

rite

cf73b1dlibrary

No description provided.

0 stars0 forksUnknownupdated 2 years ago
Open repo

The Rite Programming Language

WIP

It's gonna be like if Odin and JavaScript had a baby. Main use of the language is data transformation, that can be embedded into games or spreadsheets. Because for these things, I haven't found the rite language yet.

Sample code:

Person :: {
    name: string
    age: int
}
p := Person{name: "Tom", age: 45}
people : [Person] = [{"Hans", 23}, {"Claus", 12}]
people.push({"Maria", 12})


PI :: 3.14
Vec2 :: {x: float, y: float}
cross :: (a: Vec2, b: Vec2) -> float {return a.x*b.y - a.y*b.x}

Circle :: {radius: float}
Rectangle :: {a: float, b: float}
Polygon :: {outline : [Vec2]}

// union of different types
Shape :: Circle | Rectangle | Polygon

area :: (shape: Shape) -> float {
    switch shape {
        case Circle: return shape.radius.squared() * PI
        case Rectangle: return shape.a * shape.b
        case Polygon: return shape.outline.area() // see function below
    }
}

area :: (outline: [Vec2]) -> float {
    n := outline.len
    if n < 3 { return 0 }
    sum := 0
    for i in n {
        sum += outline[i].cross(outline[(i + 1) % n])
    }
    return sum
}

shapes := [Circle{3}, Rect{4,5}, Polygon{ouline: [{1,2}, {5,4}, {0,8}, {-2,4}]}]

// print all shapes that are a circle or have a large area:
shapes.filter(_.area() > 10 || _ is Circle).print()
Package Info
Version
cf73b1d
License
Unknown
Author
@tadeohepperle
Type
library
Forks
0
Created
2 years ago
Updated
2 years ago
Health
maintained
has releases
has readme
has license
Activity
last 56 weeks