diff options
Diffstat (limited to 'devdocs/go/builtin%2Findex.html')
| -rw-r--r-- | devdocs/go/builtin%2Findex.html | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/devdocs/go/builtin%2Findex.html b/devdocs/go/builtin%2Findex.html new file mode 100644 index 00000000..55bc205d --- /dev/null +++ b/devdocs/go/builtin%2Findex.html @@ -0,0 +1,147 @@ +<h1> Package builtin </h1> <ul id="short-nav"> +<li><code>import "builtin"</code></li> +<li><a href="#pkg-overview" class="overviewLink">Overview</a></li> +<li><a href="#pkg-index" class="indexLink">Index</a></li> +</ul> <h2 id="pkg-overview">Overview </h2> <p>Package builtin provides documentation for Go's predeclared identifiers. The items documented here are not actually in package builtin but their descriptions here allow godoc to present documentation for the language's special identifiers. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav"> +<li><a href="#pkg-constants">Constants</a></li> +<li><a href="#pkg-variables">Variables</a></li> +<li><a href="#append">func append(slice []Type, elems ...Type) []Type</a></li> +<li><a href="#cap">func cap(v Type) int</a></li> +<li><a href="#clear">func clear[T ~[]Type | ~map[Type]Type1](t T)</a></li> +<li><a href="#close">func close(c chan<- Type)</a></li> +<li><a href="#complex">func complex(r, i FloatType) ComplexType</a></li> +<li><a href="#copy">func copy(dst, src []Type) int</a></li> +<li><a href="#delete">func delete(m map[Type]Type1, key Type)</a></li> +<li><a href="#imag">func imag(c ComplexType) FloatType</a></li> +<li><a href="#len">func len(v Type) int</a></li> +<li><a href="#make">func make(t Type, size ...IntegerType) Type</a></li> +<li><a href="#max">func max[T cmp.Ordered](x T, y ...T) T</a></li> +<li><a href="#min">func min[T cmp.Ordered](x T, y ...T) T</a></li> +<li><a href="#new">func new(Type) *Type</a></li> +<li><a href="#panic">func panic(v any)</a></li> +<li><a href="#print">func print(args ...Type)</a></li> +<li><a href="#println">func println(args ...Type)</a></li> +<li><a href="#real">func real(c ComplexType) FloatType</a></li> +<li><a href="#recover">func recover() any</a></li> +<li><a href="#ComplexType">type ComplexType</a></li> +<li><a href="#FloatType">type FloatType</a></li> +<li><a href="#IntegerType">type IntegerType</a></li> +<li><a href="#Type">type Type</a></li> +<li><a href="#Type1">type Type1</a></li> +<li><a href="#any">type any</a></li> +<li><a href="#bool">type bool</a></li> +<li><a href="#byte">type byte</a></li> +<li><a href="#comparable">type comparable</a></li> +<li><a href="#complex128">type complex128</a></li> +<li><a href="#complex64">type complex64</a></li> +<li><a href="#error">type error</a></li> +<li><a href="#float32">type float32</a></li> +<li><a href="#float64">type float64</a></li> +<li><a href="#int">type int</a></li> +<li><a href="#int16">type int16</a></li> +<li><a href="#int32">type int32</a></li> +<li><a href="#int64">type int64</a></li> +<li><a href="#int8">type int8</a></li> +<li><a href="#rune">type rune</a></li> +<li><a href="#string">type string</a></li> +<li><a href="#uint">type uint</a></li> +<li><a href="#uint16">type uint16</a></li> +<li><a href="#uint32">type uint32</a></li> +<li><a href="#uint64">type uint64</a></li> +<li><a href="#uint8">type uint8</a></li> +<li><a href="#uintptr">type uintptr</a></li> +</ul> <h3>Package files</h3> <p> <span>builtin.go</span> </p> <h2 id="pkg-constants">Constants</h2> <p>true and false are the two untyped boolean values. </p> +<pre data-language="go">const ( + true = 0 == 0 // Untyped bool. + false = 0 != 0 // Untyped bool. +)</pre> <p>iota is a predeclared identifier representing the untyped integer ordinal number of the current const specification in a (usually parenthesized) const declaration. It is zero-indexed. </p> +<pre data-language="go">const iota = 0 // Untyped int. +</pre> <h2 id="pkg-variables">Variables</h2> <p>nil is a predeclared identifier representing the zero value for a pointer, channel, func, interface, map, or slice type. </p> +<pre data-language="go">var nil Type // Type must be a pointer, channel, func, interface, map, or slice type +</pre> <h2 id="append">func <span>append</span> </h2> <pre data-language="go">func append(slice []Type, elems ...Type) []Type</pre> <p>The append built-in function appends elements to the end of a slice. If it has sufficient capacity, the destination is resliced to accommodate the new elements. If it does not, a new underlying array will be allocated. Append returns the updated slice. It is therefore necessary to store the result of append, often in the variable holding the slice itself: </p> +<pre data-language="go">slice = append(slice, elem1, elem2) +slice = append(slice, anotherSlice...) +</pre> <p>As a special case, it is legal to append a string to a byte slice, like this: </p> +<pre data-language="go">slice = append([]byte("hello "), "world"...) +</pre> <h2 id="cap">func <span>cap</span> </h2> <pre data-language="go">func cap(v Type) int</pre> <p>The cap built-in function returns the capacity of v, according to its type: </p> +<pre data-language="go">Array: the number of elements in v (same as len(v)). +Pointer to array: the number of elements in *v (same as len(v)). +Slice: the maximum length the slice can reach when resliced; +if v is nil, cap(v) is zero. +Channel: the channel buffer capacity, in units of elements; +if v is nil, cap(v) is zero. +</pre> <p>For some arguments, such as a simple array expression, the result can be a constant. See the Go language specification's "Length and capacity" section for details. </p> +<h2 id="clear">func <span>clear</span> </h2> <pre data-language="go">func clear[T ~[]Type | ~map[Type]Type1](t T)</pre> <p>The clear built-in function clears maps and slices. For maps, clear deletes all entries, resulting in an empty map. For slices, clear sets all elements up to the length of the slice to the zero value of the respective element type. If the argument type is a type parameter, the type parameter's type set must contain only map or slice types, and clear performs the operation implied by the type argument. </p> +<h2 id="close">func <span>close</span> </h2> <pre data-language="go">func close(c chan<- Type)</pre> <p>The close built-in function closes a channel, which must be either bidirectional or send-only. It should be executed only by the sender, never the receiver, and has the effect of shutting down the channel after the last sent value is received. After the last value has been received from a closed channel c, any receive from c will succeed without blocking, returning the zero value for the channel element. The form </p> +<pre data-language="go">x, ok := <-c +</pre> <p>will also set ok to false for a closed and empty channel. </p> +<h2 id="complex">func <span>complex</span> </h2> <pre data-language="go">func complex(r, i FloatType) ComplexType</pre> <p>The complex built-in function constructs a complex value from two floating-point values. The real and imaginary parts must be of the same size, either float32 or float64 (or assignable to them), and the return value will be the corresponding complex type (complex64 for float32, complex128 for float64). </p> +<h2 id="copy">func <span>copy</span> </h2> <pre data-language="go">func copy(dst, src []Type) int</pre> <p>The copy built-in function copies elements from a source slice into a destination slice. (As a special case, it also will copy bytes from a string to a slice of bytes.) The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum of len(src) and len(dst). </p> +<h2 id="delete">func <span>delete</span> </h2> <pre data-language="go">func delete(m map[Type]Type1, key Type)</pre> <p>The delete built-in function deletes the element with the specified key (m[key]) from the map. If m is nil or there is no such element, delete is a no-op. </p> +<h2 id="imag">func <span>imag</span> </h2> <pre data-language="go">func imag(c ComplexType) FloatType</pre> <p>The imag built-in function returns the imaginary part of the complex number c. The return value will be floating point type corresponding to the type of c. </p> +<h2 id="len">func <span>len</span> </h2> <pre data-language="go">func len(v Type) int</pre> <p>The len built-in function returns the length of v, according to its type: </p> +<pre data-language="go">Array: the number of elements in v. +Pointer to array: the number of elements in *v (even if v is nil). +Slice, or map: the number of elements in v; if v is nil, len(v) is zero. +String: the number of bytes in v. +Channel: the number of elements queued (unread) in the channel buffer; + if v is nil, len(v) is zero. +</pre> <p>For some arguments, such as a string literal or a simple array expression, the result can be a constant. See the Go language specification's "Length and capacity" section for details. </p> +<h2 id="make">func <span>make</span> </h2> <pre data-language="go">func make(t Type, size ...IntegerType) Type</pre> <p>The make built-in function allocates and initializes an object of type slice, map, or chan (only). Like new, the first argument is a type, not a value. Unlike new, make's return type is the same as the type of its argument, not a pointer to it. The specification of the result depends on the type: </p> +<pre data-language="go">Slice: The size specifies the length. The capacity of the slice is +equal to its length. A second integer argument may be provided to +specify a different capacity; it must be no smaller than the +length. For example, make([]int, 0, 10) allocates an underlying array +of size 10 and returns a slice of length 0 and capacity 10 that is +backed by this underlying array. +Map: An empty map is allocated with enough space to hold the +specified number of elements. The size may be omitted, in which case +a small starting size is allocated. +Channel: The channel's buffer is initialized with the specified +buffer capacity. If zero, or the size is omitted, the channel is +unbuffered. +</pre> <h2 id="max">func <span>max</span> </h2> <pre data-language="go">func max[T cmp.Ordered](x T, y ...T) T</pre> <p>The max built-in function returns the largest value of a fixed number of arguments of <span>cmp.Ordered</span> types. There must be at least one argument. If T is a floating-point type and any of the arguments are NaNs, max will return NaN. </p> +<h2 id="min">func <span>min</span> </h2> <pre data-language="go">func min[T cmp.Ordered](x T, y ...T) T</pre> <p>The min built-in function returns the smallest value of a fixed number of arguments of <span>cmp.Ordered</span> types. There must be at least one argument. If T is a floating-point type and any of the arguments are NaNs, min will return NaN. </p> +<h2 id="new">func <span>new</span> </h2> <pre data-language="go">func new(Type) *Type</pre> <p>The new built-in function allocates memory. The first argument is a type, not a value, and the value returned is a pointer to a newly allocated zero value of that type. </p> +<h2 id="panic">func <span>panic</span> </h2> <pre data-language="go">func panic(v any)</pre> <p>The panic built-in function stops normal execution of the current goroutine. When a function F calls panic, normal execution of F stops immediately. Any functions whose execution was deferred by F are run in the usual way, and then F returns to its caller. To the caller G, the invocation of F then behaves like a call to panic, terminating G's execution and running any deferred functions. This continues until all functions in the executing goroutine have stopped, in reverse order. At that point, the program is terminated with a non-zero exit code. This termination sequence is called panicking and can be controlled by the built-in function recover. </p> +<p>Starting in Go 1.21, calling panic with a nil interface value or an untyped nil causes a run-time error (a different panic). The GODEBUG setting panicnil=1 disables the run-time error. </p> +<h2 id="print">func <span>print</span> </h2> <pre data-language="go">func print(args ...Type)</pre> <p>The print built-in function formats its arguments in an implementation-specific way and writes the result to standard error. Print is useful for bootstrapping and debugging; it is not guaranteed to stay in the language. </p> +<h2 id="println">func <span>println</span> </h2> <pre data-language="go">func println(args ...Type)</pre> <p>The println built-in function formats its arguments in an implementation-specific way and writes the result to standard error. Spaces are always added between arguments and a newline is appended. Println is useful for bootstrapping and debugging; it is not guaranteed to stay in the language. </p> +<h2 id="real">func <span>real</span> </h2> <pre data-language="go">func real(c ComplexType) FloatType</pre> <p>The real built-in function returns the real part of the complex number c. The return value will be floating point type corresponding to the type of c. </p> +<h2 id="recover">func <span>recover</span> </h2> <pre data-language="go">func recover() any</pre> <p>The recover built-in function allows a program to manage behavior of a panicking goroutine. Executing a call to recover inside a deferred function (but not any function called by it) stops the panicking sequence by restoring normal execution and retrieves the error value passed to the call of panic. If recover is called outside the deferred function it will not stop a panicking sequence. In this case, or when the goroutine is not panicking, recover returns nil. </p> +<p>Prior to Go 1.21, recover would also return nil if panic is called with a nil argument. See [panic] for details. </p> +<h2 id="ComplexType">type <span>ComplexType</span> </h2> <p>ComplexType is here for the purposes of documentation only. It is a stand-in for either complex type: complex64 or complex128. </p> +<pre data-language="go">type ComplexType complex64</pre> <h2 id="FloatType">type <span>FloatType</span> </h2> <p>FloatType is here for the purposes of documentation only. It is a stand-in for either float type: float32 or float64. </p> +<pre data-language="go">type FloatType float32</pre> <h2 id="IntegerType">type <span>IntegerType</span> </h2> <p>IntegerType is here for the purposes of documentation only. It is a stand-in for any integer type: int, uint, int8 etc. </p> +<pre data-language="go">type IntegerType int</pre> <h2 id="Type">type <span>Type</span> </h2> <p>Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation. </p> +<pre data-language="go">type Type int</pre> <h2 id="Type1">type <span>Type1</span> </h2> <p>Type1 is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation. </p> +<pre data-language="go">type Type1 int</pre> <h2 id="any">type <span>any</span> </h2> <p>any is an alias for interface{} and is equivalent to interface{} in all ways. </p> +<pre data-language="go">type any = interface{}</pre> <h2 id="bool">type <span>bool</span> </h2> <p>bool is the set of boolean values, true and false. </p> +<pre data-language="go">type bool bool</pre> <h2 id="byte">type <span>byte</span> </h2> <p>byte is an alias for uint8 and is equivalent to uint8 in all ways. It is used, by convention, to distinguish byte values from 8-bit unsigned integer values. </p> +<pre data-language="go">type byte = uint8</pre> <h2 id="comparable">type <span>comparable</span> </h2> <p>comparable is an interface that is implemented by all comparable types (booleans, numbers, strings, pointers, channels, arrays of comparable types, structs whose fields are all comparable types). The comparable interface may only be used as a type parameter constraint, not as the type of a variable. </p> +<pre data-language="go">type comparable interface{ comparable }</pre> <h2 id="complex128">type <span>complex128</span> </h2> <p>complex128 is the set of all complex numbers with float64 real and imaginary parts. </p> +<pre data-language="go">type complex128 complex128</pre> <h2 id="complex64">type <span>complex64</span> </h2> <p>complex64 is the set of all complex numbers with float32 real and imaginary parts. </p> +<pre data-language="go">type complex64 complex64</pre> <h2 id="error">type <span>error</span> </h2> <p>The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error. </p> +<pre data-language="go">type error interface { + Error() string +}</pre> <h2 id="float32">type <span>float32</span> </h2> <p>float32 is the set of all IEEE-754 32-bit floating-point numbers. </p> +<pre data-language="go">type float32 float32</pre> <h2 id="float64">type <span>float64</span> </h2> <p>float64 is the set of all IEEE-754 64-bit floating-point numbers. </p> +<pre data-language="go">type float64 float64</pre> <h2 id="int">type <span>int</span> </h2> <p>int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32. </p> +<pre data-language="go">type int int</pre> <h2 id="int16">type <span>int16</span> </h2> <p>int16 is the set of all signed 16-bit integers. Range: -32768 through 32767. </p> +<pre data-language="go">type int16 int16</pre> <h2 id="int32">type <span>int32</span> </h2> <p>int32 is the set of all signed 32-bit integers. Range: -2147483648 through 2147483647. </p> +<pre data-language="go">type int32 int32</pre> <h2 id="int64">type <span>int64</span> </h2> <p>int64 is the set of all signed 64-bit integers. Range: -9223372036854775808 through 9223372036854775807. </p> +<pre data-language="go">type int64 int64</pre> <h2 id="int8">type <span>int8</span> </h2> <p>int8 is the set of all signed 8-bit integers. Range: -128 through 127. </p> +<pre data-language="go">type int8 int8</pre> <h2 id="rune">type <span>rune</span> </h2> <p>rune is an alias for int32 and is equivalent to int32 in all ways. It is used, by convention, to distinguish character values from integer values. </p> +<pre data-language="go">type rune = int32</pre> <h2 id="string">type <span>string</span> </h2> <p>string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8-encoded text. A string may be empty, but not nil. Values of string type are immutable. </p> +<pre data-language="go">type string string</pre> <h2 id="uint">type <span>uint</span> </h2> <p>uint is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, uint32. </p> +<pre data-language="go">type uint uint</pre> <h2 id="uint16">type <span>uint16</span> </h2> <p>uint16 is the set of all unsigned 16-bit integers. Range: 0 through 65535. </p> +<pre data-language="go">type uint16 uint16</pre> <h2 id="uint32">type <span>uint32</span> </h2> <p>uint32 is the set of all unsigned 32-bit integers. Range: 0 through 4294967295. </p> +<pre data-language="go">type uint32 uint32</pre> <h2 id="uint64">type <span>uint64</span> </h2> <p>uint64 is the set of all unsigned 64-bit integers. Range: 0 through 18446744073709551615. </p> +<pre data-language="go">type uint64 uint64</pre> <h2 id="uint8">type <span>uint8</span> </h2> <p>uint8 is the set of all unsigned 8-bit integers. Range: 0 through 255. </p> +<pre data-language="go">type uint8 uint8</pre> <h2 id="uintptr">type <span>uintptr</span> </h2> <p>uintptr is an integer type that is large enough to hold the bit pattern of any pointer. </p> +<pre data-language="go">type uintptr uintptr</pre><div class="_attribution"> + <p class="_attribution-p"> + © Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br> + <a href="http://golang.org/pkg/builtin/" class="_attribution-link">http://golang.org/pkg/builtin/</a> + </p> +</div> |
