mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2025-01-02 18:45:53 -05:00
080-083 completed
This commit is contained in:
parent
0651d71c47
commit
376ec9ac05
4 changed files with 9 additions and 9 deletions
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue