From ba48cf3238ffa6d48a063707070219880900442d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Aulery?= Date: Sat, 26 Dec 2020 21:13:07 +0100 Subject: [PATCH] doc: list more builtin functions with better description of each (#7587) --- doc/docs.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index c2a1e82b95..9d03dd1f39 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1619,9 +1619,23 @@ are no globals: println('Top cities: $top_cities.filter(.usa)') ``` -## println and other builtin functions +## Builtin functions -`println` is a simple yet powerful builtin function. It can print anything: +Some functions are builtin like `println`. Here is the complete list: + +```v ignore +fn print(s string) // print anything on sdtout +fn println(s string) // print anything and a newline on sdtout + +fn eprint(s string) // same as print(), but use stderr +fn eprintln(s string) // same as println(), but use stderr + +fn exit(code int) // terminate the program with a custom error code +fn panic(s string) // print a message and backtraces on stderr, and terminate the program with error code 1 +fn print_backtrace() // print backtraces on stderr +``` + +`println` is a simple yet powerful builtin function, that can print anything: strings, numbers, arrays, maps, structs. ```v nofmt @@ -1654,18 +1668,6 @@ red := Color{ println(red) ``` -If you don't want to print a newline, use `print()` instead. - -The number of builtin functions is low. Other builtin functions are: - - -```v ignore -fn exit(exit_code int) // terminate the program -fn panic(message string) -fn print_backtrace() -fn eprintln(s string) // same as println, but use stderr -``` - ## Modules Every file in the root of a folder is part of the same module.