2 Hello World

We start with the simplest of all programs that prints the statement 'Hello World' on the screen.

Program 1: HelloWorld.bet

ORIGIN '~beta/basiclib/betaenv'
---- program: descriptor ----
   (*  HelloWorld.bet:
    *  =======================            
    *   Author: J.Vaucher
    *   Purpose: 
    *    This is the simplest program possible.
    *    Being able to compile and run it shows that the
    *    compiler exists and that PATHS and ALIASES have been 
    *    correctly set.  It also brings out "meta-programming" 
    *    considerations like the "fragment" system.
   'Hello world !' -> putline  

This illustrates the basic syntax of a BETA program:


In this case, there are no declarations and the statement part is merely a simple output statement.

The bulk of the program text is in the form of a comment traditionally delimited by (* and *). In the BETA book [MMN 93], comments are shown delimited by { and } but the compiler only recognizes the form shown in Program 1.

The first two lines of the program are not strictly BETA (but are essential for correct compilation). They are part of the fragment specification language that describes inter-relationships between the various BETA modules that compose a complete program. A brief introduction of the fragment system is given in the last section of this tutorial.

The first line formally identifies the library environment required by our program; in other words, it gives the file path name of the BETA module where all the basic functions and procedures (such as putline) have been defined. In this respect, it acts much like the #include <stdio.h> statement seen at the beginning of most C programs.

The body of the program is a simple procedure call to do output. It is interesting to compare the syntax of BETA's procedure calls with that of other languages:

C++:       cout << &quot;Hello world !&quot;;
C:         printf(&quot;Hello world !\n&quot;);
BETA:      'Hello world !' -> putline;

In BETA, the syntax of procedure calls is made identical to that of simple assignments (or message passing). Evaluation is strictly left to right: parameters are evaluated; then passed (->) to an object putline whose role is to output them to the screen. Finally, note that text constants are delimited by apostrophes ('...').

The betaenv library and many of the other libraries used in this tutorial are documented in the Mjølner System manual [MIA 90-8].

Libraries Tutorial
© 1994-2002 Mjølner Informatics
[Modified: Friday January 4th 2002 at 13:10]