Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; GeSHi has a deprecated constructor in /srv/http/www.cosmoslang.org/wiki/cookbook/geshi/geshi.php on line 259
Decl | Cosmos Programming Language

Decl

You cannot have a Cosmos program without a "declaration". At the very least you must declare the name of the module.

 module SomeName;

What's common to all declarations, is that they name something, and tells at least what kind of thing, the name is referring to. In the snippet above, a name "SomeName" is declared as being a kind of "module".

The "definition" of the module will then follow the source text declaring the module.

The terms declaration and definition are very similar to what's understood from C/C++. But the distinction is not hugely important because Cosmos doesn't need header files and doesn't need declarations and their uses to be ordered in any particular way.

The only cases where the distinction between declarations and definitions are significant is, when using precompiled libraries.

In that case, you have a Cosmos source file that basically only contain declarations, and basically no definitions. (similar to your average header file in C).

module liblog;

alias LogLevel = i8;
enum : LogLevel
{
        Debug,
        Info,
        Warning,
        Error,
        Fatal,
}

class Log
{
        @private this();
        @private ~this();
        @static @property void Level(LogLevel logging_level);
        @static @property LogLevel Level();
        @static void Write(LogLevel logging_level, c8[] text);
}

That code doesn't contain a single definition, only declarations.

Page last modified on December 30, 2015