display

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example (Array)
Display("x", [1]interface{}{3})
Output:

Display x ([1]interface {}):
x[0].type = int
x[0].value = 3
Example (Expr)
e, _ := eval.Parse("sqrt(A / pi)")
Display("e", e)
Output:

Display e (eval.call):
e.fn = "sqrt"
e.args[0].type = eval.binary
e.args[0].value.op = 47
e.args[0].value.x.type = eval.Var
e.args[0].value.x.value = "A"
e.args[0].value.y.type = eval.Var
e.args[0].value.y.value = "pi"
Example (Interface)
var i interface{} = 3
Display("i", i)
Output:

Display i (int):
i = 3
Example (Movie)
// !+movie
type Movie struct {
	Title, Subtitle string
	Year            int
	Color           bool
	Actor           map[string]string
	Oscars          []string
	Sequel          *string
}
// !-movie
// !+strangelove
strangelove := Movie{
	Title:    "Dr. Strangelove",
	Subtitle: "How I Learned to Stop Worrying and Love the Bomb",
	Year:     1964,
	Color:    false,
	Actor: map[string]string{
		"Dr. Strangelove":            "Peter Sellers",
		"Grp. Capt. Lionel Mandrake": "Peter Sellers",
		"Pres. Merkin Muffley":       "Peter Sellers",
		"Gen. Buck Turgidson":        "George C. Scott",
		"Brig. Gen. Jack D. Ripper":  "Sterling Hayden",
		`Maj. T.J. "King" Kong`:      "Slim Pickens",
	},

	Oscars: []string{
		"Best Actor (Nomin.)",
		"Best Adapted Screenplay (Nomin.)",
		"Best Director (Nomin.)",
		"Best Picture (Nomin.)",
	},
}
// !-strangelove
Display("strangelove", strangelove)

// We don't use an Output: comment since displaying
// a map is nondeterministic.
// !+output
// Display strangelove (display.Movie):
// strangelove.Title = "Dr. Strangelove"
// strangelove.Subtitle = "How I Learned to Stop Worrying and Love the Bomb"
// strangelove.Year = 1964
// strangelove.Color = false
// strangelove.Actor["Gen. Buck Turgidson"] = "George C. Scott"
// strangelove.Actor["Brig. Gen. Jack D. Ripper"] = "Sterling Hayden"
// strangelove.Actor["Maj. T.J. \"King\" Kong"] = "Slim Pickens"
// strangelove.Actor["Dr. Strangelove"] = "Peter Sellers"
// strangelove.Actor["Grp. Capt. Lionel Mandrake"] = "Peter Sellers"
// strangelove.Actor["Pres. Merkin Muffley"] = "Peter Sellers"
// strangelove.Oscars[0] = "Best Actor (Nomin.)"
// strangelove.Oscars[1] = "Best Adapted Screenplay (Nomin.)"
// strangelove.Oscars[2] = "Best Director (Nomin.)"
// strangelove.Oscars[3] = "Best Picture (Nomin.)"
// strangelove.Sequel = nil
// !-output
Output:

Example (NilInterface)
var w io.Writer
Display("w", w)
Output:

Display w (<nil>):
w = invalid
Example (PtrToInterface)
var w io.Writer
Display("&w", &w)
Output:

Display &w (*io.Writer):
(*&w) = nil
Example (PtrToInterface2)
var i interface{} = 3
Display("&i", &i)
Output:

Display &i (*interface {}):
(*&i).type = int
(*&i).value = 3
Example (Slice)
Display("slice", []*int{new(int), nil})
Output:

Display slice ([]*int):
(*slice[0]) = 0
slice[1] = nil
Example (Struct)
Display("x", struct{ x interface{} }{3})
Output:

Display x (struct { x interface {} }):
x.x.type = int
x.x.value = 3

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Display

func Display(name string, x interface{})

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL