File: Chapel.chpl

package info (click to toggle)
cloc 2.06-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,064 kB
  • sloc: perl: 30,146; cpp: 1,219; python: 623; ansic: 334; asm: 267; makefile: 244; sh: 186; sql: 144; java: 136; ruby: 111; cs: 104; pascal: 52; lisp: 50; haskell: 35; f90: 35; cobol: 35; objc: 25; php: 22; javascript: 15; fortran: 9; ml: 8; xml: 7; tcl: 2
file content (48 lines) | stat: -rw-r--r-- 1,891 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// "Production-grade" hello world
// From https://github.com/chapel-lang/chapel/blob/release/1.16/test/release/examples/hello2-module.chpl

/* This program is conceptually very similar to :ref:`hello.chpl
   <primers-hello>`, but it uses a more structured programming style,
   explicitly defining a module, a configuration constant, and a
   main() procedure.
 */

//
// The following statement declares a module named 'Hello'.  If a
// source file contains no module declarations, the filename minus its
// ``.chpl`` extension serves as the module name for the code it
// contains.  Thus, 'hello' would be the automatic module name for the
// previous :ref:`hello.chpl <primers-hello>` example.
//
module Hello {

//
// This next statement declares a `configuration constant` named
// `message`.  The type is inferred to be a string since the
// initializing expression is a string literal.  Users may override
// the default values of configuration constants and variables on the
// executable's command-line.  For example, we could change the
// default message for a given run using the command line: ``./hello
// --message="hiya!"``.
//
  config const message = "Hello, world!";


// Any top-level code in a module is executed as part of the module's
// initialization when the program begins executing.  Thus, in the
// previous one-line :ref:`hello.chpl <primers-hello>`, the presence
// of a `writeln()` at the file scope formed the implicit `hello`
// module's initialization and would be executed at program startup.
// Since there was no explicit `main()` function or any other
// top-level code, that's all that the program would do.


//
// In this program, we define an entry point for the program by
// defining a procedure named `main()`.  This will be invoked after
// this module and all the modules it uses are initialized.
//
  proc main() {
    writeln(message);
  }
}