Using Go packages
Until Xo has its own ecosystem, any Go package is one line away:
gointerop/main.xo
use go "strings"
use go "net/url"
fn main(os: Os) ! {
os.stdio.println(strings.to_upper("hello from go"))
let u = url.parse("https://xolang.dev/docs?tab=tour")?
os.stdio.println("${u.hostname()} ${u.query().get("tab")}")
}Output:
HELLO FROM GO
xolang.dev tour
xo check,build,run, andtestgenerate the bindings themselves.- Names follow Xo’s style:
ToUpperisto_upper. - Go’s
(T, error)becomesT ! go.Error, sourl.parse(...)?works like any Xo call, and a pointer that may be nil becomesT?. - Every call into Go performs the
goeffect. Go code can reach files and the network without a capability, so apubfunction that calls Go must sayuses go, and that escape stays visible in signatures.
Native builds can call C the same way with use c "header.h"; see section
4.5 of the specification.
That is the tour. The specification covers everything in full, and the diagnostics reference explains every error code.