Read-only forum archive

Access local ring elements outside the procedure

Access local ring elements outside the procedure

vinay · Thu Apr 11, 2019 8:36 am

I am writing a small procedure. I am defining a ring inside the procedure (depending upon the parameter to the proc). The some computations are done and then procedure returns objects in this ring. Here is a sample code:

Code:
    LIB "ring.lib";
    int p = 7; // primality of p or prime power is checked beforehand.
   
    proc mytest( int n )
    {
        ring Qz = (0,z),x,dp;
        minpoly = rootofUnity( n );
        poly i = z^(n-1);
        return (i);
    }
    ring dummy;
    mytest(7);

I am getting the following message:
Quote:
? ring change during procedure call test: dummy -> Qz (level 1)

I also tried with `export Qz`, just before return, but doesnt help. Any solution?

Not sure if this is relevant: It seems the command `test` is already defined!!!
Code:
> test(4);
// ** Gerhard, use the option command
>



-- VInay

Re: Access local ring elements outside the procedure

hannes · Thu Apr 11, 2019 4:34 pm

One can not return (from a procedure) an object belonging to a ring which did not exist at the start of the procedure.
What you can do:
inside your procedure:
- create a ring inside the procedure
- create an object in this ring
- export the object (so it will not destroyed at the end of the procedure)
- return the ring
after the return:
- change into the returned ring
- access the object
see for an example: solve from solve.lib