Re: Issue with conditionally mutating a var twice

2020-07-18 Thread d4v3y_5c0n3s
Thanks everyone, you were all extremely helpful!  I appreciate the advice 
too, and I'll look into using your suggestions to improve the code. Again, 
thanks! :D

On Thursday, July 16, 2020 at 8:12:39 AM UTC-4, d4v3y_5c0n3s wrote:
>
>   So, I'm trying to mutate a var twice in order to replicate some C code 
> that I am trying to port to ATS.  But, I've been scratching my head as to 
> why this would happen, so any help is appreciated.  In an effort to not 
> waste your time, I will be showing you the function with my issue along 
> with the declarations for the relevant functions & typedefs.  Please ask if 
> you'd like me to provide more details that I may have missed.
>
> The function I'm having trouble in:
>
> implement mat4_to_quat ( m ) = let
>   val tr = m.xx + m.yy + m.zz
> in
>   if tr > 0.f then let
> val s = $MATH.sqrt(tr + 1.f)
> val w = s / 2.f
> val x = ( mat4_at(m, 1, 2) - mat4_at(m, 2, 1) ) * (0.5f / s)
> val y = ( mat4_at(m, 2, 0) - mat4_at(m, 0, 2) ) * (0.5f / s)
> val z = ( mat4_at(m, 0, 1) - mat4_at(m, 1, 0) ) * (0.5f / s)
>   in
> quat_new(x, y, z, w)
>   end else let
> val nxt = @[int](1, 2, 0)
> var q = @[float][4](0.f)
> var i = 0
> var j = 0
> var k = 0
> var s = 0
>   in
> *i := ((if mat4_at(m, 1, 1) > mat4_at(m, 0, 0) then 1 else i):int);*
> *i := ((if mat4_at(m, 2, 2) > mat4_at(m, $showtype(i), i) then 2 else 
> i):int);  // <-- this line has the error*
> j := nxt[i];
> k := nxt[j];
> s := $MATH.sqrt( (mat4_at(m, i, i) - (mat4_at(m, j, j), mat4_at(m, k, 
> k))) + 1.f );
> q[i] := s * 0.5f;
> s := (if (s != 0.f) then 0.5f / s else s);
> q[3] := (mat4_at(m, j, k) - mat4_at(m, k, j)) * s;
> q[j] := (mat4_at(m, i, j) + mat4_at(m, j, i)) * s;
> q[k] := (mat4_at(m, i, k) + mat4_at(m, k, i)) * s;
> quat_new(q[0], q[1], q[2], q[3])
>   end
> end
>
>
> Here's the function's declaration:
>
> fun mat4_to_quat ( m: mat4 ) : quat = "sta#%"
>
>
> Here's the declaration for mat4_at:
>
> fun mat4_at {x:nat | x < 4}{y:nat | y < 4} ( m: mat4, x: int x, y: int y ) 
> : float = "sta#%"
>
>
> My full repo can be found here: 
> https://github.com/d4v3y5c0n3s/Goldelish-Engine
> Here's the error message:
>
> patscc -tcats /home/d4v3y/Goldelish-Engine/source/g_engine.dats
> **SHOWTYPE[UP]**(/home/d4v3y/Goldelish-Engine/source/g_engine.dats: 
> 35508(line=1373, offs=55) -- 35509(line=1373, offs=56)): 
> S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int)): S2RTbas(S2RTBASimp(1; 
> t@ype))
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373, 
> offs=55) -- 35509(line=1373, offs=56): error(3): the dynamic expression 
> cannot be assigned the type [S2Eapp(S2Ecst(g1int_int_t0ype); 
> S2Eextkind(atstype_int), S2EVar(6368))].
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35508(line=1373, 
> offs=55) -- 35509(line=1373, offs=56): error(3): mismatch of static terms 
> (tyleq):
> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype); 
> S2Eextkind(atstype_int), S2EVar(6368))
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35512(line=1373, 
> offs=59) -- 35513(line=1373, offs=60): error(3): the dynamic expression 
> cannot be assigned the type [S2Eapp(S2Ecst(g1int_int_t0ype); 
> S2Eextkind(atstype_int), S2EVar(6369))].
> /home/d4v3y/Goldelish-Engine/source/g_engine.dats: 35512(line=1373, 
> offs=59) -- 35513(line=1373, offs=60): error(3): mismatch of static terms 
> (tyleq):
> The actual term is: S2Eapp(S2Ecst(g0int_t0ype); S2Eextkind(atstype_int))
> The needed term is: S2Eapp(S2Ecst(g1int_int_t0ype); 
> S2Eextkind(atstype_int), S2EVar(6369))
>
> |
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/0b3447c4-47cc-47f9-8649-19f55ec5d22do%40googlegroups.com.


Re: unboxed datatypes

2020-07-18 Thread Dambaev Alexander
Well, let's hope, that ATS3 will have such feature

сб, 18 июл. 2020 г. в 06:21, Artyom Shalkhakov :

> Hi Alex,
>
> сб, 18 июл. 2020 г. в 09:17, Dambaev Alexander :
>
>> Hi,
>>
>> datatypes/datavtypes are heap-allocated, which runtime representation, I
>> guess, is a tag and a pointer to data.
>>
>> ATS has unboxed tuples and unboxed records, which runtime representation,
>> I guess, are C's structs
>>
>> Is there a way to define a stack allocated datatype?
>> I think, we can have them by using C's union types for runtime
>> representation. Am I missing something?
>>
>
> This is not supported at the moment.
>
> I too think it would be a great addition!
>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ats-lang-users/CAHjn2KzsFUPptwSPgTrWVR%3DsoA42aSEmUXv4D-MAQAR_K8f%2BKw%40mail.gmail.com
>> 
>> .
>>
>
>
> --
> Cheers,
> Artyom Shalkhakov
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/CAKO6%3DqggX%3DPE0-0FidevEnemk3JUYY6LGGD5zN5FidKNNG2Jsw%40mail.gmail.com
> 
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2Kz9e7c8DKZrnKF3kqNpuDnmNApFORJR8hBs9QtVfBrW-Q%40mail.gmail.com.