mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Adds Array.from-static function
This commit is contained in:
parent
3222e5cd22
commit
85abcbbf0a
@ -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)))
|
||||
|
||||
|
@ -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">
|
||||
|
@ -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"))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user