cl84

0 Reputation

2 Badges

14 years, 299 days

MaplePrimes Activity


These are answers submitted by cl84

Hi ,

OK, the initializer should be a list. Now I produced another test case that is like what I want to do.

But I cannot find the reason why the convert(rtable(...), Vector) stuff works outside the procedure but not in the procedure. Without a procedure its type after conversion is Vector, but it looks like the conversion is not performed when translating the procedure.

 

> doesnotwork := proc(p)
>     if(p<0) then
>         convert(rtable(1..3, {1=2*p, 2=2.7, 3=p^2}), Vector);
>     else
>         Vector([-1,2,p*p]);
>     end if;
> end proc;
doesnotwork := proc(p)
  if p < 0 then
    convert(rtable(1 .. 3, {2 = 2.7, 1 = 2*p, 3 = p^2}), Vector)
  else
    Vector([-1, 2, p*p])
  end if;
end proc;
> CodeGeneration[C](doesnotwork);
Error, (in IssueError) cannot recognize rtable initializer {2 = 2.7, 1 = 2*, 3 = ^2}
> # however, the convert(rtable( ... )) stuff is of type Vector
> whattype(convert(rtable(1..3, {1=2*p, 2=2.7, 3=p^2}), Vector));
                          Vector[row]
> works := proc(p)
>     if(p<0) then
>         Vector([2*p,2.7,p^2]);
>     else
>         Vector([-1,2,p*p]);
>     end if;
> end proc;
works := proc(p)
  if p < 0 then Vector([2*p, 2.7, p^2]) else Vector([-1, 2, p*p]) end if;
end proc;
> CodeGeneration[C](works);
void works (int p, int cgret[3])
{
  if (p < 0)
    cgret[0] = 2 * p;
    cgret[1] = 0.27e1;
    cgret[2] = p * p;
  else
    cgret[0] = -1;
    cgret[1] = 2;
    cgret[2] = p * p;
}

Hi,

sorry for the double posting of my question.

 

The first time my browser crashed. When I came back to the Questions section, I appeared to me that my Question wasn't posted. But now I see, that indeed it has been successfully submitted to the website.

 

CU

- Christoph

Page 1 of 1