-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 7 additions & 2 deletions
9
moonbit-tour/tour/chapter1_basics/lesson11_for_in_loop/index.mbt
This file contains 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
14 changes: 14 additions & 0 deletions
14
moonbit-tour/tour/chapter1_basics/lesson12_range/index.mbt
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main { | ||
println("number 1 to 3:") | ||
for i in 1..<4 { | ||
println(i) | ||
} | ||
|
||
println("number 1 to 4:") | ||
for i in 1..=4 { | ||
println(i) | ||
} | ||
} | ||
|
||
|
||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Range | ||
|
||
You can also use *range* in a for-in loop. | ||
|
||
- `start..<end` range is inclusive of the start value and exclusive of the end value. | ||
- `start..=end` range is inclusive of both the start and end values. | ||
|
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
moonbit-tour/tour/chapter2_data_types/lesson4_newtype/index.mbt
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type UserId Int | ||
type UserName String | ||
|
||
fn main { | ||
let user_id : UserId = UserId(1) | ||
let user_name : UserName = UserName("Alice") | ||
let UserId(id) = user_id | ||
let UserName(name) = user_name | ||
println(user_id._) | ||
println(user_name._) | ||
} |
Empty file.
36 changes: 36 additions & 0 deletions
36
moonbit-tour/tour/chapter3_pattern_matching/lesson8_range_pattern/index.mbt
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
fn score_to_grade(score : Int) -> String { | ||
match score { | ||
0..<60 => "F" | ||
60..<70 => "D" | ||
70..<80 => "C" | ||
80..<90 => "B" | ||
90..=100 => "A" | ||
_ => "Invalid score" | ||
} | ||
} | ||
|
||
fn classify_char(c : Char) -> String { | ||
match c { | ||
'A'..='Z' => "UpperCase" | ||
'a'..='z' => "LowerCase" | ||
'0'..='9' => "Digit" | ||
_ => "Special" | ||
} | ||
} | ||
|
||
fn is_scalar_value(codepoint : Int) -> Bool { | ||
match codepoint { | ||
0x0000..=0xD7FF | 0xE000..=0x10FFFF => true | ||
_ => false | ||
} | ||
} | ||
|
||
fn main { | ||
println(score_to_grade(50)) | ||
println(score_to_grade(85)) | ||
println(score_to_grade(95)) | ||
println(classify_char('A')) | ||
println(classify_char('1')) | ||
println(classify_char('!')) | ||
println(is_scalar_value(0xD500)) | ||
} |
13 changes: 13 additions & 0 deletions
13
moonbit-tour/tour/chapter3_pattern_matching/lesson8_range_pattern/index.md
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Range Pattern | ||
|
||
For consecutive values, using the previously introduced *or-patterns* can be somewhat cumbersome. To address this issue, we can use *range patterns*. *Range patterns* can match values within a specified range. | ||
|
||
|
||
Recall the syntax we learned in Chapter 1: | ||
|
||
- `start..<end` range is inclusive of the start value and exclusive of the end value. | ||
- `start..=end` range is inclusive of both the start and end values. | ||
|
||
|
||
Range patterns support built-in integer-like types, such as `Byte`, `Int`, `UInt`, `Int64`, `UInt64`, and `Char`. | ||
|