savi-lang / savi

A fast language for programmers who are passionate about their craft.
BSD 3-Clause "New" or "Revised" License
155 stars 12 forks source link

Make it easier to create `Array'val` literals #336

Open mneumann opened 1 year ago

mneumann commented 1 year ago

When I write e.g. [Pair(String).new("a", b"), ...] I get an Array'ref, but how do I turn this into a Array'val? On the callee side, I can use an argument type Array'box which works fine, though just curious, if the argument type would be Array'val, how would I create an Array literal asArray'val?

jemc commented 1 year ago

We do not yet have "recover" blocks as in Pony, or proper region analysis that would be used to construct such a feature.

As a result, the only way to create an Array'iso or Array'val literal, is to ensure that each element has a sendable cap. If that condition is met, then any array literal which is being "assigned to" something of a val or iso type will be automatically lifted to a val or iso array literal.

In this case, your example failed only because Pair.new creates ref objects.

In lieu of recover blocks, this problem can be sidestepped by adding a val and/or iso constructor to the Pair type.