From 9bfec97a6dfbe1690ccfcb28d4ebc55429e9e295 Mon Sep 17 00:00:00 2001 From: Andreas Heissenberger Date: Tue, 15 Jun 2021 03:45:27 +0200 Subject: [PATCH] doc: section constants / modules / declare public constants (#10410) --- doc/docs.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index d7b9da3a41..20c2644db1 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -2108,6 +2108,23 @@ println(blue) Global variables are not normally allowed, so this can be really useful. +**Modules** + +Constants can be made public with `pub const`: +```v oksyntax +module mymodule + +pub const golden_ratio = 1.61803 + +fn calc() { + println(mymodule.golden_ratio) +} +``` +The `pub` keyword is only allowed before the `const` keyword and cannot be used inside +a `const ( )` block. + +Outside from module main all constants need to be prefixed with the module name. + ### Required module prefix When naming constants, `snake_case` must be used. In order to distinguish consts