mirror of
https://github.com/fluencelabs/aqua-book
synced 2024-12-04 23:30:18 +00:00
GitBook: [#139] fixes
This commit is contained in:
parent
aa6be95af6
commit
d203f232b1
@ -31,8 +31,8 @@ func foo(peer: string, relay: ?string):
|
||||
|
||||
func bar(peer: string, relay: string):
|
||||
relayMaybe: *string
|
||||
if peer != %init_peer_id%:
|
||||
-- Wwrite into a stream
|
||||
if peer != INIT_PEER_ID:
|
||||
-- Write into a stream
|
||||
relayMaybe <<- relay
|
||||
-- Pass a stream as an optional value
|
||||
foo(peer, relayMaybe)
|
||||
@ -79,7 +79,7 @@ func foo(peers: []PeerId) -> string:
|
||||
|
||||
-- Wait for 6 responses on resp2: it's JOIN
|
||||
Op.identity(resp2!5)
|
||||
-- Once we have 5 responses, merge them
|
||||
-- Once we have 6 responses, merge them
|
||||
-- Function treats resp2 as an array of strings, and concatenates all
|
||||
-- of them into a single string.
|
||||
-- This function call "fixes" the content of resp2, making a single observation.
|
||||
|
@ -8,14 +8,14 @@ description: Static configuration pieces that affect compilation
|
||||
|
||||
Constant definition.
|
||||
|
||||
Constants can be used all across functions, exported and imported. If a constant is defined using `?=` , it can be overriden by value via compiler flags or imported values.
|
||||
Constants can be used all across functions, exported and imported. If a constant is defined using `?=` , it can be overridden by value via compiler flags or imported values.
|
||||
|
||||
```haskell
|
||||
-- This can be overriten with -const "target_peer_id = \"other peer id\""
|
||||
const target_peer_id ?= "this is a target peer id"
|
||||
-- This can be overridden with -const "TARGET_PEER_ID = \"other peer id\""
|
||||
const TARGET_PEER_ID ?= "this is a target peer id"
|
||||
|
||||
-- This constant cannot be overriden
|
||||
const service_id = "service id"
|
||||
-- This constant cannot be overridden
|
||||
const SERVICE_ID = "service id"
|
||||
```
|
||||
|
||||
You can assign only literals to constants. Constant type is the same as literal type. You can override only with a subtype of that literal type.
|
||||
|
@ -63,7 +63,7 @@ The contract is changed as in [Conditional](conditional.md#contract) flow.
|
||||
|
||||
The way to export data from `for` is the same as in [Conditional return](conditional.md#conditional-return) and [Race patterns](parallel.md#join-behavior).
|
||||
|
||||
```haskell
|
||||
```
|
||||
xs: []string
|
||||
return: *string
|
||||
|
||||
|
@ -55,7 +55,7 @@ par hello(y)
|
||||
|
||||
### co
|
||||
|
||||
`co` , short for `coroutine`, prefixes an operation to send it to the background. From π-calculus perspective, it's the same as `A | null`, where `null`-process is the one that does nothing and completes instantly.
|
||||
`co` , short for `coroutine`, prefixes an operation to send it to the background. From π-calculus perspective, it's the same as `A | null`, where `null`-process is the one that does nothing and completes immediately.
|
||||
|
||||
```haskell
|
||||
-- Let's send foo to background and continue
|
||||
@ -184,7 +184,7 @@ To eliminate the need for such workarounds, Aqua has the `join` expression that
|
||||
|
||||
You can use any number of arguments to `join`, separating them with a comma. `join` is executed on a particular node – so `join` respects the `on` scopes it's in.
|
||||
|
||||
```python
|
||||
```
|
||||
func getTwo(peerA: string, peerB: string) -> string, string:
|
||||
co on peerA:
|
||||
a <- foo()
|
||||
|
@ -111,7 +111,7 @@ nothing gets compiled as expected:
|
||||
2021.09.02 11:31:42 [INFO] Source /Users/bebo/localdev/aqua-245/documentation-examples/aqua-scripts/export.aqua: compilation OK (nothing to emit)
|
||||
```
|
||||
|
||||
You can further check the output directory, `compiled-aqua`, in our case, for the lack of output files. By corollary, `foo` cannot be imported from another files. For example:
|
||||
You can further check the output directory, `compiled-aqua`, in our case, for the lack of output files. Consequently, `foo` cannot be imported from other files. For example:
|
||||
|
||||
```python
|
||||
-- import.aqua
|
||||
|
@ -186,7 +186,7 @@ Functions that capture the topologic context of the definition site are planned,
|
||||
```haskell
|
||||
func baz():
|
||||
foo = do (x: u32):
|
||||
-- Executed there, where foo is called
|
||||
-- Executed on the peer calling foo
|
||||
Srv.call(x)
|
||||
<- x
|
||||
-- When foo is called, it will get back to this context
|
||||
|
@ -129,7 +129,7 @@ foo3: u16 -> u16
|
||||
-- Will not work
|
||||
bar(foo3)
|
||||
|
||||
foo4: u16 -> u64
|
||||
foo4: u64 -> u16
|
||||
|
||||
-- Works
|
||||
bar(foo4)
|
||||
|
@ -120,14 +120,12 @@ func foo(a: i32, b: i32) -> i32:
|
||||
f = e / d
|
||||
-- power 3: unsigned number expected
|
||||
g = f ** 3
|
||||
-- remain
|
||||
-- remainder
|
||||
e = g % f
|
||||
|
||||
-- Can use arithmetics anywhere
|
||||
-- Better use brackets to enforce ordering
|
||||
<- (a + b) - (c + d * (e - 6 ))
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Collections
|
||||
@ -167,7 +165,7 @@ As of Aqua `0.6.3`, it is not possible to get an element by index directly from
|
||||
|
||||
## Getters
|
||||
|
||||
In Aqua, you can use a getter to peak into a field of a product or indexed element in an array.
|
||||
In Aqua, you can use a getter to peek into a field of a product or indexed element in an array.
|
||||
|
||||
```haskell
|
||||
data Sub:
|
||||
|
Loading…
Reference in New Issue
Block a user