Go Concepts - Lexical Structure: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 72: Line 72:
| <tt>[[go Keyword range|range]]</tt> || <tt>[[go Keyword type|type]]</tt> || <tt>[[go Keyword func|func]]</tt> || . || .
| <tt>[[go Keyword range|range]]</tt> || <tt>[[go Keyword type|type]]</tt> || <tt>[[go Keyword func|func]]</tt> || . || .
|-
|-
|  <tt>[[go Keyword package|package]]</tt> || <tt>[[go Keyword go|go]]</tt> || . || . || .
|  <tt>[[Go Concepts - Packages#The_package_keyword|package]]</tt> || <tt>[[go Keyword go|go]]</tt> || . || . || .
|-
|-
| <tt>[[go Keyword defer|defer]]</tt> || <tt>[[go Keyword chan|chan]]</tt> || . || . || .
| <tt>[[go Keyword defer|defer]]</tt> || <tt>[[go Keyword chan|chan]]</tt> || . || . || .
Line 115: Line 115:
=Code Base Structure=
=Code Base Structure=


Code file. Each code file contains the <tt>[[Go Keyword package|package]]</tt> keyword.
Code file. Each code file contains the <tt>[[Go Concepts - Packages#The_package_keyword|package]]</tt> keyword.


=Package=
=Package=

Revision as of 02:47, 22 March 2016

Internal


Operators

Identifiers

Types, functions, constants, variables, interfaces.

The blank identifier "_".

Identifiers (not values) can be exported or unexported.

Lower-case letter identifiers

Upper-case letter identifiers


Whitespace

Newlines, spaces and tabs.

Expression

Operators combine operands into expressions.

Literal

String Literal

Numeric Literal

Array Literal

Slice Literal

Map Literal

Struct Literal

Comment

// to the end of the line
/*
  Multiline
  line 1
  ...
  line n
*/

Statements

for

if

Keywords

range type func . .
package go . . .
defer chan . . .

Constants

Variables

Variables are always initialized to the type's zero value.


  var <var-name> <type> = <initial-value>

  var a string = "blah"


  <var-name> := <initial-value>

   a := "blah"

Variable Scopes

Package-level variable

Pass by Value vs Pass by Reference

In Go, all variables are passed by value. Even for pointer variables, since the value of the pointer is a memory address, passing pointer variables is still considered pass by value.

Pointers

Pointer variable.


Code Base Structure

Code file. Each code file contains the package keyword.

Package

package mypackage