Overview
gomacro is an almost complete Go interpreter written in pure Go. At its prompt you type Go one statement at a time and see the value of each expression at once, so you can try a part of a program without building the whole of it. It needs no Go compiler to run your code, and it supports generics (experimental), line editing with Tab completion, and a debugger.
For more information on gomacro, you can also check the link below :
For more information of go please refer standard go website:
Why to use gomacro
It helps you learn Go: check how a construct behaves while you are learning it, in a loop of type, read, adjust.
An expression prints its value and its type, for example
42 // int.Packages of the standard library are imported with the usual
import "fmt".
Usage
Type a Go statement at the gomacro> prompt and press Enter. Statements run as soon as they are complete, so a for loop prints its output right away. A statement that is not finished yet (an open brace, bracket or parenthesis) goes on to the next line.
Try it
gomacro> 12+31
{int 43} // untyped.Lit
gomacro> x := 6
gomacro> x * 7
42 // int
gomacro> import "fmt"
gomacro> for i := 0; i < 3; i++ { fmt.Println("Hi:", i) }
Hi: 0
Hi: 1
Hi: 2
gomacro> sq := func(n int) int { return n * n }
gomacro> sq(12)
144 // int
Commands
gomacro also understands some commands that are not part of the Go language. They start with a ":" and can be shortened to their first letters. A few of them:
| Command | Usage |
|---|---|
| :help | List all the commands. |
| :env [NAME] | Show the functions, variables and constants of the current package, or of the imported package NAME. |
| :inspect EXPR | Inspect an expression or a type interactively. |
| :options [OPTS] | Show or toggle the options of the interpreter. |
| :quit | Leave gomacro. |
Limitations
It is an interpreter, so a heavy computation is slower than the same program built with the Go compiler. Use the Run button of the editor to build and run a whole program.
Defining generic functions and types is experimental, and generics of imported packages are not available.
gotocan only jump backward, and conversions from and tounsafe.Pointerare not supported.
References
Further information on golang and gomacro can be found in the links below: