Skip to content

Commit

Permalink
Merge pull request #193 from eczn/eczn_doc_fix
Browse files Browse the repository at this point in the history
fix: wrong return type of Ref
  • Loading branch information
bobzhang authored May 1, 2024
2 parents 52bd2d5 + d42eb60 commit 2dcc34e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn init {
The default expression will be evaluated everytime it is used. And the side effect in the default expression, if any, will also be triggered. For example:

```rust
fn incr(~counter : Ref[Int] = { val: 0 }) -> Int {
fn incr(~counter : Ref[Int] = { val: 0 }) -> Ref[Int] {
counter.val = counter.val + 1
counter.val
}
Expand All @@ -204,7 +204,7 @@ If you want to share the result of default expression between different function
```rust
let default_counter : Ref[Int] = { val: 0 }

fn incr(~conuter : Ref[Int] = default_counter) -> Int {
fn incr(~counter : Ref[Int] = default_counter) -> Int {
counter.val = counter.val + 1
counter.val
}
Expand Down Expand Up @@ -467,6 +467,7 @@ fn pack(a: Bool, b: Int, c: String, d: Double) -> (Bool, Int, String, Double) {
fn init {
let quad = pack(false, 100, "text", 3.14)
let (bool_val, int_val, str, float_val) = quad
println("\(bool_val) \(int_val) \(str) \(float_val)")
}
```

Expand Down
5 changes: 3 additions & 2 deletions zh-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn init {
每次使用默认参数调用一个函数时,都会重新求值默认值的表达式,也会被重新触发其中的副作用。例如:

```rust
fn incr(~counter : Ref[Int] = { val: 0 }) -> Int {
fn incr(~counter : Ref[Int] = { val: 0 }) -> Ref[Int] {
counter.val = counter.val + 1
counter
}
Expand All @@ -208,7 +208,7 @@ fn init {
```rust
let default_counter : Ref[Int] = { val: 0 }

fn incr(~conuter : Ref[Int] = default_counter) -> Int {
fn incr(~counter : Ref[Int] = default_counter) -> Int {
counter.val = counter.val + 1
counter.val
}
Expand Down Expand Up @@ -467,6 +467,7 @@ fn pack(a: Bool, b: Int, c: String, d: Double) -> (Bool, Int, String, Double) {
fn init {
let quad = pack(false, 100, "text", 3.14)
let (bool_val, int_val, str, float_val) = quad
println("\(bool_val) \(int_val) \(str) \(float_val)")
}
```

Expand Down

0 comments on commit 2dcc34e

Please sign in to comment.