doc: clear up concurrency and immutable fn args

master
Alexander Medvednikov 2022-06-23 17:46:57 +03:00 committed by GitHub
parent 298dc77c38
commit c17200c33d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 10 deletions

View File

@ -107,7 +107,7 @@ For more details and troubleshooting, please visit the [vab GitHub repository](h
</td><td width=33% valign=top> </td><td width=33% valign=top>
* [Functions 2](#functions-2) * [Functions 2](#functions-2)
* [Pure functions by default](#pure-functions-by-default) * [Immutable function args by default](#immutable-function-args-by-default)
* [Mutable arguments](#mutable-arguments) * [Mutable arguments](#mutable-arguments)
* [Variable number of arguments](#variable-number-of-arguments) * [Variable number of arguments](#variable-number-of-arguments)
* [Anonymous & higher-order functions](#anonymous--higher-order-functions) * [Anonymous & higher-order functions](#anonymous--higher-order-functions)
@ -343,8 +343,7 @@ the expression `T(v)` converts the value `v` to the
type `T`. type `T`.
Unlike most other languages, V only allows defining variables in functions. Unlike most other languages, V only allows defining variables in functions.
Global (module level) variables are not allowed. There's no global state in V Global (module level) variables are not allowed. There's no global state in V.
(see [Pure functions by default](#pure-functions-by-default) for details).
For consistency across different code bases, all variable and function names For consistency across different code bases, all variable and function names
must use the `snake_case` style, as opposed to type names, which must use `PascalCase`. must use the `snake_case` style, as opposed to type names, which must use `PascalCase`.
@ -2279,13 +2278,13 @@ Note that the embedded struct arguments are not necessarily stored in the order
## Functions 2 ## Functions 2
### Pure functions by default ### Immutable function args by default, mutable args have to be marked on call
V functions are pure by default, meaning that their return values are a function of their In V function args are immutable by default, mutable args have to be marked on call.
arguments only, and their evaluation has no side effects (besides I/O). Since there are also no globals, that means that functions' return values are a function of their
arguments only, and their evaluation has no side effects (unless the function uses I/O).
This is achieved by a lack of global variables and all function arguments being Function arguments are immutable by default even when [references](#references) are passed.
immutable by default, even when [references](#references) are passed.
V is not a purely functional language however. V is not a purely functional language however.
@ -3601,8 +3600,8 @@ println(compare(1.1, 1.2)) // -1
## Concurrency ## Concurrency
### Spawning Concurrent Tasks ### Spawning Concurrent Tasks
V's model of concurrency is very similar to Go's. To run `foo()` concurrently in V's model of concurrency is going to be very similar to Go's. For now, `go foo()` runs `foo()` concurrently in
a different thread, just call it with `go foo()`: a different thread:
```v ```v
import math import math
@ -3618,6 +3617,9 @@ fn main() {
} }
``` ```
> In V 0.4 `go foo()` will be automatically renamed via vfmt to `spawn foo()`, and there will be a way to launch
a coroutine (a lightweight thread managed by the runtime).
Sometimes it is necessary to wait until a parallel thread has finished. This can Sometimes it is necessary to wait until a parallel thread has finished. This can
be done by assigning a *handle* to the started thread and calling the `wait()` method be done by assigning a *handle* to the started thread and calling the `wait()` method
to this handle later: to this handle later: