Functionally Equivalent Language Translation →
(const (const-name (value-expression)) (const (PI 3.14159) (E 2.718)) (const (SIGNON "Hello World"))
This allows you to instruct the coder to declare a constant. Can be used inside or outside of a CLASS declaration. The (const-name value-expression)
can be any valid FELT expression but must translate to valid code for the chosen target language. 'CONSTC' allows back-end coders to allow for instance and class constants should such a thing be available. Convention dictates names are in uppercase but you do not have to follow convention. Ever ;)
When used outside of a class-definition the CONST
instruction instructs the back-end to generate an "immutable" value in the generated source code. For PHP this means using the const
keyword as opposed to DEFINE
which uses the PHP keyword of the same name.
The examples given in the head render to PHP like so:
const PI = 3.14159; const E = 2.718; const SIGNON = "Hello World";
JavaScript doesn't yet have the same concept and so FELT makes a best guess and generates a bunch of var
-s like so:
var PI = 3.14159; var E = 2.718; var SIGNON = "Hello World";
When the CONST
instruction is used within the context of a currently active CLASS
declaration the behaviour adapts itself as required by the selected back-end coder.
The modified example source now has a class:
(class ConstantDemo
(const (PI 3.14159) (E 2.718))
(const (SIGNON "Hello World")))
For PHP that means pretty much nothing as the syntax is the same, just within the scope of a class:
class ConstantDef { const PI = 3.14159; const E = 2.718; const SIGNON = "Hello World"; }
JavaScript doesn't really have "classes", being a prototype based language, but despite that FELT makes the "most effective" decision and the back-end coder will generate this code.
function ConstantDef () { this.PI = 3.14159; this.E = 2.718; this.SIGNON = "Hello World"; }
Note that this time the constants have been prefixed with this
to make them available to the instance.