Array : How to initialize an array from a given array

I want to initialize an uninitialized arrayptr array from an initialized
arratyptr array .

Here is the full code of my attempt that does not compile :

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2(A1,A,n) = let

implement
array_initize$init (i,x) = let
val (fpf | A1) = decode($vcopyenv_vt (A1))
val () = x := g0u2i(i) + arrayptr_get_at_gint(A1,i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () end

Thanks

Sorry for the incomplete solution, but all I have for now is that this may
get you a bit closer:

val idx = g1ofg0_int(g0uint2int(i))
… arrayptr_get_at_gint(A1,idx)On Thursday, February 13, 2014 2:29:13 AM UTC-5, chotu s wrote:

I want to initialize an uninitialized arrayptr array from an initialized
arratyptr array .

Here is the full code of my attempt that does not compile :

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2(A1,A,n) = let

implement
array_initize$init (i,x) = let
val (fpf | A1) = decode($vcopyenv_vt (A1))
val () = x := g0u2i(i) + arrayptr_get_at_gint(A1,i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () end

Thanks

This one works:

staload “share/atspre_staload.hats”

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2{n}(A1,A,n) = let

implement
array_initize$init (i,x) = let
val i = $UNSAFE.cast{sizeLt(n)}(i)
val (fpf | A1) = decode($vcopyenv_vt (A1))
val () = x := A1[i] + sz2i(i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () endOn Thursday, February 13, 2014 2:29:13 AM UTC-5, chotu s wrote:

I want to initialize an uninitialized arrayptr array from an initialized
arratyptr array .

Here is the full code of my attempt that does not compile :

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2(A1,A,n) = let

implement
array_initize$init (i,x) = let
val (fpf | A1) = decode($vcopyenv_vt (A1))
val () = x := g0u2i(i) + arrayptr_get_at_gint(A1,i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () end

Thanks

Thanks a lot guys , code now compiles successfully.

I should have known that i < n need to be shown in array_initize$init , but
why I did not is a mystery to me , oh well my inference engine fails again
:smiley: :smiley:

Just a side not group might get a duplicate message (I think my prev
message was lost)On Thu, Feb 13, 2014 at 7:36 PM, gmhwxi gmh...@gmail.com wrote:

This one works:

staload “share/atspre_staload.hats”

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2{n}(A1,A,n) = let

implement
array_initize$init (i,x) = let
val i = $UNSAFE.cast{sizeLt(n)}(i)

val (fpf | A1) = decode($vcopyenv_vt (A1))

val () = x := A1[i] + sz2i(i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () end

On Thursday, February 13, 2014 2:29:13 AM UTC-5, chotu s wrote:

I want to initialize an uninitialized arrayptr array from an initialized
arratyptr array .

Here is the full code of my attempt that does not compile :

extern
fun arr_exmpl2{n:nat}
(A1 : !arrayptr (int,n),
A : !arrayptr (int?,n) >> arrayptr (int,n) , n: int(n) ): void

implement
arr_exmpl2(A1,A,n) = let

implement
array_initize$init (i,x) = let
val (fpf | A1) = decode($vcopyenv_vt (A1))
val () = x := g0u2i(i) + arrayptr_get_at_gint(A1,i)

(* why does not i or sz2i(i) works above )
(
what is g0u2i and why sz2i(i) does not work here ?? *)

val () = fpf (A1)
in () end

val () = arrayptr_initize(A,i2sz(n))

in () end

Thanks


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/de4be7ba-711c-4bf7-9637-55854a95a2e2%40googlegroups.com
.