19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

foo:String → ()<br />

baz: String → String<br />

then the file is assumed to consist of the declaration of a single API named Blarf .<br />

Unlike component compilation, API compilation does not shadow existing elements of a fortress. If we attempt to<br />

compile an API with the same name as an API already defined in the resident fortress, an error is signaled and the<br />

fortress is left unchanged. To remove an API, we must first remove all components referring to the API, and then issue<br />

the shell command:<br />

fortress removeApi name<br />

A component that exports an API must provide a definition for every program construct declared in the API. For<br />

example, because our component HelloWorld:<br />

component HelloWorld<br />

export Executable<br />

run(args) = print “Hello, world!”<br />

end<br />

exports the API Executable, it must include a definition for the function run . <strong>The</strong> definition of run in HelloWorld<br />

need not include declarations of the parameter type or return type of run , as these can be inferred from the definition<br />

of API Executable.<br />

Components are also allowed to import APIs. A component that imports an API is allowed to use any of the program<br />

constructs declared in that API. For example, the following component imports API Zeepf and calls the function foo<br />

declared in Zeepf :<br />

component Blargh<br />

import Zeepf<br />

export Executable<br />

run(args) = Zeepf.foo(“whatever”)<br />

end<br />

Component Blargh imports the API Zeepf and exports the API Executable. Its run function is defined by calling<br />

function foo , defined in Zeepf . Note that foo must be referred to by the qualified name Zeepf.foo , to distinguish it<br />

from other declarations of foo that are imported by or defined in Blargh. To call foo as an unqualified name, we can<br />

write the following form of import statement:<br />

component Blargh<br />

import {foo} from Zeepf<br />

export Executable<br />

run(args) = Zeepf.foo(“whatever”)<br />

end<br />

In an import statement of the form:<br />

import S from A<br />

all names in the set of names S are imported from API A, and can be referred to as unqualified names within the<br />

importing component. In the example above, the set of names we have imported consists of a single name: foo . If we<br />

had instead written:<br />

import {foo,baz} from Zeepf<br />

19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!