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
| GSET | Go 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 cls | for i := 0; i < n; i++ {} |
arrays [1, 2] | []interface{}{1, 2} |
maps {"a": 1} | map[string]interface{}{"a": 1} |
| functions | func returning interface{} |
try/catch | ❌ not supported — Go has no exceptions |
true/null | true/nil |
The three rules that keep Go output valid
- Always
var-declare before use.x = 42alone →undefined: x. Every dynamic-looking program must declare:var x = 42. - Type your arithmetic or keep it out of Go.
var n = n * non an interface yieldsinvalid operation: n * n (operator * not defined on interface{}). Use typed annotations:var n int = 5. - Parameterize functions with types.
function square(n) { return n * n }fails to compile in Go;function square(n int) intdoes 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
1Watch out
fmtimport is automatic. Anyprint-alias or string containingfmt-mapped names triggersimport "fmt". You don't add imports.- Array print format.
print([1, 2, 3])prints Go's[1 2 3](space-separated, no commas) — inherent tofmt.Println, differs from Python/JS. - No exceptions.
try/catchemits Go-invalidtry {. Keeptryblocks only for non-Go targets. - Types live only in typed annotations. GSET is dynamically typed; Go output mirrors whatever you typed explicitly.