"Hello World" and "99 bottles of beer"

Hello world

To maintain the text output "Hello world" the following line is all it takes:

"Hello world" Attention 

Compare to other programming languages:  http://www.lob.de/pdf/helloworld.pdf or http://www.roesler-ac.de/wolfram/hello.htm

"Hello world" - multilingual version

InstantView® makes it just as easy to generate the according multilingual version. For this, neither language kind nor number of languages are defined or limited.

For "Hello world", a Multilingual Text simply needs to be put in the stack.

T("Hallo Welt", "Hello world", "Hola mundo") Attention 

The user-specific language setting will now determine the correct text output. The setting can be changed any time during runtime.



"99 bottles of beer" - multilingual version


To display the entire song for instance in German, too, the programming becomes be a bit more complex. The actual problem though, will be the differentiation of singular and plural.
 

"99 bottles of beer" as service

A few simple upgrades makes it possible to encapsulate code in a separate module. The messages

"SING_BOTTLES_OF_BEER_IN_ENGLISH" calls the English version, "SING_BOTTLES_OF_BEER_ML" calls the multilingual version and "SING_BOTTLES_OF_BEER_WITH_UNITS" calls the version with units from everywhere.

Therefore, the English version can be called with:
100 SendMsg(SING_BOTTLES_OF_BEER_IN_ENGLISH) 


"99 bottles of beer"

This famous American nursery rhyme is often used to compare different programming languages.

A Simple InstantView® Script could look as follows:
 
// Define macro
    Define(SingBottlesOfBeerSimple)
       Var(i)
       99 -> i
       ""
       do
         i "%s bottle(s) of beer on the wall, " String(STACK) + i "%s bottle(s) of beer.\n" String(STACK) +
         "Take one down and pass it around, " +
         Decr(i)
         i if {
           i "%s bottle(s)" String(STACK) +
         }
         else {
           "no more bottles" +
         }
         " of beer on the wall.\n\n" +
 
         i ifnot break
       loop

       "No more bottles of beer on the wall, no more bottles of beer.\n" +
       "Go to the store and buy some more, 99 bottles of beer on the wall." +
    ;

// Call macro
   SingBottlesOfBeerSimple Attention

The equivalent implementation in other programming languages is shown here: http://www.99-bottles-of-beer.net. Unlike our version above, many examples shown on this page don't differentiate between plural "bottles" and singular "bottle", making programming easier.
 


"99 bottles of beer" with units

InstantView® allows for any user-defined unit. In our case, we are dealing with "bottles"!

Therefore, the number of beer bottles gets displayed with a Value Object of the unit "bottles/bottle", which automatically results in a differentiation of singular and plural.