Hello World (Oz)
From LiteratePrograms
- Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL
The Oz programming language includes both an interactive development environment, and a compiler. In this article we'll examine how to produce the classic Hello World using both tools.
Contents |
Hello world in the interactive environment
In the interactive environment, the classic Hello World can be accomplished by simply typing
<<interactive>>= {Show 'Hello World'}
into the Oz buffer, and then selecting the menu option that feeds this line to the compiler. The atom 'Hello World!'
will then appear in the Oz emulator window.
Another alternative is to type
<<interactive>>= {Browse 'Hello World'}
into the Oz buffer. This produces a similar result as the Show
example, except that the output is written to the GUI Oz browser window.
Hello world executable
While the interactive environment is great for exploring ideas, ultimately it would be nice to produce an executable. Here we define a simple hello world program which first prints "Hello World!" to the screen, and then prints the numbers 1 to 10 in sequence.
Implementation
Program modules in Oz are referred to as functors. The hello world functor consists of a set of import statements, followed by the body of the program.
<<helloworld.oz>>= functor import imports define body end
The hello world functor requires two standard Oz modules: Application
, to provide executable application termination, and System
, to provide terminal output.
<<imports>>= Application System
The body of the functor uses the System.showInfo
procedure to print an argument to the screen, followed by a newline. The for-loop applies System.showInfo
to a numbers 1 through 10 in sequence.
<<body>>= {System.showInfo 'Hello World!'} for X in 1..10 do {System.showInfo X} end {Application.exit 0}
Compilation and execution
The helloworld.oz
program can be compiled using the ozc
compiler provided as part of the system. To compile to an executable, the compiler should be invoked using the -x
option:
ozc -x helloworld.oz
The resulting helloworld
executable can be run from the command line.
Download code |