It is currently Thu Nov 21, 2019 7:19 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: AliasModule to re-declare module names with an alias
PostPosted: Wed Oct 02, 2019 7:54 am 
Offline
Addict
Addict

Joined: Sat Jun 30, 2007 8:04 pm
Posts: 3362
Lets say that I have various Shape modules that implement the types long, float, and double for 2D and 3D shapes, resulting in 6 modules. I also have another set of modules for different kinds of shapes such as Triangle, Rectangle, Pentagon, Octagon, Polygon, etc.

We cannot declare modules within other modules:

Code:
DeclareModule Shape2i
  DeclareModule Triangle2i
  EndDeclareModule
EndDeclareModule


This is something that I wish we could do. But that only solves half the problem. Sometimes I want a module in scope but under a different name.

For example, lets say that modules Shape2i and Triangle2i are defined in the global scope. Once I decide I want "2i" shapes, I shouldn't need to refer to the primitive type again. Therefore I would define Shape2i as such:

Code:
DeclareModule Shape2i
  AliasModule Triangle Triangle2i
EndDeclareModule


This would allow me to access "Triangle" from within Shape2i as Shape2i::Triangle.

Then in the global scope, once I decide which shape I want to use for my program, I can alias it there too, providing access with a typeless naming scheme.

Code:
AliasModule Shape Shape2i

Shape::Triangle::new()


This is sort of a way to fake generics/templates with information hiding through aliases. The major difference being that we would still have to not only implement every type we wish to support explicitly, but also use the AliasModule keyword to bring it into scope.


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye