GSET
Targets

Go Target

The default intermediate representation — package main, func main, and the typing rules you must follow.

Implemented

Go is GSET's default intermediate representation: .gset files default to the Go target, gset run hello.gset works out of the box, and go is what gset transpile produces unless you pass --target.

The generated file is a complete runnable Go program:

package main
import "fmt"

func main() {
    var name = "World"
    var count = 3
    fmt.Println("Hello, " + name)
    for count > 0 {
        fmt.Println(count)
        count = count - 1
    }
}

Mapping table

GSETGo output
var x = …var x = …
assignment x = …x = … (needs prior var)
while cond {}for cond {}
foreach i, v in arr {}for i, v := range arr {}
for clsfor i := 0; i < n; i++ {}
arrays [1, 2][]interface{}{1, 2}
maps {"a": 1}map[string]interface{}{"a": 1}
functionsfunc returning interface{}
try/catch❌ not supported — Go has no exceptions
true/nulltrue/nil

The three rules that keep Go output valid

  1. Always var-declare before use. x = 42 alone → undefined: x. Every dynamic-looking program must declare: var x = 42.
  2. Type your arithmetic or keep it out of Go. var n = n * n on an interface yields invalid operation: n * n (operator * not defined on interface{}). Use typed annotations: var n int = 5.
  3. Parameterize functions with types. function square(n) { return n * n } fails to compile in Go; function square(n int) int does not.

Verified example

var name = "World"
var count = 3
print("Hello, " + name)
while count > 0 {
    print(count)
    count = count - 1
}
$ gset run hello.gset
Hello, World
3
2
1

Watch out

  • fmt import is automatic. Any print-alias or string containing fmt-mapped names triggers import "fmt". You don't add imports.
  • Array print format. print([1, 2, 3]) prints Go's [1 2 3] (space-separated, no commas) — inherent to fmt.Println, differs from Python/JS.
  • No exceptions. try/catch emits Go-invalid try {. Keep try blocks only for non-Go targets.
  • Types live only in typed annotations. GSET is dynamically typed; Go output mirrors whatever you typed explicitly.

On this page