Skip to content
John Horigan edited this page Mar 18, 2015 · 1 revision

The names of shapes, paths, variables, and functions must all be unique. Two paths or two functions with the same name is not allowed. Trying to have two distinct shapes with the same name will either merge all of the rules together or through an error. If two variables have the same name then the newer one shadows the older one (making it invisible) until the newer variable goes out of scope. This is not an issue for individual cfdg files, it just forces the designer to plan out the name usage.

This kind of planning is not always possible when importing another cfdg file. The imported cfdg file may have shapes, paths variables, or functions internal to its own working that happen to be the same as a shape, path, variable, or function in the importing cfdg file. This is known as naming collision, when two separate elements in a shared space of names (aka a namespace) share the same name.

// master.cfdg
import someFile.cfdg
 
path somePath {
  ...
}
 
shape someShape {
  drawSomething[]
}
// someFile.cfdg
 
path somePath {    // Error! Conflicts with somePath in master.cfdg
  ...
}
 
shape drawSomething {
  ...
  somePath[]
}

Context Free solves this issue by allowing a cfdg file to be imported into its own namespace so that there is no possibility of naming collision between the two files.

// master.cfdg
import@foo someFile.cfdg    // import someFile.cfdg into namespace foo
 
path somePath {
  ...
}
 
shape someShape {
  foo::drawSomething[]    // Look for drawSomething in foo namespace, not current namespace
}
// someFile.cfdg
 
path somePath {    // OK! looks like foo::somePath w.r.t. master.cfdg
  ...
}
 
shape drawSomething {
  ...
  somePath[]  // Refers to somePath in current namespace, not the one in master.cfdg
}

Configuration Namespace

Ordinarily, variables can only be declared in the current namespace (shapes, paths, and functions too). Configuration declarations are the exception, they are declared in the CF:: namespace.

CF::Tile = [s 5]
Clone this wiki locally