borgo-lang / borgo

Borgo is a statically typed language that compiles to Go.
https://borgo-lang.github.io
3.68k stars 50 forks source link

Suggestion : Get inspiration from Go+ (aka Goplus) #23

Open serge-hulne opened 5 months ago

serge-hulne commented 5 months ago

Here's the link to the Go+ project.

https://github.com/goplus/gop?tab=readme-ov-file

alpacaaa commented 5 months ago

Inspiration on what?

serge-hulne commented 5 months ago

On a multitude of features:

type MyBigInt struct { *big.Int }

func Int(v *big.Int) MyBigInt { return MyBigInt{v} }

func (a MyBigInt) + (b MyBigInt) MyBigInt { // binary operator return MyBigInt{new(big.Int).Add(a.Int, b.Int)} }

func (a MyBigInt) += (b MyBigInt) { a.Int.Add(a.Int, b.Int) }

func -(a MyBigInt) MyBigInt { // unary operator return MyBigInt{new(big.Int).Neg(a.Int)} }

a := Int(1r) a += Int(2r) println a + Int(3r) println -a


- List comprehension

a := [xx for x <- [1, 3, 5, 7, 11]] b := [xx for x <- [1, 3, 5, 7, 11] if x > 3] c := [i+v for i, v <- [1, 3, 5, 7, 11] if i%2 == 1]

arr := [1, 2, 3, 4, 5, 6] d := [[a, b] for a <- arr if a < b for b <- arr if b > 2]

x := {x: i for i, x <- [1, 3, 5, 7, 11]} y := {x: i for i, x <- [1, 3, 5, 7, 11] if i%2 == 1} z := {v: k for k, v <- {1: "Hello", 3: "Hi", 5: "xsw", 7: "Go+"} if k > 3}


- Unix shebang

!/usr/bin/env -S gop run

println "Hello, Go+"

println 1r << 129 println 1/3r + 2/7r*2

arr := [1, 3, 5, 7, 11, 13, 17, 19] println arr println [x*x for x <- arr, x > 3]

m := {"Hi": 1, "Go+": 2} println m println {v: k for k, v <- m} println [k for k, _ <- m] println [v for v <- m]