Getting Started

This chapter explains how to download and install Stanza for your system, compile the example programs, and also write your own very first Stanza program.

Get Stanza

Download Stanza

Navigate to www.lbstanza.org, go to the Downloads section of the webpage, and download the zip file containing the Stanza compiler for your platform. Unzip the file contents to a folder called mystanza. This is the directory where Stanza will be installed.

The main Stanza compiler should be located at

mystanza/stanza

and the core and collections libraries should be located at

mystanza/core/core.stanza
mystanza/core/collections.stanza

Installing on Linux and OS-X

If you're on a linux platform, open the terminal and type

cd mystanza
./stanza install -platform linux

If you're on Mac OS-X, then type instead

cd mystanza
./stanza install -platform os-x

This creates a .stanza file in your home directory that contains the installation directory for Stanza.

Put Stanza in your Path

Type the following if you want to be able to call Stanza from any working directory.

sudo ln stanza /usr/local/bin/stanza

Installing on Windows

Open cmd.exe and type

cd mystanza
stanza install -platform windows -path .

This creates a .stanza file in the mystanza directory. Stanza will print out a message telling you to set the STANZA_CONFIG environment variable to the installation directory. Additionally, add the mystanza directory to the PATH environment variable to be able to run stanza from any directory.

Running Stanza on windows additionally requires the MinGW-w64 port of the gcc compiler. Download the mingw-w64-install.exe installer from https://sourceforge.net/projects/mingw-w64/ and run it. By default, it is installed in C:\Program Files\mingw-w64. Add the MinGW-w64 bin directory to the PATH environment variable.

At the time of writing, the bin directory corresponding to our MinGW-w64 installation was located at

C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin

Test

Type the following in the terminal

stanza version

It should print out the version of the Stanza compiler that you downloaded. If you don't see this, then double check that

  1. you downloaded Stanza for the right platform.
  2. you installed Stanza with the correct -platform flag.
  3. you put Stanza on your path.

Compile an Example

Type the following in the terminal

cd mystanza
stanza examples/helloworld.stanza -o helloworld

This should compile the helloworld example that comes with Stanza and generate an executable called helloworld. If this does not work, then double check that

  1. you are in the mystanza folder.
  2. you installed Stanza with the correct -platform flag.
  3. you have the Gnu C compiler installed and can call it by typing cc (or gcc for Windows) in the terminal.

Run the Example

Type the following to run the compiled executable. It should print out "hello world".

./helloworld

If you're running Windows, then type either

helloworld

or

helloworld.exe

Congratulations! You've successfully installed Stanza! Now try compiling and running the other examples in the examples directory.

Write a Program

Basic Skeleton

Create a folder called stanzaprojects and create a file called hello.stanza containing

defpackage mypackage :
   import core
  
defn main () :
   println("Timon")
   println("and")
   println("Pumbaa")

main()

Make sure you don't forget the space between the main and the ()! We will explain later why this is important. Compile and run it by typing

stanza hello.stanza -o hello
./hello

It should print out

Timon
and
Pumbaa

More println Statements

Surround the call to main with the following print statements

println("Simba")
main()
println("and Nala")

Run the program again and it should print out

Simba
Timon
and
Pumbaa
and Nala

The program runs in the order that it sees the top-level statements.

Delete the Call to main

Delete the call to main entirely.

println("Simba")
println("and Nala")

Now the program prints out

Simba
and Nala

If you don't call main then it never runs.

Rename main

Rename the main function to hakuna.

defpackage mypackage :
   import core
  
defn hakuna () :
   println("Timon")
   println("and")
   println("Pumbaa")

hakuna()

The program still prints out

Timon
and
Pumbaa

There is nothing special about the main function. Name it whatever you like.