Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Are packages like C structs?
PostPosted: Sun Apr 12, 2009 11:10 pm 
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!


Report this post
Top
  
Reply with quote  
 Post subject: Re: packages are not like C structs
PostPosted: Thu May 21, 2009 2:17 pm 

Joined: Wed May 25, 2005 4:16 pm
Posts: 275
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

It is currently Fri May 13, 2022 11:05 am
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group