|
2 | 2 |
|
3 | 3 | ## ⚠️ Attention! Ziglings has moved to Codeberg!
|
4 | 4 |
|
5 |
| -Check out our handy new URL: https://ziglings.org |
| 5 | +Check out directly our handy new URL: https://ziglings.org |
6 | 6 |
|
7 |
| -Or visit the repo directly at: https://codeberg.org/ziglings/exercises |
| 7 | +Or visit the repo at: https://codeberg.org/ziglings/exercises |
8 | 8 |
|
9 |
| -*** |
10 |
| - |
11 |
| -Welcome to Ziglings! This project contains a series of tiny |
12 |
| -broken programs (and one nasty surprise). By fixing them, you'll |
13 |
| -learn how to read and write [Zig](https://ziglang.org/) code. |
14 |
| - |
15 |
| - |
16 |
| - |
17 |
| -Those broken programs need your help! (You'll also save the |
18 |
| -planet from evil aliens and help some friendly elephants stick |
19 |
| -together, which is very sweet of you.) |
20 |
| - |
21 |
| -This project was directly inspired by the brilliant and fun |
22 |
| -[rustlings](https://github.com/rust-lang/rustlings) |
23 |
| -project for the [Rust](https://www.rust-lang.org/) language. |
24 |
| -Indirect inspiration comes from [Ruby Koans](http://rubykoans.com/) |
25 |
| -and the Little LISPer/Little Schemer series of books. |
26 |
| - |
27 |
| -## Intended Audience |
28 |
| - |
29 |
| -This will probably be difficult if you've _never_ programmed |
30 |
| -before. But no specific programming experience is required. And |
31 |
| -in particular, you are _not_ expected to have any prior |
32 |
| -experience with "systems programming" or a "systems" level |
33 |
| -language such as C. |
34 |
| - |
35 |
| -Each exercise is self-contained and self-explained. However, |
36 |
| -you're encouraged to also check out these Zig language resources |
37 |
| -for more detail: |
38 |
| - |
39 |
| -* https://ziglang.org/learn/ |
40 |
| -* https://ziglearn.org/ |
41 |
| -* https://ziglang.org/documentation/master/ |
42 |
| - |
43 |
| -Also, the [Zig community](https://github.com/ziglang/zig/wiki/Community) |
44 |
| -is incredibly friendly and helpful! |
45 |
| - |
46 |
| -## Getting Started |
47 |
| - |
48 |
| -Install a [development build](https://ziglang.org/download/) of |
49 |
| -the Zig compiler. (See the "master" section of the downloads |
50 |
| -page.) |
51 |
| - |
52 |
| -Verify the installation and build number of `zig` like so: |
53 |
| - |
54 |
| -``` |
55 |
| -$ zig version |
56 |
| -0.11.0-dev.4246+xxxxxxxxx |
57 |
| -``` |
58 |
| - |
59 |
| -Clone this repository with Git: |
60 |
| - |
61 |
| -``` |
62 |
| -$ git clone https://ziglings.org |
63 |
| -$ cd ziglings.org |
64 |
| -``` |
65 |
| - |
66 |
| -Then run `zig build` and follow the instructions to begin! |
67 |
| - |
68 |
| -``` |
69 |
| -$ zig build |
70 |
| -``` |
71 |
| - |
72 |
| -Note: The output of Ziglings is the unaltered output from the Zig |
73 |
| -compiler. Part of the purpose of Ziglings is to acclimate you to |
74 |
| -reading these. |
75 |
| - |
76 |
| -## A Note About Versions |
77 |
| - |
78 |
| -The Zig language is under very active development. In order to be |
79 |
| -current, Ziglings tracks **development** builds of the Zig |
80 |
| -compiler rather than versioned **release** builds. The last |
81 |
| -stable release was `0.10.1`, but Ziglings needs a dev build with |
82 |
| -pre-release version "0.11.0" and a build number at least as high |
83 |
| -as that shown in the example version check above. |
84 |
| - |
85 |
| -It is likely that you'll download a build which is _greater_ than |
86 |
| -the minimum. |
87 |
| - |
88 |
| -_(For those who cannot easily update Zig, there are also |
89 |
| -community-supported branches in this repo. At the moment, there's |
90 |
| -one for v0.8.1. Older version branches may or may not have all |
91 |
| -exercises and/or bugfixes.)_ |
92 |
| - |
93 |
| -Once you have a build of the Zig compiler that works with |
94 |
| -Ziglings, they'll continue to work together. But keep in mind |
95 |
| -that if you update one, you may need to also update the other. |
96 |
| - |
97 |
| - |
98 |
| -### Version Changes |
99 |
| - |
100 |
| -Version-0.11.0-dev.4246+71dfce31b |
101 |
| -* *2023-06-26* zig 0.11.0-dev.4246 - changes in compile step (now it can be null) |
102 |
| -* *2023-06-26* zig 0.11.0-dev.3853 - removal of destination type from all cast builtins |
103 |
| -* *2023-06-20* zig 0.11.0-dev.3747 - `@enumToInt` is now `@intFromEnum` and `@intToFloat` is now `@floatFromInt` |
104 |
| -* *2023-05-25* zig 0.11.0-dev.3295 - `std.debug.TTY` is now `std.io.tty` |
105 |
| -* *2023-04-30* zig 0.11.0-dev.2704 - use of the new `std.Build.ExecutableOptions.link_libc` field |
106 |
| -* *2023-04-12* zig 0.11.0-dev.2560 - changes in `std.Build` - remove run() and install() |
107 |
| -* *2023-04-07* zig 0.11.0-dev.2401 - fixes of the new build system - see [#212](https://github.com/ratfactor/ziglings/pull/212) |
108 |
| -* *2023-02-21* zig 0.11.0-dev.2157 - changes in `build system` - new: parallel processing of the build steps |
109 |
| -* *2023-02-21* zig 0.11.0-dev.1711 - changes in `for loops` - new: Multi-Object For-Loops + Struct-of-Arrays |
110 |
| -* *2023-02-12* zig 0.11.0-dev.1638 - changes in `std.Build` cache_root now returns a directory struct |
111 |
| -* *2023-02-04* zig 0.11.0-dev.1568 - changes in `std.Build` (combine `std.build` and `std.build.Builder` into `std.Build`) |
112 |
| -* *2023-01-14* zig 0.11.0-dev.1302 - changes in `@addWithOverflow` (now returns a tuple) and `@typeInfo`; temporary disabled async functionality |
113 |
| -* *2022-09-09* zig 0.10.0-dev.3978 - change in `NativeTargetInfo.detect` in build |
114 |
| -* *2022-09-06* zig 0.10.0-dev.3880 - Ex 074 correctly fails again: comptime array len |
115 |
| -* *2022-08-29* zig 0.10.0-dev.3685 - `@typeName()` output change, stage1 req. for async |
116 |
| -* *2022-07-31* zig 0.10.0-dev.3385 - std lib string `fmt()` option changes |
117 |
| -* *2022-03-19* zig 0.10.0-dev.1427 - method for getting sentinel of type changed |
118 |
| -* *2021-12-20* zig 0.9.0-dev.2025 - `c_void` is now `anyopaque` |
119 |
| -* *2021-06-14* zig 0.9.0-dev.137 - std.build.Id `.Custom` is now `.custom` |
120 |
| -* *2021-04-21* zig 0.8.0-dev.1983 - std.fmt.format() `any` format string required |
121 |
| -* *2021-02-12* zig 0.8.0-dev.1065 - std.fmt.format() `s` (string) format string required |
122 |
| - |
123 |
| -## Advanced Usage |
124 |
| - |
125 |
| -It can be handy to check just a single exercise: |
126 |
| - |
127 |
| -``` |
128 |
| -zig build -Dn=19 |
129 |
| -``` |
130 |
| - |
131 |
| -You can also run without checking for correctness: |
132 |
| - |
133 |
| -``` |
134 |
| -zig build -Dn=19 test |
135 |
| -``` |
136 |
| - |
137 |
| -Or skip the build system entirely and interact directly with the |
138 |
| -compiler if you're into that sort of thing: |
139 |
| - |
140 |
| -``` |
141 |
| -zig run exercises/001_hello.zig |
142 |
| -``` |
143 |
| - |
144 |
| -Calling all wizards: To prepare an executable for debugging, |
145 |
| -install it to zig-cache/bin with: |
146 |
| - |
147 |
| -``` |
148 |
| -zig build -Dn=19 install |
149 |
| -``` |
150 |
| - |
151 |
| -To get a list of all possible options, run: |
152 |
| - |
153 |
| -``` |
154 |
| -zig build -Dn=19 -l |
155 |
| -
|
156 |
| - install Install 019_functions2.zig to prefix path |
157 |
| - uninstall Uninstall 019_functions2.zig from prefix path |
158 |
| - test Run 019_functions2.zig without checking output |
159 |
| - ... |
160 |
| -``` |
161 |
| - |
162 |
| -## What's Covered |
163 |
| - |
164 |
| -The primary goal for Ziglings is to cover the core Zig language. |
165 |
| - |
166 |
| -It would be nice to cover the Standard Library as well, but this |
167 |
| -is currently challenging because the stdlib is evolving even |
168 |
| -faster than the core language (and that's saying something!). |
169 |
| -Not only would stdlib coverage change very rapidly, some |
170 |
| -exercises might even cease to be relevant entirely. |
171 |
| - |
172 |
| -Having said that, there are some stdlib features that are |
173 |
| -probably here to stay or are so important to understand that they |
174 |
| -are worth the extra effort to keep current. |
175 |
| - |
176 |
| -Conspicuously absent from Ziglings are a lot of string |
177 |
| -manipulation exercises. This is because Zig itself largely avoids |
178 |
| -dealing with strings. Hopefully there will be an obvious way to |
179 |
| -address this in the future. The Ziglings crew loves strings! |
180 |
| - |
181 |
| -Zig Core Language |
182 |
| - |
183 |
| -* [x] Hello world (main needs to be public) |
184 |
| -* [x] Importing standard library |
185 |
| -* [x] Assignment |
186 |
| -* [x] Arrays |
187 |
| -* [x] Strings |
188 |
| -* [x] If |
189 |
| -* [x] While |
190 |
| -* [x] For |
191 |
| -* [x] Functions |
192 |
| -* [x] Errors (error/try/catch/if-else-err) |
193 |
| -* [x] Defer (and errdefer) |
194 |
| -* [x] Switch |
195 |
| -* [x] Unreachable |
196 |
| -* [x] Enums |
197 |
| -* [x] Structs |
198 |
| -* [x] Pointers |
199 |
| -* [x] Optionals |
200 |
| -* [x] Struct methods |
201 |
| -* [x] Slices |
202 |
| -* [x] Many-item pointers |
203 |
| -* [x] Unions |
204 |
| -* [x] Numeric types (integers, floats) |
205 |
| -* [x] Labelled blocks and loops |
206 |
| -* [x] Loops as expressions |
207 |
| -* [x] Builtins |
208 |
| -* [x] Inline loops |
209 |
| -* [x] Comptime |
210 |
| -* [x] Sentinel termination |
211 |
| -* [x] Quoted identifiers @"" |
212 |
| -* [x] Anonymous structs/tuples/lists |
213 |
| -* [ ] Async <--- ironically awaiting upstream Zig updates |
214 |
| -* [X] Interfaces |
215 |
| -* [X] Bit manipulation |
216 |
| -* [X] Working with C |
217 |
| - |
218 |
| -Zig Standard Library |
219 |
| - |
220 |
| -* [X] String formatting |
221 |
| -* [X] Testing |
222 |
| -* [X] Tokenization |
223 |
| - |
224 |
| -## Contributing |
225 |
| - |
226 |
| -Contributions are very welcome! I'm writing this to teach myself |
227 |
| -and to create the learning resource I wished for. There will be |
228 |
| -tons of room for improvement: |
229 |
| - |
230 |
| -* Wording of explanations |
231 |
| -* Idiomatic usage of Zig |
232 |
| -* Additional exercises |
233 |
| - |
234 |
| -Please see [CONTRIBUTING](https://github.com/ratfactor/ziglings/blob/main/CONTRIBUTING.md) |
235 |
| -in this repo for the full details. |
0 commit comments