Reserved words
Go keeps a set of words for its own syntax, so a program cannot use them as names. When a Program
name collides with one, the renderer appends a single underscore — type becomes
type_ — so the program keeps the name it chose and the output still compiles.
Because _ is illegal in a Program identifier, the escape can never collide with a name a
program actually chose.
Contents
How a Program becomes Go, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Go target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Go it renders to.
- Naming considerations — how Program's dotted names are carried into Go.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Go behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Go.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Go keeps for itself, and how a colliding name is escaped.
The full list
Every word Go reserves, with the identifier a colliding Program name is escaped to. The rule is
uniform — append a single _:
| Reserved word | Rendered identifier |
|---|---|
break | break_ |
case | case_ |
chan | chan_ |
const | const_ |
continue | continue_ |
default | default_ |
defer | defer_ |
else | else_ |
fallthrough | fallthrough_ |
for | for_ |
func | func_ |
go | go_ |
goto | goto_ |
if | if_ |
import | import_ |
interface | interface_ |
map | map_ |
package | package_ |
range | range_ |
return | return_ |
select | select_ |
struct | struct_ |
switch | switch_ |
type | type_ |
var | var_ |