The Chaga programming language contains the following built-in functions and procedures:
Usage:
define procedure fizzbuzz (int counter) { declare int state; set state = 0; if ((counter % 3) == 0) { set state = 1; } if ((counter % 5) == 0) { set state = state * 2 + 2; } if (state == 1) { call print ("Fizz"); } else { if (state == 2) { call print ("Buzz"); } else { if (state == 4) { call print ("Fizzbuzz"); } else { call print (counter); } } } } define function main (int argc, pointer argv) return (int) { declare int counter; set counter = 1; while (counter <= 100) { call fizzbuzz (counter); set counter = counter + 1; if (counter <= 100) { call print (", "); } else { call print ("\n"); } } return (0); }
Returns the date denoted by output_date_identifier resulting from adding an input number of days denoted by input_int_datatype to the input date denoted by input_date_datatype.
Jump to top
Returns the date denoted by output_date_identifier resulting from adding an input number of months denoted by input_int_datatype to the input date denoted by input_date_datatype.
Returns the date denoted by output_date_identifier resulting from adding an input number of years denoted by input_int_datatype to the input date denoted by input_date_datatype.
Returns the day from an input DATE datatype variable as an integer datatype.
Returns the day name (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) from an input DATE variable as a string datatype.
Example: date_get_day_name
declare date d1; declare string s1, day_name; set s1 = "2026-11-26"; // string format for date is YYYY-MM-DD format. set d1 = call string_to_date (s1); day_name = call date_get_day_name (d1); call print (day_of_week, "\n");
Output from date_get_day_name
Thursday
Returns the month from an input DATE datatype variable as an integer (int datetype).
Returns the name of the month (January, February, March, April, May, June, July, August, September, October, November, December) from an input DATE datatype variable as an integer (int datetype).
Returns the four-digit year from an input DATE datatype variable as an integer (int datetype).
Returns the current date in YYYY-MM-DD format.
Updates the day of an input DATE datatype denoted by input_date_datatype variable to the value denoted by input_integer_datatype. The input_integer_datatype must be a value between 1 and 31 inclusive.
Updates the month of an input DATE datatype denoted by input_date_datatype variable to the value denoted by input_integer_datatype. The input_integer_datatype must be a value between 1 and 12 inclusive.
Updates the year of an input DATE datatype denoted by input_date_datatype variable to the value denoted by input_integer_datatype.
Returns the date denoted by output_date_identifier resulting from subtracting an input number of days denoted by input_int_datatype to the input date denoted by input_date_datatype.
Returns the date denoted by output_date_identifier resulting from subtracting an input number of months denoted by input_int_datatype to the input date denoted by input_date_datatype.
Returns the date denoted by output_date_identifier resulting from subtracting an input number of years denoted by input_int_datatype to the input date denoted by input_date_datatype.
Returns a date denoted by output_date_identifier resulting from subtracting the first input date denoted by input_date_datatype1 from a second input date denoted by input_date_datatype2.
Add a new element to the left side of a list.
Example: list_add_element_left
declare int i1; declare real r1, r2; declare list L1; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_left (L1, i1); call list_add_element_left (L1, r1); call list_add_element_left (L1, r2); call print (L1, "\n");
Output from list_add_element_left
{2.718, 3.14, 1}
Add a new element to the right side of a list.
Example: list_add_element_right
declare int i1; declare real r1, r2; declare list L1; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); call print (L1, "\n");
Output from list_add_element_right
{1, 3.14, 2.718}
Copy the leftmost element in a list.
Example: list_get_element_left
declare int i1; declare real r1, r2; declare list L1, L2; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); set L2 = call list_copy_element_left (L1); call print (L2, "\n");
Output list_copy_element_left
{1}
Copy the rightmost element in a list.
Example: list_copy_element_right
declare int i1; declare real r1, r2; declare list L1, L2; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); set L2 = call list_copy_element_right (L1); call print (L2, "\n");
Output list_copy_element_right
{2.718}
Remove the leftmost element from a list.
Example: list_delete_element_left
declare int i1; declare real r1, r2; declare list L1; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); call list_delete_element_left (L1); call print (L1, "\n");
Output from list_delete_element_left
{3.14, 2.718}
Remove the rightmost element from a list.
Example: list_delete_element_right
declare int i1; declare real r1, r2; declare list L1; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); call list_delete_element_right (L1); call print (L1, "\n");
{1, 3.14}
Retrieve the number of elements in a list.
Example: list_length
declare int i1, num_items; declare real r1, r2; declare list L1; set i1 = 1; set r1 = 3.14; set r2 = 2.718; call list_add_element_right (L1, i1); call list_add_element_right (L1, r1); call list_add_element_right (L1, r2); set num_items = call list_length (L1); call print (num_items, "\n");
Output from list_length
3
Compare string1 to string2. Possible return values:
Example: string_compare
declare string s1, s2; declare int result1, result2, result3; set s1 = "Never odd or even"; set s2 = "Never even or odd"; set result1 = call string_compare (s1, s2); set result2 = call string_compare (s2, s1); set result3 = call string_compare (s1, s1); call print (result1, "\n"); call print (result2, "\n"); call print (result3, "\n");
Output from string_compare
1 -1 0
Copy the string stored in input_string_identifier in reverse order.
Example: string_copy_reverse
declare string input_string, reversed_string; set input_string = "Never odd or even" set reversed_string = call string_copy_reverse (input_string); call print (reversed_string, "\n");
Output from string_copy_reverse
neve ro ddo reveN
Copy the string segment beginning at begin_byte_identifier and ending at end_byte_identifier inclusive from string source input_string_identifier. Note: constants may be used instead of identifiers for the beginning and ending byte positions.
Example: string_copy_segment
declare string input_string, output_string1, output_string2, output_string3, output_string4; declare int begin_byte_position, end_byte_position; set begin_byte_position = 0; set end_byte_position = 2; set input_string = "foo bar baz zab rab oof" set output_string1 = call string_copy_segment (input_string, begin_byte_position, end_byte_position); set output_string2 = call string_copy_segment (input_string, 0, end_byte_position); set output_string3 = call string_copy_segment (input_string, begin_byte_position, 2); set output_string4 = call string_copy_segment (input_string, 0, 2); call print (output_string1, "\n"); call print (output_string2, "\n"); call print (output_string3, "\n"); call print (output_string4, "\n");
Output from string_copy_segment
foo foo foo foo
Copy number_of_bytes bytes from string source input_string_identifier beginning at leftmost position of input string.
Example: string_copy_segment_left
declare string input_string, output_string1, output_string2; declare int number_of_bytes; set number_of_bytes = 7; set input_string = "foo bar baz zab rab oof" set output_string1 = call string_copy_segment_left (input_string, number_of_bytes); set output_string2 = call string_copy_segment_left (input_string, 7); call print (output_string1, "\n"); call print (output_string2, "\n");
Output from string_copy_segment_left
foo bar foo bar
Copy number_of_bytes bytes from the end of input string source input_string_identifier.
Example: string_copy_segment_right
declare string input_string, output_string1, output_string2; declare int number_of_bytes; set number_of_bytes = 7; set input_string = "foo bar baz zab rab oof" set output_string1 = call string_copy_segment_right (input_string, number_of_bytes); set output_string2 = call string_copy_segment_right (input_string, 7); call print (output_string1, "\n"); call print (output_string2, "\n");
Output from string_copy_segment_right
rab oof rab oof
Copy string stored in input_string_identifier converting all uppercase characters to lowercase.
Example: string_copy_lowercase
declare string input_string, output_string; set input_string = "FOO! 'BAR?' \"BAZ\"." set output_string = call string_copy_lowercase (input_string); call print (output_string, "\n");
Output from string_copy_lowercase
foo! 'bar?' "baz".
Copy string stored in input_string_identifier converting all lowercase characters to uppercase.
Example: string_copy_uppercase
declare string input_string, output_string; set input_string = "foo! 'bar?' \"baz\"."; set output_string = call string_copy_uppercase (input_string); call print (output_string, "\n");
Output from string_copy_uppercase
FOO! 'BAR?' "BAZ".
Copy string stored in input_string_identifier converting each letter in a word to lowercase except for the first letter. The first letter is converted to uppercase.
Example: string_copy_titlecase
declare string input_string, output_string; set input_string = "FOO! 'BAR?' \"BAZ\"."; set output_string = call string_copy_titlecase (input_string); call print (output_string, "\n");
Output from string_copy_titlecase
Foo! 'Bar?' "Baz".
Delete a string segment beginning at begin_byte_position and ending at end_byte_position inclusive from string source input_string_identifier.
Example: string_delete_segment
declare string input_string1, input_string2, input_string3, input_string4; declare int begin_byte_position, end_byte_position; set begin_byte_position = 4; set end_byte_position = 7; set input_string1 = "foo bar baz"; set input_string2 = input_string1; set input_string3 = input_string1; set input_string4 = input_string1; call string_delete_segment (input_string1, begin_byte_position, end_byte_position); call string_delete_segment (input_string2, begin_byte_position, 7); call string_delete_segment (input_string3, 4, end_byte_position); call string_delete_segment (input_string4, 4, 7); call print (input_string1, "\n"); call print (input_string2, "\n"); call print (input_string3, "\n"); call print (input_string4, "\n");
Output from string_delete_segment
foo baz foo baz foo baz foo baz
Delete number_of_bytes bytes from string source input_string_identifier beginning at leftmost position of input string.
Example: string_delete_segment_left
declare string input_string1, input_string2; declare int number_of_bytes; set number_of_bytes = 4; set input_string1 = "foo bar baz"; set input_string2 = input_string1; call string_delete_segment_left (input_string1, number_of_bytes); call string_delete_segment_left (input_string2, 4); call print (input_string1, "\n"); call print (input_string2, "\n");
Output from string_delete_segment_left
bar baz bar baz
Delete number_of_bytes bytes from the end of input string source input_string_identifier.
Example: string_delete_segment_right
declare string input_string1, input_string2; declare int number_of_bytes; set number_of_bytes = 4; set input_string1 = "foo bar baz"; set input_string2 = input_string1; call string_delete_segment_right (input_string1, number_of_bytes); call string_delete_segment_right (input_string2, 4); call print (input_string1, "\n"); call print (input_string2, "\n");
Output from string_delete_segment_right
Return a list of positions (list datatype) for every match of string pattern in an input string. The status UNDEFINED is returned if the string pattern is not found.
Example: string_search_all_matches
declare string input_string, keyword; declare list result; set input_string = "haystack needle haystack needle"; set keyword = "needle"; set result = call string_search_all_matches (input_string, keyword); call print (result, "\n");
Output from string_search_all_matches
{9, 25}
Return the first position (whole number) where a string pattern matches an input string. The status UNDEFINED is returned if the string pattern is not found.
Example: string_search_first_match
declare string input_string, keyword; declare list result; set input_string = "haystack needle haystack needle" set keyword = "haystack"; set result = call string_search_first_match (input_string, keyword); call print (result, "\n");
Output from string_search_first_match
{0}
Return the last position (whole number) where a string pattern matches an input string. The status UNDEFINED is returned if the string pattern is not found.
Example: string_search_last_match
declare string input_string, keyword; declare list result; set input_string = "haystack needle haystack needle"; set keyword = "needle"; set result = call string_search_last_match (input_string, keyword); call print (result, "\n");
Output from string_search_last_match
{25}
Remove leading bytes which match byte or input_byte_identifier from left side of input_string_identifier and trailing bytes from right of input_string_identifier which match byte or input_byte_identifier. Examples:
Example: string_trim
declare string input_string1, input_string2; declare char byte_to_remove; set byte_to_remove = "-"; set input_string1 = "-------Dashes-------"; set input_string2 = input_string1; call string_trim (input_string1, "-"); call string_trim (input_string2, byte_to_remove); call print (input_string1, "\n"); call print (input_string2, "\n");
Output from string_trim
Dashes Dashes
Remove leading bytes from left side of input_string_identifier which match byte.
Example: string_trim_left
declare string input_string1, input_string2; declare char byte_to_remove; set byte_to_remove = " "; set input_string1 = " Leading spaces."; set input_string2 = input_string1; call string_trim_left (input_string1, " "); call string_trim_left (input_string2, byte_to_remove); call print (input_string1, "\n"); call print (input_string2, "\n");
Output from string_trim_left
Leading spaces. Leading spaces.
Remove trailing bytes from right side of input_string_identifier which match byte.
Example: string_trim_right
declare string input_string1, input_string2; declare char byte_to_remove; set byte_to_remove = "."; set input_string1 = "Trailing periods...."; set input_string2 = input_string1; call string_trim_right (input_string1, "."); call string_trim_right (input_string2, byte_to_remove); call print (input_string1, "\n"); call print (input_string2, "\n");
Output from string_trim_right
Trailing periods Trailing periods
Compute the factorial for a non-negative integer.
Example: factorial
declare int input_number, result1, result2; set input_number = 25; set result1 = call factorial (input_number); set result2 = call factorial (25); call print (output_string1, "\n"); call print (output_string2, "\n");
Output from factorial
15511210043330985984000000 15511210043330985984000000
Compute the nth_root of a number using bisection method. The input number may be int, real, imaginary, or complex datatype. Note: this function will return two roots as a list datatype. Results may be may be integer, real, imaginary, or complex.
Compute the nth_root of a number using the Newton-Raphson method. The input number may be int, real, imaginary, or complex datatype. Note: this function will return two roots as a list datatype. Results may be may be integer, real, imaginary, or complex.
Convert bool datatype to int dataype.
Convert bool datatype to real dataype.
Convert bool datatype to string dataype.
Convert complex datatype into a list dataype with two elements. The first element is the real component of the complex number. The second element is the imaginary component of the complex number.
Convert complex datatype to string dataype.
Convert date datatype to list dataype.
Convert date datatype to string dataype.
Convert int datatype to bool dataype.
Convert int datatype to real dataype.
Convert int datatype to string dataype.
Convert LIST datatype to string dataype.
Convert real datatype to bool dataype.
Convert real datatype to int dataype. Note: input real right of decimal will be truncated upon conversion to int datatype. Example:
Convert real datatype to string dataype.
Convert string datatype to bool dataype.
Convert string datatype to date dataype.
Convert string datatype to int dataype.
Convert string datatype to list dataype.
Convert string datatype to real datype.
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