Skip to content

Commit 9314ecc

Browse files
committed
feat: update gleam starter
add comments.
1 parent 2492f7c commit 9314ecc

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
import argv
22
import file_streams/read_stream
3-
import gleam/bit_array
43
import gleam/int.{to_string}
54
import gleam/io
6-
import gleam/list.{each}
75

86
pub fn main() {
97
// You can use print statements as follows for debugging, they'll be visible when running tests.
108
io.println("Logs from your program will appear here!")
9+
1110
let args = argv.load().arguments
11+
1212
// Uncomment this to pass the first stage
1313
// case args {
1414
// [database_file_path, ".dbinfo", ..] -> {
1515
// let assert Ok(rs) = read_stream.open(database_file_path)
16-
// let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
17-
// let assert Ok(int_value) = read_stream.read_int16_be(rs)
16+
// // Get a file handle to the database file, and skip the first 16 bytes
17+
// let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
18+
// // The next 2 bytes hold the page size in big-endian format
19+
// let assert Ok(page_size) = read_stream.read_int16_be(rs)
1820
//
1921
// io.print("database page size: ")
20-
// io.println(to_string(int_value))
22+
// io.println(to_string(page_size))
2123
// }
2224
// _ -> {
23-
// io.println("No match")
25+
// io.println("Unknown command")
2426
// }
2527
// }
2628
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import argv
22
import file_streams/read_stream
3-
import gleam/bit_array
43
import gleam/int.{to_string}
54
import gleam/io
6-
import gleam/list.{each}
75

86
pub fn main() {
97
let args = argv.load().arguments
8+
109
case args {
1110
[database_file_path, ".dbinfo", ..] -> {
1211
let assert Ok(rs) = read_stream.open(database_file_path)
13-
let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
14-
let assert Ok(int_value) = read_stream.read_int16_be(rs)
12+
// Get a file handle to the database file, and skip the first 16 bytes
13+
let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
14+
// The next 2 bytes hold the page size in big-endian format
15+
let assert Ok(page_size) = read_stream.read_int16_be(rs)
1516

1617
io.print("database page size: ")
17-
io.println(to_string(int_value))
18+
io.println(to_string(page_size))
1819
}
1920
_ -> {
20-
io.println("No match")
21+
io.println("Unknown command")
2122
}
2223
}
2324
}
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
@@ -1,26 +1,23 @@
1+
@@ -1,28 +1,24 @@
22
import argv
33
import file_streams/read_stream
4-
import gleam/bit_array
54
import gleam/int.{to_string}
65
import gleam/io
7-
import gleam/list.{each}
86

97
pub fn main() {
108
- // You can use print statements as follows for debugging, they'll be visible when running tests.
119
- io.println("Logs from your program will appear here!")
10+
-
1211
let args = argv.load().arguments
12+
1313
- // Uncomment this to pass the first stage
1414
- // case args {
1515
- // [database_file_path, ".dbinfo", ..] -> {
1616
- // let assert Ok(rs) = read_stream.open(database_file_path)
17-
- // let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
18-
- // let assert Ok(int_value) = read_stream.read_int16_be(rs)
17+
- // // Get a file handle to the database file, and skip the first 16 bytes
18+
- // let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
19+
- // // The next 2 bytes hold the page size in big-endian format
20+
- // let assert Ok(page_size) = read_stream.read_int16_be(rs)
1921
- //
2022
- // io.print("database page size: ")
21-
- // io.println(to_string(int_value))
23+
- // io.println(to_string(page_size))
2224
- // }
2325
- // _ -> {
24-
- // io.println("No match")
26+
- // io.println("Unknown command")
2527
- // }
2628
- // }
2729
+ case args {
2830
+ [database_file_path, ".dbinfo", ..] -> {
2931
+ let assert Ok(rs) = read_stream.open(database_file_path)
30-
+ let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
31-
+ let assert Ok(int_value) = read_stream.read_int16_be(rs)
32+
+ // Get a file handle to the database file, and skip the first 16 bytes
33+
+ let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
34+
+ // The next 2 bytes hold the page size in big-endian format
35+
+ let assert Ok(page_size) = read_stream.read_int16_be(rs)
3236
+
3337
+ io.print("database page size: ")
34-
+ io.println(to_string(int_value))
38+
+ io.println(to_string(page_size))
3539
+ }
3640
+ _ -> {
37-
+ io.println("No match")
41+
+ io.println("Unknown command")
3842
+ }
3943
+ }
4044
}

solutions/gleam/01-init/explanation.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ Study and uncomment the relevant code:
77
case args {
88
[database_file_path, ".dbinfo", ..] -> {
99
let assert Ok(rs) = read_stream.open(database_file_path)
10-
let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
11-
let assert Ok(int_value) = read_stream.read_int16_be(rs)
10+
// Get a file handle to the database file, and skip the first 16 bytes
11+
let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
12+
// The next 2 bytes hold the page size in big-endian format
13+
let assert Ok(page_size) = read_stream.read_int16_be(rs)
1214
1315
io.print("database page size: ")
14-
io.println(to_string(int_value))
16+
io.println(to_string(page_size))
1517
}
1618
_ -> {
17-
io.println("No match")
19+
io.println("Unknown command")
1820
}
1921
}
2022
```
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
import argv
22
import file_streams/read_stream
3-
import gleam/bit_array
43
import gleam/int.{to_string}
54
import gleam/io
6-
import gleam/list.{each}
75

86
pub fn main() {
97
// You can use print statements as follows for debugging, they'll be visible when running tests.
108
io.println("Logs from your program will appear here!")
9+
1110
let args = argv.load().arguments
11+
1212
// Uncomment this to pass the first stage
1313
// case args {
1414
// [database_file_path, ".dbinfo", ..] -> {
1515
// let assert Ok(rs) = read_stream.open(database_file_path)
16-
// let assert Ok(bytes) = read_stream.read_bytes_exact(rs, 16)
17-
// let assert Ok(int_value) = read_stream.read_int16_be(rs)
16+
// // Get a file handle to the database file, and skip the first 16 bytes
17+
// let assert Ok(_bytes) = read_stream.read_bytes_exact(rs, 16)
18+
// // The next 2 bytes hold the page size in big-endian format
19+
// let assert Ok(page_size) = read_stream.read_int16_be(rs)
1820
//
1921
// io.print("database page size: ")
20-
// io.println(to_string(int_value))
22+
// io.println(to_string(page_size))
2123
// }
2224
// _ -> {
23-
// io.println("No match")
25+
// io.println("Unknown command")
2426
// }
2527
// }
2628
}

0 commit comments

Comments
 (0)