1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

doc: section constants / modules / declare public constants (#10410)

This commit is contained in:
Andreas Heissenberger 2021-06-15 03:45:27 +02:00 committed by GitHub
parent e328b1d292
commit 9bfec97a6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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