Hello World

From vishap oberon compiler
Revision as of 16:26, 24 February 2016 by Noch (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

by using module Console

Create a new file named hello.Mod:

MODULE hello;

  IMPORT Console;


    Console.String ("Hello World!");

  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

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

 IMPORT Oberon, Texts;
   VAR W: Texts.Writer;
     Texts.WriteString(W, "Hello World!");
     Texts.Append(Oberon.Log, W.buf);
  END 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

... to be written