Array : How to initialize an array from a given array

30 views
Skip to first unread message

chotu s

unread,
Feb 13, 2014, 2:29:13 AM2/13/14
to ats-lan...@googlegroups.com
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<int> (i,x) = let
  val (fpf | A1) = decode($vcopyenv_vt (A1)) 
  val () = x :=  g0u2i(i) + arrayptr_get_at_gint<int>(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<int>(A,i2sz(n))

in () end



Thanks



Brandon Barker

unread,
Feb 13, 2014, 7:50:04 AM2/13/14
to ats-lan...@googlegroups.com
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<int>(A1,idx)

gmhwxi

unread,
Feb 13, 2014, 9:06:12 AM2/13/14
to ats-lan...@googlegroups.com
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
<int> (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<int>(A,i2sz(n))

in () end


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

chotu s

unread,
Feb 13, 2014, 10:16:48 AM2/13/14
to gmhwxi, ats-lan...@googlegroups.com
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 :D :D 

Just a side not group might get a duplicate message (I think my prev message was lost)



--
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.

Reply all
Reply to author
Forward
0 new messages