Difference between revisions of "Language Reference/Constants"

From wiki.visual-prolog.com
m (1 revision(s))
(TypeExpression)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{languageReferenceNavbar|Constants}}
{{languageReferenceNavbar|Constants}}


== Constants Sections ==
=== Constants Sections ===


A <vp>constants</vp> section defines a set of constants in the current scope.
A <vp>constants</vp> section defines a set of constants in the current scope.
Line 8: Line 8:
     constants <ConstantDefinition>-dot-term-list-opt</vipbnf>
     constants <ConstantDefinition>-dot-term-list-opt</vipbnf>


== Constant Definitions ==
=== Constant Definitions ===


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>
<ConstantDefinition> :    <ConstantName> : <TypeName> = <ConstantValue></vipbnf>
    <ConstantName> : <TypeExpression> = <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 lower case identifier {{lang2|Lexical_Elements|Identifiers|lowerCaseIdentifier}}.
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}}.


If the {{lang2|Domains|Type_Names|typeName}} is omitted, then the constant domain must be univocally determined by the <vpbnf><ConstantValue></vpbnf> expression. The {{lang2|Domains|Type_Names|typeName}} can be omitted only for the following built-in domains:
The {{lang2|Domains|Type_Expressions|TypeExpression}} 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).
Line 29: Line 28:
#{{lang2|Built-in_entities|char|Character}} constants.
#{{lang2|Built-in_entities|char|Character}} constants.


'''Examples''':
{{Example|
 
<vip>constants
<vip>constants
     my_char = 'a'.
     my_char = 'a'.
Line 36: Line 34:
     binaryFileName = "mybin".
     binaryFileName = "mybin".
     myBinary = #bininclude(binaryFileName).</vip>
     myBinary = #bininclude(binaryFileName).</vip>
}}

Latest revision as of 15:13, 2 May 2017

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 : TypeExpression = 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 TypeExpression can be omitted only for the following built-in domains:

  1. 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).
  2. Binary constants.
  3. String constants.
  4. Character constants.
Example
constants
    my_char = 'a'.
    true_const : boolean = true.
    binaryFileName = "mybin".
    myBinary = #bininclude(binaryFileName).