Sketch out the MVP standard library#14
Conversation
Co-authored-by: justinfagnani <522948+justinfagnani@users.noreply.github.com>
Co-authored-by: justinfagnani <522948+justinfagnani@users.noreply.github.com>
| See `docs/design/strings.md` for full details. | ||
|
|
||
| ### 2. Array<T> | ||
| #### 2. Array<T> |
There was a problem hiding this comment.
Do we want an interface for not-necessarily-growable indexed collections so that we have a common interface between Array and List? We should also have ReadonlyArray<T> which is fixed length due to immutability. I've seen the interface Sequence used before.
I wonder about the names here. List is used in Java and Dart, but JavaScript/TypeScript is the most popular language now and a lot of people are used to Array. Can Array be the indexed, growable interface and we come up with a new name for the WASAM-array backed data type? ie FixedArray?
I think most people would want growable arrays or fully immutable arrays. Fixed-length mutable arrays are kind of an anomaly in high level languages.
There was a problem hiding this comment.
Updated the naming scheme in commit 0dfa002:
FixedArray<T>- WASM GC array primitive (fixed-length, mutable)Array<T>- Growable array interface (JS-familiar naming)Sequence<T>- Read-only indexed access interface (common abstraction)ReadonlyArray<T>- Immutable fixed-length array wrapper
The Sequence<T> interface provides the common abstraction for all indexed collections, enabling code to work with any array type without caring about mutability.
| Efficient mutable string building: | ||
|
|
||
| ```typescript | ||
| class StringBuilder { |
There was a problem hiding this comment.
Would we need this if we had multiple internal string implementations, like a Rope, and optimized the + operator? Or is this approach just a lot simpler on us? Array.join() could be an option too.
There was a problem hiding this comment.
Added a discussion in commit 0dfa002. Alternatives considered:
- Rope: O(log n) concat but adds complexity and may hurt small string performance
- Array.join(): Already included in the
Array<T>interface
Recommendation: Start with StringBuilder as the simple explicit approach. Consider Rope as a future optimization if profiling shows string concatenation is a bottleneck.
|
|
||
| ### Math Module (Phase 4) | ||
|
|
||
| Module: `zena:math` |
There was a problem hiding this comment.
Do we want to split the math library between what's available as WASM instructions and what we have to build into the library, like the trig functions?
There was a problem hiding this comment.
Split the math module in commit 0dfa002:
WASM Intrinsics (zero-cost): floor, ceil, trunc, round, sqrt, absF32, minF32, maxF32, copysign
Library Functions (Zena or host): Trig functions (sin, cos, tan, etc.), exponentials (exp, log, pow), integer operations (abs, min, max, clamp)
Recommendation: Start with host delegation for trig/transcendental functions, consider pure Zena implementations later for environments without host math support.
…ce, clarify StringBuilder alternatives, split math module Co-authored-by: justinfagnani <522948+justinfagnani@users.noreply.github.com>
Co-authored-by: justinfagnani <522948+justinfagnani@users.noreply.github.com>
d8f9f3d to
0a9c643
Compare
docs/design/standard-library.mdwith the MVP planFixedArray<T>(WASM primitive),Array<T>(growable)Sequence<T>interface for read-only indexed accessReadonlyArray<T>for immutable arraysOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.