-
-
Notifications
You must be signed in to change notification settings - Fork 159
[Swift 6]: Update lasagna master and its concept #836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
meatball133
wants to merge
3
commits into
exercism:main
Choose a base branch
from
meatball133:update-lasagna-master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
# Introduction | ||
# Default parameter values | ||
|
||
Default parameter values can be supplied for any of a function's parameters by assigning a value to the parameter in the parameter list following the parameter's type annotation. When a default parameter value is specified, the caller of the function can omit that parameter when calling the function and the default value will be used instead. | ||
[Default parameter values][default-parameter-values] can be supplied for any of a function's parameters by assigning a value to the parameter in the parameter list following the parameter's type annotation. | ||
When a default parameter value is specified, the caller of the function can omit that parameter when calling the function and the default value will be used instead. | ||
|
||
```swift | ||
func greeting(name: String = "guest", duration: Int = 2) -> String { | ||
"Welcome, \(name). Enjoy your \(duration) night stay." | ||
} | ||
|
||
greeting(name: "Bobo", duration: 7) | ||
// => "Welcome, Bobo. Enjoy your 7 night stay." | ||
// Returns "Welcome, Bobo. Enjoy your 7 night stay." | ||
greeting(duration: 3) | ||
// => "Welcome, guest. Enjoy your 3 night stay." | ||
// Returns "Welcome, guest. Enjoy your 3 night stay." | ||
greeting(name: "Wynona") | ||
// => "Welcome, Wynona. Enjoy your 2 night stay." | ||
// Returns "Welcome, Wynona. Enjoy your 2 night stay." | ||
greeting() | ||
// => "Welcome, guest. Enjoy your 2 night stay." | ||
// Returns "Welcome, guest. Enjoy your 2 night stay." | ||
``` | ||
|
||
[default-parameter-values]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Default-Parameter-Values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"url": "https://docs.swift.org/swift-book/LanguageGuide/Functions.html", | ||
"description": "Swift.org: Functions" | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Default-Parameter-Values", | ||
"description": "Swift.org: Default Parameter Values" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"url": "https://docs.swift.org/swift-book/LanguageGuide/Functions.html", | ||
"description": "Swift.org: Functions" | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations/#In-Out-Parameters", | ||
"description": "Swift.org: In-Out Parameters" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,22 @@ | ||
# Nested functions | ||
|
||
Functions may be defined [inside of other functions][nested-functions]. This is commonly used to create helper functions which are only useful to their enclosing function and so don't need to pollute the outside namespace. | ||
Functions may be defined [inside of other functions][nested-functions]. | ||
This is commonly used to create helper functions which are only useful to their enclosing function and so don't need to pollute the outside namespace. | ||
|
||
These functions are defined and called just like normal functions, but are not visible outside the enclosing function. | ||
|
||
```swift | ||
func makeNumber(_ bits: [Bool]) -> Int { | ||
func makeNumber(_ number: Int) -> Int { | ||
func double(_ x: Int) -> Int { 2 * x } | ||
func add(_ x: Int) -> Int { x + 1 } | ||
|
||
var number = 0 | ||
for bit in bits { | ||
number = double(number) | ||
if bit { | ||
number = add(number) | ||
} | ||
} | ||
return number | ||
return number.isMultiple(of: 2) ? add(double(number)) : double(number) | ||
} | ||
|
||
makeNumber([true, false, true, true]) | ||
// => 11 | ||
makeNumber([true, true, false, false, false, true, true]) | ||
// => 99 | ||
makeNumber(3) | ||
// Returns 6 | ||
makeNumber(4) | ||
// Returns 9 | ||
``` | ||
|
||
[nested-functions]: https://docs.swift.org/swift-book/LanguageGuide/Functions.html#ID178 | ||
[nested-functions]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Nested-Functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
# Introduction | ||
# Nested functions | ||
|
||
Functions may be defined inside of other functions, which are known as _nested-functions_. | ||
Functions may be defined [inside of other functions][nested-functions]. | ||
This is commonly used to create helper functions which are only useful to their enclosing function and so don't need to pollute the outside namespace. | ||
|
||
These functions are defined and called just like normal functions, but are not visible outside the enclosing function. | ||
|
||
```swift | ||
func double(_ x: Int) -> Int { | ||
func add(_ x: Int, y: Int) -> Int { x + y } | ||
func makeNumber(_ number: Int) -> Int { | ||
func double(_ x: Int) -> Int { 2 * x } | ||
func add(_ x: Int) -> Int { x + 1 } | ||
|
||
add(x, x) | ||
return number.isMultiple(of: 2) ? add(double(number)) : double(number) | ||
} | ||
|
||
makeNumber(3) | ||
// Returns 6 | ||
makeNumber(4) | ||
// Returns 9 | ||
``` | ||
|
||
[nested-functions]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Nested-Functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"url": "https://docs.swift.org/swift-book/LanguageGuide/Functions.html", | ||
"description": "Swift.org: Functions" | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Nested-Functions", | ||
"description": "Swift.org: Nested Functions" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[ | ||
{ | ||
"url": "https://docs.swift.org/swift-book/LanguageGuide/Functions.html", | ||
"description": "Swift.org: Functions" | ||
"url": "https://docs.swift.org/swift-book/documentation/the-swift-programming-language/functions/#Variadic-Parameters", | ||
"description": "Swift.org: Variadic Parameters" | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strings concept doc doesn't have "Returns" on every example line of code. It might be good to pick one style and use it consistently.