Opened 13 years ago

Closed 13 years ago

#360 closed bug (wontfix)

export not working properly if procedure loaded via LIB

Reported by: ren Owned by: hannes
Priority: minor Milestone: 3-1-4 and higher
Component: dontKnow Version: 3-1-3
Keywords: export, keepring Cc:

Description

assuming I have a file called testingexport.txt (or .lib) with following content:

proc testingexport(int n)
{
  int result=n;
  export(result);
}

Now if I do the following, everything works fine:

                     SINGULAR                                 /  Development
 A Computer Algebra System for Polynomial Computations       /   version 3-1-3
                                                           0<
 by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \   March 2011
FB Mathematik der Universitaet, D-67653 Kaiserslautern        \
created type 518 (cone)
created type 519 (fan)
// ** executing /home/ren/trunk/Singular/LIB/.singularrc
> <"testingexport.txt";
> testingexport(2);
> listvar(all);
// result               [0]  int 2

But this does not work:

                     SINGULAR                                 /  Development
 A Computer Algebra System for Polynomial Computations       /   version 3-1-3
                                                           0<
 by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \   March 2011
FB Mathematik der Universitaet, D-67653 Kaiserslautern        \
created type 518 (cone)
created type 519 (fan)
// ** executing /home/ren/trunk/Singular/LIB/.singularrc
> LIB "testingexport.txt";
// ** loaded /home/ren/trunk/Singular/LIB/testingexport.txt 
// ** library testingexport.txt has old format. This format is still accepted,
// ** but for functionality you may wish to change to the new
// ** format. Please refer to the manual for further information.
> testingexport(2);
> listvar(all);
> result;
   ? `result` is undefined
   ? error occurred in or before STDIN line 5: `result;`

The same holds true for "keepring": In both cases, the ring of the procedure is kept, however in the second case Singular forgets what the ring is called. With the procedure

proc testkeepring(int n)
{
  ring r=0,x(1..n),dp;
  keepring r;
}

one gets:

                     SINGULAR                                 /  Development
 A Computer Algebra System for Polynomial Computations       /   version 3-1-3
                                                           0<
 by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \   March 2011
FB Mathematik der Universitaet, D-67653 Kaiserslautern        \
created type 518 (cone)
created type 519 (fan)
// ** executing /home/ren/trunk/Singular/LIB/.singularrc
> LIB "testingexport.txt";
// ** loaded /home/ren/trunk/Singular/LIB/testingexport.txt 
// ** library testingexport.txt has old format. This format is still accepted,
// ** but for functionality you may wish to change to the new
// ** format. Please refer to the manual for further information.
> testkeepring(2);
> basering;
//   characteristic : 0
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x(1) x(2)
//        block   2 : ordering C
> r;
   ? `r` is undefined
   ? error occurred in or before STDIN line 4: `r;`

Change History (2)

comment:1 Changed 13 years ago by gorzel

Owner: changed from somebody to hannes

There is not really a bug (to be resolve as invalid)

If you call export from within a proc loaded by a library, then the object (the variable) is exported by default to the package defined by the library. This means the variable is not defined in the Namespace Top but in the Namespace Testingexport. To access the variable, you have to address it with its full name, i.e. with preceeding Namespace

> LIB "testingexport.lib";
// ** loaded testingexport.lib 
// ** library testingexport.lib has old format. This format is still accepted,
// ** but for functionality you may wish to change to the new
// ** format. Please refer to the manual for further information.
> listvar(package);
// Testingexport        [0]  package (S,testingexport.lib)
// Standard             [0]  package (S,standard.lib)
// Top                  [0]  package (N)
> testingexport(2);
> listvar(Testingexport);
// Testingexport        [0]  package (S,testingexport.lib)
// ::result             [0]  int 2
// ::testingexport      [0]  proc from testingexport.lib
> defined(result);
0
> defined(Testingexport::result);
1

If you want the variable result to defined on Top, then you have use exportto(Top,result);

Add to your file this proc:

proc testingexporttotop(int n)
{
  int result=n;
  exportto(Top,result);
}

and see that it works fine.

> LIB "testingexport.txt";
// ** loaded testingexport.txt 
// ** library testingexport.txt has old format. This format is still accepted,
// ** but for functionality you may wish to change to the new
// ** format. Please refer to the manual for further information.
> testingexport(2);
> Testingexport::result;
2
> testingexporttotop(3);
> result;
3

The manual

http://www.singular.uni-kl.de/Manual/latest/sing_354.htm#SEC394

says that keepring is obsolete. But if you want to use keepring then call first exportto.

Add this proc:

proc testkeepringtotop(int n)
{
  ring r=0,x(1..n),dp;
  exportto(Top,r);
  keepring r;
}

And everything should work as you want:

> LIB "testingexport.txt";
// ** loaded testingexport.txt 
// ** library testingexport.txt has old format. This format is still accepted,
// ** but for functionality you may wish to change to the new
// ** format. Please refer to the manual for further information.
> ring R=0,x,dp;
> testkeepringtotop(2);
> listvar();
// r                    [0]  *ring
// R                    [0]  ring
> basering;
//   characteristic : 0
//   number of vars : 2
//        block   1 : ordering dp
//                  : names    x(1) x(2)
//        block   2 : ordering C

See also what I say in the forum about global variables in Libraries

http://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1927

BTW: 1.) Why do you use a Developper version of Singular? The lastest patches are in UNIX/nighltybuild

2.) Follow Singular's complaints about the unsufficnt library format and name a library *.lib

Last edited 13 years ago by gorzel (previous) (diff)

comment:2 Changed 13 years ago by hannes

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.