W Wrapl, The Programming Language

Chapter 1

Interactive Mode

In order to quickly test some Wrapl code, Wrapl provides an interactive evaluator, wrapl, normally installed as /usr/bin/wrapl on Linux, and as C:\Program Files\Wrapl\bin\wrapl.exe on Windows. At the Wrapl command prompt, any Wrapl expression or global declaration can be entered. Every expression and declaration in Wrapl must be terminated with a semicolon, ;. The expression or declaration is then evaluated within an incremental global scope, and the result displayed to screen.

By default, wrapl provides a basic line editor for input. Since Wrapl supports multiple threads, Ctrl+C interrupts the main thread and returns to the prompt. To exit the interpreter, use exit;, or Ctrl+\ in Linux.

$ wrapl Interactive Wrapl [1.5.985:985] --> 1 + 1; 2; --> VAR x <- "banana"; "banana" --> ALL x:find("a"); [2, 4, 6] --> ?x; /usr/lib/riva/Agg/List.T --> VAR n <- 0; 0 --> REP n <- n + 1; -- Press Ctrl+C at some stage here ^CInterrupted --> n; 10242967 --> exit; Exiting. $

wrapl accepts several command line arguments, see wrapl for more details.

Batch Mode

Wrapl programs are loaded within a versatile module system called riva. Thus, a Wrapl module saved in the file Hello.wrapl can be run by executing riva Hello.wrapl.

1MOD Hello; 2 3IMP IO.Terminal USE Out; 4 5Out:write("Hello world!\n"); 6 7END Hello.
$ riva Hello.wrapl Hello world! $

The full filename is required since by default riva does not add the current working directory to the module search path. To add the current directory to the search path, use -L..

$ riva Hello Error: module Hello not found $ riva -L. Hello Hello world! $

On *nix systems which support shell scripts, Wrapl modules can be made directly executable by including the line #!/usr/bin/riva at the beginning of the file, and making the file executable with chmod +x filename. The Wrapl module loader will automatically skip over a #! line at the start of a file. Note that this method loads the file by filename, as described above, so that the directory containing the executable script will not be added to the module search path.

1#!/usr/bin/riva 2MOD Hello; 3 4IMP IO.Terminal USE Out; 5 6Out:write("Hello world!\n"); 7 8END Hello.
$ chmod +x hello $ ./hello Hello world! $

Comments

Line comments in Wrapl extend from -- to the end of the line. Block comments extend from -= to the matching =-. Note that block comments may be nested, however if -= or =- is in a line comment, it will be ignored.

Examples:

1MOD Main; 2 3VAR x; -- This is a line comment 4 5DEF f(x) ( 6 VAR y -= 7 This is a block comment 8=- <- 100; 9 RET x + 200; 10); 11 12END Main.

Source Encoding

The Wrapl interpreter accepts source code in UTF-8. This means that identifiers can be written using UTF-8 characters, which can allow for neater source code, especially when using mathematical symbols. In addition, there are single UTF-8 character equivalents of some keywords/operations. Of course, the Wrapl interpreter will accept code using only the ASCII subset of characters.

1MOD Main; 2 3IMP IO.Terminal USE Out; 4 5VAR Ω ← ALL 1:to(10); 6 7Out:write('Mean = {(∑ Ω:values) / Ω:length}\n'); 8 9END Main.

Navigate