Merge pull request #119 from JIghtuse/master

chapter3: Fix multiple-argument functions signatures
This commit is contained in:
Carol (Nichols || Goulding) 2016-07-05 11:23:48 -04:00 committed by GitHub
commit ab0e9ab406
2 changed files with 4 additions and 4 deletions

View File

@ -878,7 +878,7 @@ The one difference is that in function signatures, we _must_ declare the type. T
When you want a function to have multiple arguments, just separate them inside the function signature with commas, like this:
```text
fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) {
fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) {
```
And just like a `let` declaration with multiple patterns, a type must be applied to each pattern separately. To demonstrate, heres a full example of a function with multiple arguments:
@ -956,7 +956,7 @@ Note that our bindings are called `a` and `b`, yet inside the function, we refer
Functions can return values back to functions that call them. The signature for a function that returns a value looks like this:
```TEXT
fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) -> TYPE {
fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) -> TYPE {
```
In Rust, we dont name return values, but we do declare their type, after the arrow (`->`). Heres a sample program to illustrate this concept:

View File

@ -106,7 +106,7 @@ functions means that you almost never need them anywhere else.
You can separate multiple arguments with a comma:
```text
fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) {
fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) {
```
Heres a full example:
@ -168,7 +168,7 @@ passed as parameters dont need to have the same name as the arguments.
Functions can also return values back to the function that called them:
```TEXT
fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) -> TYPE {
fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) -> TYPE {
```
We dont name return values, but we do declare their type, after an arrow: