Singular
https://www.singular.uni-kl.de/forum/

Are packages like C structs?
https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1706
Page 1 of 1

Author:  Chris Davis [ Sun Apr 12, 2009 11:10 pm ]
Post subject:  Are packages like C structs?

It seems like I should be able to treat a package data type like a C struct, but when I return a package from a procedure, I can't access any of its nested identifiers. I've also tried using importfrom(package,identifier), but that doesn't work either. Here's an example.

Code:
> proc gimmePackage()
. {
.    package apack;
.    int apack::anum = 1;
.
.    return(apack);
. }
>
> package testpack = gimmePackage();
> listvar(testpack);
// testpack             [0]  package (N)
// ::anum               [1]  int 1
>
> testpack::anum;
   ? `anum` is undefined
   ? error occurred in STDIN line 95: `testpack::anum;`
>
> importfrom(testpack,anum);
   ? `anum` not found in `testpack`
   ? error occurred in STDIN line 96: `importfrom(testpack,anum);`
>
> importfrom(testpack,::anum);
   ? error occurred in STDIN line 97: `importfrom(testpack,::anum);`
   ? last reserved name was `importfrom`
   skipping text from `anum` error at token `)`
>
> importfrom(testpack,testpack::anum);
   ? `anum` not found in `testpack`
   ? error occurred in STDIN line 98: `importfrom(testpack,testpack::anum);`


It also seems that poly data types can't be stored in (user-defined) packages. Is that correct?

Any help is greatly appreciated!

Author:  hannes [ Thu May 21, 2009 2:17 pm ]
Post subject:  Re: packages are not like C structs

packages are not like C structs, more like a C++ name space.
It should (and is ) used to avoid name collisions between different
libraries (and the Top level).
And, yes, they contain only types which are ring independent.
Ring depended types (like poly) are contain in their base rings,
#which are quite similiar to packages.

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/