Hacker News new | ask | show | jobs
by stefantalpalaru 4033 days ago
> why not a Go implementation in Nim via cross-compilation?

Nim's macros have one limitation that prevents an accurate implementation of another syntax: they can't fully modify the existing syntax.

See how I had to use "scase" inside "select" blocks because the existing "case" keyword insists on having "of" after it. So Nim's semantics put some limits on the amount of hijacking one can inflict on it through macros.

2 comments

I don't believe they should accept the full Golang syntax, just help with the import. E.g.

    macro goImport(path: string): stmt
      // TODO
      discard
    
    goImport("golang.org/x/crypto/nacl/box")
If you front compilation with Go's parser, you could generate bog-standard Nim code from the AST.
You can, but you'd be limiting yourself to pure Go. I'd rather have Go with Nim's generics, transpilation to C, macros, compile time computation, etc.