Remix.run Logo
TobinCavanaugh 2 days ago

Zena looks super cool! I was wondering if you could walk me through this syntax thats part of the example loops:

``` let iterator = items.[Iterable.iterator](); // <--- this part in particular is confusing me while (let (true, item) = iterator.next()) { console.log(`next: ${item}`); } ```

Dimensional types and formal verification make me super excited to see more of this language. You also probably mention this somewhere and I'm missing it, but any thoughts on adding pure functions / more general mutability enforcements?

spankalee a day ago | parent [-]

Thanks!

So `items.[Iterable.iterator]()` is invoking a symbol-keyed method.

It's declared like:

    export interface Iterable<T> {
      static symbol iterator;

      [iterator](): Iterator<T>;
    }

    export MyArray<T> implements Iterable<T> {
      [Iterable.iterator]() { ... }
    }
This is similar to JS, where you can access properties of an object dynamically with [] notation, but Zena is static and doesn't have any reflection (yet) so the symbol has to be declared and statically resolvable, and Zena has operator overloading an a [] operator so we need a way to differentiate between symbol-keyed access from indexed access ([]), thus the o.[] syntax.

I do want to add pure functions, especially for compile time constants. I want to add a macro system that can either run pure functions (on the AST or IR, not sure yet) at compile time, or run arbitrary code sandboxed in a Wasm module.