Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
language:namespaces [2024/07/27 12:49]
rajit [Opening namespaces]
language:namespaces [2024/07/27 12:52] (current)
rajit [Renaming namespaces]
Line 139: Line 139:
 ===== Opening namespaces ===== ===== Opening namespaces =====
  
- +If  a project has many different people working on it, it can be convenient 
-A second issue is one that is more about convenience. Consider a +to have each component/module in their
-project that has many different people working on it, each in their+
 own namespace to avoid naming conflicts. This situation can result in own namespace to avoid naming conflicts. This situation can result in
 very long type names. Plus it would be more bookkeeping to have to very long type names. Plus it would be more bookkeeping to have to
 create a test environment for the types within, say, create a test environment for the types within, say,
 ''processor::lib''---not just because of the long type names, but ''processor::lib''---not just because of the long type names, but
-because not all types might be exported! In this case we can say:+because not all types might be exported!  
 + 
 +As a syntactic convenience, we can say:
  
 <code act> <code act>
Line 179: Line 180:
 In this example, the ''open'' construct enables one to rename a namespace. Once this In this example, the ''open'' construct enables one to rename a namespace. Once this
 has occured, there cannot be any naming conflicts. This version of ''open'' is a renaming construct; after the open statement, the old name for the namespace is eliminated. has occured, there cannot be any naming conflicts. This version of ''open'' is a renaming construct; after the open statement, the old name for the namespace is eliminated.
 +
 +Another renaming scenario that can be useful is to move a namespace into another one.
 +<code act>
 +import lib;
 +import lib => priv;
 +</code>
 +The first import statement above loads in the ''lib'' namespace. The second moves the namespace //into// ''priv''. If ''priv'' doesn't exist as a namespace, it is created. With this sequence, the original ''lib'' is now accessed as ''priv::lib''.