Built-in Functions

A few functions are predefined, meaning you don’t have to include any packageto get access to them. lists them all.6

closenewpaniccomplex
deletemakerecoverreal
lenappendprintimag
capcopyprintln

Pre-defined functions in Go.

These built-in functions are documented in the builtin pseudo package that is included in recent Go releases. Let’s go over thesefunctions briefly.

  • close
  • is used in channel communication. It closes a channel. We’ll learn more about this in .
  • delete
  • is used for deleting entries in maps.
  • len and cap
  • are used on a number of different types, len isused to return the lengths of strings, maps, slices, andarrays. In the next section we’ll look at slices,arrays and the function cap.
  • new
  • is used for allocating memory for user defineddata types. See .
  • make
  • is used for allocating memory for built-intypes (maps, slices, and channels). See .
  • copy, append
  • copy is for copying slices. And append is for concatenating slices. See in this chapter.
  • panic, recover
  • are used for an exception mechanism. See for more.
  • print, println
  • are low level printing functions that can be used without reverting to thefmt package. These are mainly used for debugging.built-in,println)
  • complex, real, imag
  • all deal with complex numbers. We will not use complex numbers in this book.