Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Constants

Oussama Essamadi edited this page Mar 24, 2024 · 2 revisions

LangKama allows for the declaration of constants, providing a way to define values that are intended to remain unchanged throughout the execution of a program. This section details the syntax for constant declaration, common errors associated with constants, and how to avoid them.

Declaring Constants

Constants in LangKama are declared using a syntax similar to variable declaration, but they are intended to hold values that cannot be changed once set.

Declaration with Value

Constants must be declared with an initial value. The declaration starts with a narrative approach, using a sa7 hear me out, followed by the constant name, the is keyword, and the value.

a sa7 hear me out zero is 0.

Error Handling

LangKama includes specific error-handling mechanisms for constants to ensure that their immutable nature is preserved and that declarations are correctly formulated.

UninitializedConstantError

Attempting to declare a constant without specifying an initial value results in an error. Constants must always be initialized during declaration.

a sa7 hear me out zero.  bs Missing initial value

VariableDefinedError (Constant Duplication)

LangKama prevents the redeclaration of constants with the same name, ensuring each constant is uniquely identified within its scope.

a sa7 hear me out zero is 0.
a sa7 hear me out zero is 0.  bs Attempting to duplicate the 'zero' constant

ConstantReassignmentError

Since constants cannot be changed once declared, attempting to reassign a constant's value results in an error.

a sa7 hear me out one is 1.
one is 2.  bs Attempting to reassign the "one" constant

VariableNotDefinedError (Undeclared Constant)

Referencing a constant that has not been declared results in an error. This ensures that all constants are defined before use.

myVar.  bs "myVar" has not been declared