github.com/llvm-mirror/llgo@v0.0.0-20190322182713-bf6f0a60fce1/docs/llgoi.rst (about)

     1  =====
     2  llgoi
     3  =====
     4  
     5  Introduction
     6  ============
     7  
     8  llgoi is an interactive REPL for Go. It supports expressions, statements,
     9  most declarations and imports, including binary imports from the standard
    10  library and source imports from ``$GOPATH``.
    11  
    12  Example usage
    13  =============
    14  
    15  .. code-block:: none
    16  
    17    (llgo) 1+1
    18    #0 untyped int = 2
    19    (llgo) x := 1
    20    x untyped int = 1
    21    (llgo) x++
    22    (llgo) x
    23    #0 int = 2
    24    (llgo) import "fmt"
    25    (llgo) fmt.Println("hello world")
    26    hello world
    27    #0 int = 12
    28    #1 error (<nil>) = <nil>
    29    (llgo) for i := 0; i != 3; i++ {
    30           fmt.Println(i)
    31           }
    32    0
    33    1
    34    2
    35    (llgo) func foo() {
    36           fmt.Println("hello decl")
    37           }
    38    (llgo) foo()
    39    hello decl
    40    (llgo) import "golang.org/x/tools/go/types"
    41    # golang.org/x/tools/go/ast/astutil
    42    # golang.org/x/tools/go/exact
    43    # golang.org/x/tools/go/types
    44    (llgo) types.Eval("1+1", nil, nil)
    45    #0 golang.org/x/tools/go/types.TypeAndValue = {mode:4 Type:untyped int Value:2}
    46    #1 error (<nil>) = <nil>
    47  
    48  Expressions
    49  ===========
    50  
    51  Expressions can be evaluated by entering them at the llgoi prompt. The
    52  result of evaluating the expression is displayed as if printed with the
    53  format string ``"%+v"``. If the expression has multiple values (e.g. calls),
    54  each value is displayed separately.
    55  
    56  Declarations
    57  ============
    58  
    59  Declarations introduce new entities into llgoi's scope. For example, entering
    60  ``x := 1`` introduces into the scope a variable named ``x`` with an initial
    61  value of 1. In addition to short variable declarations (i.e. variables declared
    62  with ``:=``), llgoi supports constant declarations, function declarations,
    63  variable declarations and type declarations.
    64  
    65  Imports
    66  =======
    67  
    68  To import a package, enter ``import`` followed by the name of a package
    69  surrounded by quotes. This introduces the package name into llgoi's
    70  scope. The package may be a standard library package, or a source package on
    71  ``$GOPATH``. In the latter case, llgoi will first compile the package and
    72  its dependencies.
    73  
    74  Statements
    75  ==========
    76  
    77  Aside from declarations and expressions, the following kinds of statements
    78  can be evaluated by entering them at the llgoi prompt: IncDec statements,
    79  assignments, go statements, blocks, if statements, switch statements, select
    80  statements and for statements.