Chaga Programming Language: Chapter 3

Functions and Procedures

  • Functions and procedures allow one to define a series of programming statements as a subroutine. This technique promotes modularity and reduces code duplication.
  • Functions and procedures are invoked from a calling program using the CALL statement.
  • Functions and procedures both acccept zero or more inputs parameters.
  • Functions return one or more parameters to the calling program.
  • Procedures do not return a value to the calling program.

DEFINE statement

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

CALL statement

  • set identifier = call identifier (parameter list);

Example:

define int function read_keyboard (pointer buffer)
{
  declare num_bytes;
  [...]
  return num_bytes;
}

define procedure example (void)
{
  declare string input_buf;
  declare int num_bytes_read;
  [...]
  set num_bytes_read = call read_keyboard (input_buf.address);
}


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