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

docs: fix some minor mistakes (#17582)

This commit is contained in:
jmdyck 2023-03-10 04:04:14 -05:00 committed by GitHub
parent 23e385ee8a
commit 368604f9a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1823,7 +1823,7 @@ for i, name in names {
The `for value in arr` form is used for going through elements of an array. The `for value in arr` form is used for going through elements of an array.
If an index is required, an alternative form `for index, value in arr` can be used. If an index is required, an alternative form `for index, value in arr` can be used.
Note, that the value is read-only. Note that the value is read-only.
If you need to modify the array while looping, you need to declare the element as mutable: If you need to modify the array while looping, you need to declare the element as mutable:
```v ```v
@ -2599,7 +2599,7 @@ println(nums)
// "[2, 4, 6]" // "[2, 4, 6]"
``` ```
Note, that you have to add `mut` before `nums` when calling this function. This makes Note that you have to add `mut` before `nums` when calling this function. This makes
it clear that the function being called will modify the value. it clear that the function being called will modify the value.
It is preferable to return values instead of modifying arguments, It is preferable to return values instead of modifying arguments,
@ -3344,7 +3344,7 @@ fn fn1(s Foo) {
We can test the underlying type of an interface using dynamic cast operators: We can test the underlying type of an interface using dynamic cast operators:
```v oksyntax ```v oksyntax
// interface-exmaple.3 (continued from interface-exampe.1) // interface-example.3 (continued from interface-example.1)
interface Something {} interface Something {}
fn announce(s Something) { fn announce(s Something) {
@ -3408,7 +3408,7 @@ For more information, see [Dynamic casts](#dynamic-casts).
#### Interface method definitions #### Interface method definitions
Also unlike Go, an interface can have it's own methods, similar to how Also unlike Go, an interface can have its own methods, similar to how
structs can have their methods. These 'interface methods' do not have structs can have their methods. These 'interface methods' do not have
to be implemented, by structs which implement that interface. to be implemented, by structs which implement that interface.
They are just a convenient way to write `i.some_function()` instead of They are just a convenient way to write `i.some_function()` instead of
@ -3708,7 +3708,8 @@ fn main() {
V used to combine `Option` and `Result` into one type, now they are separate. V used to combine `Option` and `Result` into one type, now they are separate.
The amount of work required to "upgrade" a function to an option/result function is minimal; The amount of work required to "upgrade" a function to an option/result function is minimal;
you have to add a `?` or `!` to the return type and return an error when something goes wrong. you have to add a `?` or `!` to the return type and return `none` or an error (respectively)
when something goes wrong.
This is the primary mechanism for error handling in V. They are still values, like in Go, This is the primary mechanism for error handling in V. They are still values, like in Go,
but the advantage is that errors can't be unhandled, and handling them is a lot less verbose. but the advantage is that errors can't be unhandled, and handling them is a lot less verbose.
@ -4328,7 +4329,7 @@ which is handy when developing new functionality, to keep your invariants in che
### Asserts with an extra message ### Asserts with an extra message
This form of the `assert` statement, will print the extra message when it fails. Note, that This form of the `assert` statement, will print the extra message when it fails. Note that
you can use any string expression there - string literals, functions returning a string, you can use any string expression there - string literals, functions returning a string,
strings that interpolate variables, etc. strings that interpolate variables, etc.
@ -4343,7 +4344,7 @@ fn test_assertion_with_extra_message_failure() {
### Asserts that do not abort your program ### Asserts that do not abort your program
When initially prototyping functionality and tests, it is sometimes desirable to When initially prototyping functionality and tests, it is sometimes desirable to
have asserts, that do not stop the program, but just print their failures. That can have asserts that do not stop the program, but just print their failures. That can
be achieved by tagging your assert containing functions with an `[assert_continues]` be achieved by tagging your assert containing functions with an `[assert_continues]`
tag, for example running this program: tag, for example running this program:
@ -4421,7 +4422,7 @@ producing the correct output. V executes all test functions in the file.
have access to the private functions/types of the modules. They can test only have access to the private functions/types of the modules. They can test only
the external/public API that a module provides. the external/public API that a module provides.
In the example above, `test_hello` is an internal test, that can call In the example above, `test_hello` is an internal test that can call
the private function `hello()` because `hello_test.v` has `module main`, the private function `hello()` because `hello_test.v` has `module main`,
just like `hello.v`, i.e. both are part of the same module. Note also that just like `hello.v`, i.e. both are part of the same module. Note also that
since `module main` is a regular module like the others, internal tests can since `module main` is a regular module like the others, internal tests can
@ -4613,7 +4614,7 @@ fn f() (RefStruct, &MyStruct) {
} }
``` ```
Here `a` is stored on the stack since it's address never leaves the function `f()`. Here `a` is stored on the stack since its address never leaves the function `f()`.
However a reference to `b` is part of `e` which is returned. Also a reference to However a reference to `b` is part of `e` which is returned. Also a reference to
`c` is returned. For this reason `b` and `c` will be heap allocated. `c` is returned. For this reason `b` and `c` will be heap allocated.
@ -5342,7 +5343,8 @@ type FastFn = fn (int) bool
// Windows only: // Windows only:
// Without this attribute all graphical apps will have the following behavior on Windows: // Without this attribute all graphical apps will have the following behavior on Windows:
// If run from a console or terminal; keep the terminal open so all (e)println statements can be viewed. // If run from a console or terminal; keep the terminal open so all (e)println statements can be viewed.
// If run from e.g. Explorer, by double-click; app is opened, but no terminal is opened, and no (e)println output can be seen. // If run from e.g. Explorer, by double-click; app is opened, but no terminal is opened, and no
// (e)println output can be seen.
// Use it to force-open a terminal to view output in, even if the app is started from Explorer. // Use it to force-open a terminal to view output in, even if the app is started from Explorer.
// Valid before main() only. // Valid before main() only.
[console] [console]
@ -5466,13 +5468,13 @@ is compiled with `v -g` or `v -cg`.
If you're using a custom ifdef, then you do need `$if option ? {}` and compile with`v -d option`. If you're using a custom ifdef, then you do need `$if option ? {}` and compile with`v -d option`.
Full list of builtin options: Full list of builtin options:
| OS | Compilers | Platforms | Other | | OS | Compilers | Platforms | Other |
|--------------------------------|------------------|------------------|--------------------------------------------------| |--------------------------------|------------------|------------------|-----------------------------------------------|
| `windows`, `linux`, `macos` | `gcc`, `tinyc` | `amd64`, `arm64` | `debug`, `prod`, `test` | | `windows`, `linux`, `macos` | `gcc`, `tinyc` | `amd64`, `arm64` | `debug`, `prod`, `test` |
| `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `js`, `glibc`, `prealloc` | | `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `js`, `glibc`, `prealloc` |
| `android`, `mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking`, `freestanding` | | `android`, `mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking`, `freestanding` |
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | `no_segfault_handler`, `no_backtrace`, `no_main` | | `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | `no_segfault_handler`, `no_backtrace` |
| `solaris`, `termux` | | | | | `solaris`, `termux` | | | `no_main` |
#### `$embed_file` #### `$embed_file`