## 6.6.7 Hello world

 Page 85 of 800 Search internet

Logiweb is intended for distribution of definitions, lemmas, and proofs and for electronic publishing of high quality journal papers. Thus, writing a stand alone 'hello world' program may seem off-topic. Basically, however, the Logiweb package just provides yet another compiler for yet another programming language.

Even though the language is pure functional (or univocal), it is possible to write programs with arbitrarily complex interactive behavior. The lgc compiler is written in its own language, and Logiweb is prepared for even expressing functional operating systems in it.

To make a hello world program, proceed as follows. Write a file named helloworld.lgs containing this:

01   ""P helloworld
02   ""R base
03   ""D 0
04   hello
05   ""B
06   page ( ""N , ""C )
07   title "Hello world"
08   bib "".
09   main text "
10   \section{A hello world program}
11   We define the "[[ hello ]]" program thus:
12   "[[[ eager define hello as
13   map ( \ x . << writeln request ( "Hello World" ) >> )
14   end define ]]]"
15   We 'render' the "[[ hello ]]" program as
16   a file named 'hw' in the 'page/bin'
17   subdirectory of the rendering directory:
18   "[[[ execute define "hw" as << hello >> end define ]]]"
19   "
20   appendix "
21   \section{\TeX\ definitions}
22   \begin{statements}
23   \item "[[ tex show define hello as "
24   \mathbf{Hello}" end define ]]"
25   \end{statements}
26   "
27   end page


Then compile it:

   > lgc helloworld


Then try your hello world program:

   > helloworld/page/bin/hw


Line 18 above defines the hw program. More precisely, Line 18 defines the aspect of the string as .

A definition consists of an aspect, a left hand side, and a right hand side. Nothing prevents the left hand side to be a string as is done in the definition of 'hw'.

Definitions are unique in the sense that one can assign at most one right hand side to a given aspect of a given construct on a given page. Nothing prevents distinct pages to give distinct execute definitions of the same string, however. Thus, even though the page above defines the execute aspect of 'hw', another page may define a different execute aspect of 'hw' and thus generate a different program named hw.

The right hand side of an execute definition should be a list whose first element defines what the program does. Further arguments can be used for defining compiled in defaults. In the simplest form, compiled in defaults are given explicitly as string constants, but one can also do more advanced things.

The construct defines what the 'hw' program does. Lines 12-13 define as a maptagged lambda abstraction. When the 'hw' program is invoked, a structure similar to argc and argv in C is passed through the lambda variable. The structure contains the command line argument list argv, the environment env, a list of compiled in defaults, and the cache of the helloworld page.

In the 'hw' program we ignore the input event and just return a list of output events whose sole element is a writeln event.

We shall not go into further detail with such stand alone programs here. For further examples, consult Chapter 7 of the base page. There you will find:

• A 'hello world' program which writes Hello World like the program above.
• An 'echo' program which echos terminal input back as terminal output.
• An 'eecho' program which echos each input character twice.
• An 'lgciotest' program which defines and tests the interface used by the lgc compiler.

 Page 85 of 800 Search logiweb.eu