blob: 51550a459cb69788d5b9060b4cb69a8d82ccb6df [file] [log] [blame]
Rob Pikede1f8562011-08-16 07:51:44 +10001// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5/*
Andrew Gerrand4d3c9992011-11-02 15:03:36 +09006 Package builtin provides documentation for Go's predeclared identifiers.
7 The items documented here are not actually in package builtin
Rob Pikede1f8562011-08-16 07:51:44 +10008 but their descriptions here allow godoc to present documentation
Andrew Gerrand4d3c9992011-11-02 15:03:36 +09009 for the language's special identifiers.
Rob Pikede1f8562011-08-16 07:51:44 +100010*/
11package builtin
12
Rob Pike7db617b2011-11-02 12:06:36 -070013// bool is the set of boolean values, true and false.
14type bool bool
15
Robert Griesemer8457afb2013-04-18 14:36:08 -070016// true and false are the two untyped boolean values.
17const (
18 true = 0 == 0 // Untyped bool.
19 false = 0 != 0 // Untyped bool.
20)
21
Andrew Gerrand1c530d52011-11-03 14:52:38 +110022// uint8 is the set of all unsigned 8-bit integers.
Rob Pike7db617b2011-11-02 12:06:36 -070023// Range: 0 through 255.
24type uint8 uint8
25
26// uint16 is the set of all unsigned 16-bit integers.
27// Range: 0 through 65535.
28type uint16 uint16
29
30// uint32 is the set of all unsigned 32-bit integers.
31// Range: 0 through 4294967295.
32type uint32 uint32
33
34// uint64 is the set of all unsigned 64-bit integers.
35// Range: 0 through 18446744073709551615.
36type uint64 uint64
37
Andrew Gerrand1c530d52011-11-03 14:52:38 +110038// int8 is the set of all signed 8-bit integers.
Rob Pike7db617b2011-11-02 12:06:36 -070039// Range: -128 through 127.
40type int8 int8
41
42// int16 is the set of all signed 16-bit integers.
43// Range: -32768 through 32767.
44type int16 int16
45
46// int32 is the set of all signed 32-bit integers.
47// Range: -2147483648 through 2147483647.
48type int32 int32
49
50// int64 is the set of all signed 64-bit integers.
51// Range: -9223372036854775808 through 9223372036854775807.
52type int64 int64
53
54// float32 is the set of all IEEE-754 32-bit floating-point numbers.
55type float32 float32
56
57// float64 is the set of all IEEE-754 64-bit floating-point numbers.
58type float64 float64
59
60// complex64 is the set of all complex numbers with float32 real and
61// imaginary parts.
62type complex64 complex64
63
64// complex128 is the set of all complex numbers with float64 real and
65// imaginary parts.
66type complex128 complex128
67
68// string is the set of all strings of 8-bit bytes, conventionally but not
69// necessarily representing UTF-8-encoded text. A string may be empty, but
70// not nil. Values of string type are immutable.
71type string string
72
73// int is a signed integer type that is at least 32 bits in size. It is a
74// distinct type, however, and not an alias for, say, int32.
75type int int
76
77// uint is an unsigned integer type that is at least 32 bits in size. It is a
78// distinct type, however, and not an alias for, say, uint32.
79type uint uint
80
81// uintptr is an integer type that is large enough to hold the bit pattern of
82// any pointer.
83type uintptr uintptr
84
85// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
86// used, by convention, to distinguish byte values from 8-bit unsigned
87// integer values.
88type byte byte
89
Anthony Eufemioe8de8b52012-09-18 11:01:10 -070090// rune is an alias for int32 and is equivalent to int32 in all ways. It is
Rob Pike7db617b2011-11-02 12:06:36 -070091// used, by convention, to distinguish character values from integer values.
Rob Pike7db617b2011-11-02 12:06:36 -070092type rune rune
93
Rob Pike02b75502013-03-26 11:05:06 -070094// iota is a predeclared identifier representing the untyped integer ordinal
95// number of the current const specification in a (usually parenthesized)
96// const declaration. It is zero-indexed.
97const iota = 0 // Untyped int.
98
99// nil is a predeclared identifier representing the zero value for a
100// pointer, channel, func, interface, map, or slice type.
101var nil Type // Type must be a pointer, channel, func, interface, map, or slice type
102
Rob Pikede1f8562011-08-16 07:51:44 +1000103// Type is here for the purposes of documentation only. It is a stand-in
104// for any Go type, but represents the same type for any given function
105// invocation.
106type Type int
107
Rob Pikee99f68f2011-11-09 10:49:41 -0800108// Type1 is here for the purposes of documentation only. It is a stand-in
109// for any Go type, but represents the same type for any given function
110// invocation.
111type Type1 int
112
Rob Pikede1f8562011-08-16 07:51:44 +1000113// IntegerType is here for the purposes of documentation only. It is a stand-in
114// for any integer type: int, uint, int8 etc.
115type IntegerType int
116
117// FloatType is here for the purposes of documentation only. It is a stand-in
118// for either float type: float32 or float64.
Rob Pike7db617b2011-11-02 12:06:36 -0700119type FloatType float32
Rob Pikede1f8562011-08-16 07:51:44 +1000120
121// ComplexType is here for the purposes of documentation only. It is a
122// stand-in for either complex type: complex64 or complex128.
Rob Pike7db617b2011-11-02 12:06:36 -0700123type ComplexType complex64
Rob Pikede1f8562011-08-16 07:51:44 +1000124
125// The append built-in function appends elements to the end of a slice. If
126// it has sufficient capacity, the destination is resliced to accommodate the
127// new elements. If it does not, a new underlying array will be allocated.
128// Append returns the updated slice. It is therefore necessary to store the
129// result of append, often in the variable holding the slice itself:
130// slice = append(slice, elem1, elem2)
131// slice = append(slice, anotherSlice...)
Rob Pikef12796e2013-02-27 16:11:17 -0800132// As a special case, it is legal to append a string to a byte slice, like this:
133// slice = append([]byte("hello "), "world"...)
Rob Pikede1f8562011-08-16 07:51:44 +1000134func append(slice []Type, elems ...Type) []Type
135
136// The copy built-in function copies elements from a source slice into a
137// destination slice. (As a special case, it also will copy bytes from a
138// string to a slice of bytes.) The source and destination may overlap. Copy
139// returns the number of elements copied, which will be the minimum of
140// len(src) and len(dst).
141func copy(dst, src []Type) int
142
Rob Pikee99f68f2011-11-09 10:49:41 -0800143// The delete built-in function deletes the element with the specified key
Jingcheng Zhang0b50a5d2012-12-14 09:13:42 -0800144// (m[key]) from the map. If m is nil or there is no such element, delete
145// is a no-op.
Rob Pikee99f68f2011-11-09 10:49:41 -0800146func delete(m map[Type]Type1, key Type)
147
Rob Pikede1f8562011-08-16 07:51:44 +1000148// The len built-in function returns the length of v, according to its type:
149// Array: the number of elements in v.
Rob Pike43d63892011-08-16 15:24:00 +1000150// Pointer to array: the number of elements in *v (even if v is nil).
151// Slice, or map: the number of elements in v; if v is nil, len(v) is zero.
Rob Pikede1f8562011-08-16 07:51:44 +1000152// String: the number of bytes in v.
Rob Pike43d63892011-08-16 15:24:00 +1000153// Channel: the number of elements queued (unread) in the channel buffer;
154// if v is nil, len(v) is zero.
Rob Pikede1f8562011-08-16 07:51:44 +1000155func len(v Type) int
156
157// The cap built-in function returns the capacity of v, according to its type:
158// Array: the number of elements in v (same as len(v)).
159// Pointer to array: the number of elements in *v (same as len(v)).
Rob Pike43d63892011-08-16 15:24:00 +1000160// Slice: the maximum length the slice can reach when resliced;
161// if v is nil, cap(v) is zero.
162// Channel: the channel buffer capacity, in units of elements;
163// if v is nil, cap(v) is zero.
Rob Pikede1f8562011-08-16 07:51:44 +1000164func cap(v Type) int
165
166// The make built-in function allocates and initializes an object of type
167// slice, map, or chan (only). Like new, the first argument is a type, not a
168// value. Unlike new, make's return type is the same as the type of its
169// argument, not a pointer to it. The specification of the result depends on
170// the type:
171// Slice: The size specifies the length. The capacity of the slice is
172// equal to its length. A second integer argument may be provided to
173// specify a different capacity; it must be no smaller than the
174// length, so make([]int, 0, 10) allocates a slice of length 0 and
175// capacity 10.
176// Map: An initial allocation is made according to the size but the
177// resulting map has length 0. The size may be omitted, in which case
178// a small starting size is allocated.
179// Channel: The channel's buffer is initialized with the specified
180// buffer capacity. If zero, or the size is omitted, the channel is
181// unbuffered.
182func make(Type, size IntegerType) Type
183
184// The new built-in function allocates memory. The first argument is a type,
185// not a value, and the value returned is a pointer to a newly
186// allocated zero value of that type.
187func new(Type) *Type
188
189// The complex built-in function constructs a complex value from two
190// floating-point values. The real and imaginary parts must be of the same
191// size, either float32 or float64 (or assignable to them), and the return
192// value will be the corresponding complex type (complex64 for float32,
193// complex128 for float64).
194func complex(r, i FloatType) ComplexType
195
196// The real built-in function returns the real part of the complex number c.
197// The return value will be floating point type corresponding to the type of c.
198func real(c ComplexType) FloatType
199
Rob Pikee99f68f2011-11-09 10:49:41 -0800200// The imag built-in function returns the imaginary part of the complex
Rob Pikede1f8562011-08-16 07:51:44 +1000201// number c. The return value will be floating point type corresponding to
202// the type of c.
203func imag(c ComplexType) FloatType
204
205// The close built-in function closes a channel, which must be either
206// bidirectional or send-only. It should be executed only by the sender,
207// never the receiver, and has the effect of shutting down the channel after
208// the last sent value is received. After the last value has been received
Rob Pike00dd2b42011-08-16 16:03:30 +1000209// from a closed channel c, any receive from c will succeed without
210// blocking, returning the zero value for the channel element. The form
Rob Pikede1f8562011-08-16 07:51:44 +1000211// x, ok := <-c
Rob Pike00dd2b42011-08-16 16:03:30 +1000212// will also set ok to false for a closed channel.
Rob Pikede1f8562011-08-16 07:51:44 +1000213func close(c chan<- Type)
214
215// The panic built-in function stops normal execution of the current
216// goroutine. When a function F calls panic, normal execution of F stops
217// immediately. Any functions whose execution was deferred by F are run in
218// the usual way, and then F returns to its caller. To the caller G, the
219// invocation of F then behaves like a call to panic, terminating G's
220// execution and running any deferred functions. This continues until all
221// functions in the executing goroutine have stopped, in reverse order. At
222// that point, the program is terminated and the error condition is reported,
223// including the value of the argument to panic. This termination sequence
224// is called panicking and can be controlled by the built-in function
225// recover.
226func panic(v interface{})
227
228// The recover built-in function allows a program to manage behavior of a
229// panicking goroutine. Executing a call to recover inside a deferred
230// function (but not any function called by it) stops the panicking sequence
231// by restoring normal execution and retrieves the error value passed to the
232// call of panic. If recover is called outside the deferred function it will
233// not stop a panicking sequence. In this case, or when the goroutine is not
234// panicking, or if the argument supplied to panic was nil, recover returns
235// nil. Thus the return value from recover reports whether the goroutine is
236// panicking.
237func recover() interface{}
Andrew Gerrand4d3c9992011-11-02 15:03:36 +0900238
Robert Griesemerc7065e92013-07-09 16:20:19 -0700239// The print built-in function formats its arguments in an implementation-
240// specific way and writes the result to standard error.
241// Print is useful for bootstrapping and debugging; it is not guaranteed
242// to stay in the language.
243func print(args ...Type)
244
245// The println built-in function formats its arguments in an implementation-
246// specific way and writes the result to standard error.
247// Spaces are always added between arguments and a newline is appended.
248// Println is useful for bootstrapping and debugging; it is not guaranteed
249// to stay in the language.
250func println(args ...Type)
251
Andrew Gerrand4d3c9992011-11-02 15:03:36 +0900252// The error built-in interface type is the conventional interface for
253// representing an error condition, with the nil value representing no error.
254type error interface {
255 Error() string
256}