Adds Array.from-static function

This commit is contained in:
Tim Deve 2020-05-03 12:15:36 +01:00 committed by Tim Dévé
parent 3222e5cd22
commit 85abcbbf0a
3 changed files with 33 additions and 2 deletions

View File

@ -389,5 +389,12 @@ It will create a copy. If you want to avoid that, consider using [`endo-filter`]
(set! y (Array.length arr)))
(set! a (push-back a (Array.slice arr x y)))
(set! x y)))
a)))
a))
(doc from-static "Turns a `StaticArray` into an `Array`. Copies elements.")
(defn from-static [sarr]
(let-do [darr (allocate (StaticArray.length sarr))]
(for [i 0 (StaticArray.length sarr)]
(aset-uninitialized! &darr i @(StaticArray.unsafe-nth sarr i)))
darr)))

View File

@ -621,6 +621,26 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#from-static">
<h3 id="from-static">
from-static
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (StaticArray a) b)] (Array a))
</p>
<pre class="args">
(from-static sarr)
</pre>
<p class="doc">
<p>Turns a StaticArray into an Array. Copies elements.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#index-of">
<h3 id="index-of">

View File

@ -306,4 +306,8 @@
&[1.0 1.5 2.0 2.5]
&(unreduce 1.0 &(fn [x] (< x 3.0)) &(fn [x] (+ x 0.5)))
"unreduce works")
)
(assert-equal test
&[1 2 3]
&(from-static $[1 2 3])
"from-static works"))