Difference between revisions of "Language Reference/Constants"
From wiki.visual-prolog.com
| m (header levels) |  (→Constant Definitions:  BNF plus remove strange sentence) | ||
| Line 12: | Line 12: | ||
| A constant definition defines a named constant, its type, and its value. | A constant definition defines a named constant, its type, and its value. | ||
| <vipbnf><ConstantDefinition>: | <vipbnf><ConstantDefinition>: one of | ||
|      <ConstantName> = <ConstantValue> |      <ConstantName> = <ConstantValue> | ||
|     <ConstantName> : <TypeName> = <ConstantValue></vipbnf> | |||
| <vipbnf><ConstantName>: | <vipbnf><ConstantName>: | ||
|      <LowerCaseIdentifier></vipbnf> |      <LowerCaseIdentifier></vipbnf> | ||
| The <vpbnf><ConstantValue></vpbnf> should be an expression, which can be evaluated at compile time and it should have the type of the correspondent domain. The <vpbnf><ConstantName></vpbnf> should be a  | The <vpbnf><ConstantValue></vpbnf> should be an expression, which can be evaluated at compile time and it should have the type of the correspondent domain. The <vpbnf><ConstantName></vpbnf> should be a {{lang2|Lexical_Elements|Identifiers|lower case identifier}}. | ||
| The {{lang2|Domains|Type_Names|TypeName}} can be omitted only for the following built-in domains: | |||
| #Numerical (i.e. integral or real) constants. In this case, the corresponding anonymous numerical domain is adopted for a constant (see the {{lang2|Domains|Integral_Domains|numerical domains}} for details). | #Numerical (i.e. integral or real) constants. In this case, the corresponding anonymous numerical domain is adopted for a constant (see the {{lang2|Domains|Integral_Domains|numerical domains}} for details). | ||
Revision as of 13:19, 17 October 2008
Constants Sections
A constants section defines a set of constants in the current scope.
ConstantsSection : constants ConstantDefinition-dot-term-list-opt
Constant Definitions
A constant definition defines a named constant, its type, and its value.
ConstantDefinition: one of ConstantName = ConstantValue ConstantName : TypeName = ConstantValue
ConstantName: LowerCaseIdentifier
The ConstantValue should be an expression, which can be evaluated at compile time and it should have the type of the correspondent domain. The ConstantName should be a lower case identifier.
The TypeName can be omitted only for the following built-in domains:
- Numerical (i.e. integral or real) constants. In this case, the corresponding anonymous numerical domain is adopted for a constant (see the numerical domains for details).
- Binary constants.
- String constants.
- Character constants.
Examples:
constants my_char = 'a'. true_const : boolean = true. binaryFileName = "mybin". myBinary = #bininclude(binaryFileName).

