Chaga Programming Language: Chapter 2

DECLARE statement

  • Variables are created with the DECLARE statement.
  • The datatype specifies the kind of data a variable will retain.
  • Optionally, one may declare a variable as an array with one, two, or three dimensions with array1, array2, or array3, respectively.
  • The number of array dimensions cannot be changed; however, the size of the dimensions can be adjusted dynamically with the metadata array size attributes, depending on whether the variable is declared with one, two, or three dimensions.

Usage:

  • declare datatype identifier;
  • declare array1 datatype identifier;
  • declare array2 datatype identifier;
  • declare array3 datatype identifier;

Example: declare statements

declare int counter;
declare real length, width, height;
declare string name;
declare array1 int my_1d_array;
declare array2 bool my_2d_array;
declare array3 real my_3d_array;

DEFINE statement

The define command creates a user-defined datatype, procedure, or function.

Usage:

  • define type identifier {parameter list}
  • define datatatype function identifier (datatype parameter list) {statement block}
  • define procedure identifier (datatype parameter list) {statement block}

Example: creating a user-defined datatype.

define type volume
{
  real length;
  real width;
  real height;
}

SET statement

A variable's value is assigned with the SET statement.

Usage:

  • set identifier = expression ;

Example: set statements

define type volume
{
  real length;
  real width;
  real height;
}

declare int counter;
declare real length, width, height;
declare string name;
declare array1 int my_1d_array;
declare array2 bool my_2d_array;
declare array3 real my_3d_array;
declare area rectangle;
declare volume cube, block;

set counter = 5;
set length = 1.001;
set width = 2.001;
set height = 3.001;
set name = "Alfred E. Neuman";
set my_1d_array.size1 = 50;
set my_2d_array.size1 = 4;
set my_2d_array.size2 = 8;
set my_3d_array.size1 = 9;
set my_3d_array.size2 = 9;
set my_3d_array.size3 = 9;
set my_1d_array[49] = -6;
set my_2d_array[1][1] = TRUE;
set my_3d_array[1][2][3] = length;
set rectangle->length = 2;
set rectangle->width = 4;
set cube->length = 3;
set cube->width = 3;
set cube->height = 3;
set block->length = 4;
set block->width = 5;
set block->height = 6;

Math operators

  • +: This operator computes the sum on two operands or it can be used as a unary operator to indicate the sign on one operand.
  • −: This operator computes the difference on two operands or it can be used as a unary operator to indicate the sign on one operand.
  • *: This operator computes the product on two operands.
  • /: This operator computes the quotient on two operands.
  • %: This operator computes the modulo (remainder) on two operands.
  • ^: This operator computes the power of a number. Example: x^2 = x2.

Boolean operators

  • and: This operator performs a Boolean AND operation on two Boolean operands. Example: operand1 and operand2
  • or: This operator performs a Boolean OR operation on two Boolean operands. Example operand1 or operand2
  • not: This operator performs a Boolean NOT operation on one Boolean operand. Example: not operand1
  • xor: This operator performs a Boolean EXCLUSIVE OR operation on two Boolean operands. Example: operand1 xor operand2
  • >=: This operator returns TRUE if the first operand is GREATER THAN OR EQUAL to the second operand otherwise FALSE is returned. Example: operand1 >= operand2
  • <=: This operator returns TRUE if the first operand is LESS THAN OR EQUAL to the second operand otherwise FALSE is returned. Example: operand1 <= operand2
  • >: This operator returns TRUE if the first operand is GREATER THAN the second operand otherwise FALSE is returned. Example: operand1 > operand2
  • <: This operator returns TRUE if the first operand is LESS THAN the second operand otherwise FALSE is returned. Example: operand1 < operand2
  • ==: This operator returns TRUE if the first operand is EQUAL to the second operand otherwise FALSE is returned. Example: operand1 == operand2
  • <>: This operator returns TRUE if the first operand is NOT EQUAL to the second operand otherwise FALSE is returned. Example: operand1 <> operand2

Copyright © 2025, 2026 Robert James Bruce.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is available at https://www.gnu.org/licenses/fdl-1.3.html