Values in Chapel

Chapel has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

use IO;

proc main() {
    // Strings, which can be added together with +.
    writeln("chapel" + "lang");

    // Integers and floats.
    writeln("1+1 = ", 1 + 1);
    writeln("7.0/3.0 = ", 7.0 / 3.0);

    // Booleans, with boolean operators as you'd expect.
    writeln(true && false);
    writeln(true || false);
    writeln(!true);
}

To run the program, save it as values.chpl and use the chpl compiler:

$ chpl values.chpl -o values
$ ./values
chapellang
1+1 = 2
7.0/3.0 = 2.33333
false
true
false

In this Chapel program:

  1. We use the IO module for input/output operations.
  2. The proc main() defines the main procedure, similar to other languages’ main functions.
  3. Chapel uses writeln() for printing to the console, which is similar to println() in other languages.
  4. String concatenation, arithmetic operations, and boolean operations work similarly to many other programming languages.
  5. Chapel uses // for single-line comments.

Chapel’s syntax is quite similar to C-style languages, making it relatively easy to read and write for those familiar with such languages.