Hello World

From vishap oberon compiler
Jump to navigation Jump to search

Deutsch (de) | English (en) | հայերեն (hy)

by using module Console[edit]

Create a new file named hello.Mod:

MODULE hello;

  IMPORT Console;

  BEGIN

    Console.String ("Hello World!");
    Console.Ln

  END hello.

Which means

MODULE hello — The module's name is hello.

IMPORT Console — Import the module Console.

BEGIN — Here we start our code!

Console.String ("Hello World!"); — Module Console, Procedure String (which is going to show a sting on our console) Hello World!
Console.Ln; — Print a line on the Console.

END hello. — End of the module hello, and let's not forget the dot. (:

Now let's compile it!

voc -m hello.Mod

and now let's run it!

$ ./hello
Hello World!

$

by using Texts and Oberon.Log[edit]

this is a more traditional way in a spirit of Oberon system.

MODULE Hello;
 IMPORT Oberon, Texts;
   VAR W: Texts.Writer;
 PROCEDURE World*;
   BEGIN
     Texts.WriteString(W, "Hello World!");
     Texts.WriteLn(W);
     Texts.Append(Oberon.Log, W.buf);
     Oberon.DumpLog;
  END World;

 BEGIN
   Texts.OpenWriter(W);
   World
 END Hello.

There are two small differences with Oberon system version:

  • in Oberon system you can call from the shell Hello.World function, while in Linŭ there is only one program entrance point (main), and in the main module it's a section which starts with BEGIN keyword. Thus you need to call World procedure from that part.
  • We have a function Oberon.DumpLog, in order to dump Oberon.Log to console.

This may be considered a more portable way, because not all systems have console (windows?), and Oberon.Log can be dumped to the different space.

by ulmWrite module[edit]

... to be written