b1a5dc3cb9a5 — Leonard Ritter tip 28 days ago
* `Generator` now supports `countof`
2 files changed, 13 insertions(+), 0 deletions(-)

M lib/scopes/core.sc
M testing/test_iter2.sc
M lib/scopes/core.sc +9 -0
@@ 3710,6 3710,15 @@ let va-option =
                 let self = (bitcast self Closure)
                 `(self)
 
+    __countof =
+        inline (self)
+            let init valid? at next = (self)
+            loop (x stat... = 0:usize (init))
+                if (valid? stat...)
+                    repeat (add x 1:usize) (next stat...)
+                else
+                    break x
+
 'set-docstring Generator '__call
     """"*spice*{.property} `__call`{.descname} (* self *)[](#scopes.Generator.spice.__call "Permalink to this definition"){.headerlink} {#scopes.Generator.spice.__call}
 

          
M testing/test_iter2.sc +4 -0
@@ 59,3 59,7 @@ let x y =
 
 assert (x == 45)
 assert (y == -45)
+
+test ((countof (range 3)) == 3)
+
+;
  No newline at end of file