221V 19 hours ago
parent
commit
97ef20c379
1 changed files with 18 additions and 17 deletions
  1. 18 17
      exercises/069_comptime4.zig

+ 18 - 17
exercises/069_comptime4.zig

@@ -13,14 +13,14 @@
 //
 //
 const print = @import("std").debug.print;
 const print = @import("std").debug.print;
 
 
-pub fn main() void {
-    // Here we declare arrays of three different types and sizes
-    // at compile time from a function call. Neat!
-    const s1 = makeSequence(u8, 3); // creates a [3]u8
-    const s2 = makeSequence(u32, 5); // creates a [5]u32
-    const s3 = makeSequence(i64, 7); // creates a [7]i64
-
-    print("s1={any}, s2={any}, s3={any}\n", .{ s1, s2, s3 });
+pub fn main() void{
+  // Here we declare arrays of three different types and sizes
+  // at compile time from a function call. Neat!
+  const s1 = makeSequence(u8, 3); // creates a [3]u8
+  const s2 = makeSequence(u32, 5); // creates a [5]u32
+  const s3 = makeSequence(i64, 7); // creates a [7]i64
+  
+  print("s1={any}, s2={any}, s3={any}\n", .{ s1, s2, s3 });
 }
 }
 
 
 // This function is pretty wild because it executes at runtime
 // This function is pretty wild because it executes at runtime
@@ -42,13 +42,14 @@ pub fn main() void {
 //     2) Sets the size of the array of type T (which is the
 //     2) Sets the size of the array of type T (which is the
 //        sequence we're creating and returning).
 //        sequence we're creating and returning).
 //
 //
-fn makeSequence(comptime T: type, ??? size: usize) [???]T {
-    var sequence: [???]T = undefined;
-    var i: usize = 0;
-
-    while (i < size) : (i += 1) {
-        sequence[i] = @as(T, @intCast(i)) + 1;
-    }
-
-    return sequence;
+fn makeSequence(comptime T: type, comptime size: usize) [size]T{
+  var sequence: [size]T = undefined;
+  var i: usize = 0;
+  
+  while(i < size) : (i += 1){
+    sequence[i] = @as(T, @intCast(i)) + 1;
+  }
+  
+  return sequence;
 }
 }
+