080-083 completed

This commit is contained in:
Andrew Scott 2024-06-13 15:37:47 -04:00
parent 0651d71c47
commit 376ec9ac05
Signed by: a
GPG key ID: 7CD5A5977E4931C1
4 changed files with 9 additions and 9 deletions

View file

@ -48,13 +48,13 @@ pub fn main() void {
// * circle1 should hold i32 integers // * circle1 should hold i32 integers
// * circle2 should hold f32 floats // * circle2 should hold f32 floats
// //
const circle1 = ??? { const circle1 = Circle(i32){
.center_x = 25, .center_x = 25,
.center_y = 70, .center_y = 70,
.radius = 15, .radius = 15,
}; };
const circle2 = ??? { const circle2 = Circle(f32){
.center_x = 25.234, .center_x = 25.234,
.center_y = 70.999, .center_y = 70.999,
.radius = 15.714, .radius = 15.714,

View file

@ -38,7 +38,7 @@ pub fn main() void {
// Please complete this function which prints an anonymous struct // Please complete this function which prints an anonymous struct
// representing a circle. // representing a circle.
fn printCircle(???) void { fn printCircle(circle: anytype) void {
print("x:{} y:{} radius:{}\n", .{ print("x:{} y:{} radius:{}\n", .{
circle.center_x, circle.center_x,
circle.center_y, circle.center_y,

View file

@ -82,14 +82,14 @@ fn printTuple(tuple: anytype) void {
// @typeInfo(Circle).Struct.fields // @typeInfo(Circle).Struct.fields
// //
// This will be an array of StructFields. // This will be an array of StructFields.
const fields = ???; const fields = @typeInfo(@TypeOf(tuple)).Struct.fields;
// 2. Loop through each field. This must be done at compile // 2. Loop through each field. This must be done at compile
// time. // time.
// //
// Hint: remember 'inline' loops? // Hint: remember 'inline' loops?
// //
for (fields) |field| { inline for (fields) |field| {
// 3. Print the field's name, type, and value. // 3. Print the field's name, type, and value.
// //
// Each 'field' in this loop is one of these: // Each 'field' in this loop is one of these:
@ -117,9 +117,9 @@ fn printTuple(tuple: anytype) void {
// //
// The first field should print as: "0"(bool):true // The first field should print as: "0"(bool):true
print("\"{s}\"({any}):{any} ", .{ print("\"{s}\"({any}):{any} ", .{
field.???, field.name,
field.???, field.type,
???, @field(tuple, field.name),
}); });
} }
} }

View file

@ -20,6 +20,6 @@ pub fn main() void {
// //
// = .{ 'h', 'e', 'l', 'l', 'o' }; // = .{ 'h', 'e', 'l', 'l', 'o' };
// //
const hello = .{ 'h', 'e', 'l', 'l', 'o' }; const hello: [5]u8 = .{ 'h', 'e', 'l', 'l', 'o' };
print("I say {s}!\n", .{hello}); print("I say {s}!\n", .{hello});
} }