-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter1.html
More file actions
37 lines (36 loc) · 7.54 KB
/
chapter1.html
File metadata and controls
37 lines (36 loc) · 7.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html>
<head>
<title>L.B.Stanza</title>
<link type="text/css" rel="stylesheet" href="resources/mainstyle.css">
<link type="text/css" rel="stylesheet" href="resources/documentation.css">
</head>
<body>
<table class="wrap">
<tr><td colspan="3" class="banner">
<a href="index.html">Home</a><a href="stanzabyexample.html">Table of Contents</a><a href="chapter2.html">Next Chapter</a>
</td></tr>
<tr>
<td class="nav">
<h1>NAVIGATION</h1>
<h2><a href="#anchor120">Getting Started</a></h2><h3><a href="#anchor0">Get Stanza</a></h3><h4><a href="#anchor121">Download Stanza</a></h4><h4><a href="#anchor122">Installing on Linux and OS-X</a></h4><h4><a href="#anchor123">Put Stanza in your Path</a></h4><h4><a href="#anchor124">Installing on Windows</a></h4><h4><a href="#anchor125">Test</a></h4><h4><a href="#anchor126">Compile an Example</a></h4><h4><a href="#anchor127">Run the Example</a></h4><h3><a href="#anchor1">Write a Program</a></h3><h4><a href="#anchor128">Basic Skeleton</a></h4><h4><a href="#anchor129">More println Statements</a></h4><h4><a href="#anchor130">Delete the Call to main</a></h4><h4><a href="#anchor131">Rename main</a></h4>
</td>
<td class="main">
<h1 id="anchor120">Getting Started</h1><p>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.</p><h2 id="anchor0">Get Stanza</h2><p></p><h3 id="anchor121">Download Stanza</h3><p>Navigate to <code>www.lbstanza.org</code>, 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 <code>mystanza</code>. This is the directory where Stanza will be installed.</p><p>The main Stanza compiler should be located at</p><pre><code>mystanza/stanza</code></pre><p>and the core and collections libraries should be located at</p><pre><code>mystanza/core/core.stanza<br>mystanza/core/collections.stanza</code></pre><h3 id="anchor122">Installing on Linux and OS-X</h3><p>If you're on a linux platform, open the terminal and type</p><pre><code>cd mystanza<br>./stanza install -platform linux</code></pre><p>If you're on Mac OS-X, then type instead</p><pre><code>cd mystanza<br>./stanza install -platform os-x</code></pre><p>This creates a <code>.stanza</code> file in your home directory that contains the installation directory for Stanza.</p><h3 id="anchor123">Put Stanza in your Path</h3><p>Type the following if you want to be able to call Stanza from any working directory.</p><pre><code>sudo ln stanza /usr/local/bin/stanza</code></pre><h3 id="anchor124">Installing on Windows</h3><p>Open <code>cmd.exe</code> and type</p><pre><code>cd mystanza<br>stanza install -platform windows -path .</code></pre><p>This creates a <code>.stanza</code> file in the <code>mystanza</code> directory. Stanza will print out a message telling you to set the <code>STANZA_CONFIG</code> environment variable to the installation directory. Additionally, add the <code>mystanza</code> directory to the <code>PATH</code> environment variable to be able to run stanza from any directory.</p><p>Running Stanza on windows additionally requires the MinGW-w64 port of the gcc compiler. Download the <code>mingw-w64-install.exe</code> installer from <a href=https://sourceforge.net/projects/mingw-w64/>https://sourceforge.net/projects/mingw-w64/</a> and run it. By default, it is installed in <code>C:\Program Files\mingw-w64</code>. Add the MinGW-w64 <code>bin</code> directory to the <code>PATH</code> environment variable.</p><p>At the time of writing, the <code>bin</code> directory corresponding to our MinGW-w64 installation was located at</p><pre><code>C:\Program Files\mingw-w64\x86_64-5.3.0-posix-seh-rt_v4-rev0\mingw64\bin</code></pre><h3 id="anchor125">Test</h3><p>Type the following in the terminal</p><pre><code>stanza version</code></pre><p>It should print out the version of the Stanza compiler that you downloaded. If you don't see this, then double check that</p><ol><li>you downloaded Stanza for the right platform.
</li><li>you installed Stanza with the correct <code>-platform</code> flag.
</li><li>you put Stanza on your path.
</li></ol><h3 id="anchor126">Compile an Example</h3><p>Type the following in the terminal</p><pre><code>cd mystanza<br>stanza examples/helloworld.stanza -o helloworld</code></pre><p>This should compile the <code>helloworld</code> example that comes with Stanza and generate an executable called <code>helloworld</code>. If this does not work, then double check that</p><ol><li>you are in the <code>mystanza</code> folder.
</li><li>you installed Stanza with the correct <code>-platform</code> flag.
</li><li>you have the Gnu C compiler installed and can call it by typing <code>cc</code> (or <code>gcc</code> for Windows) in the terminal.
</li></ol><h3 id="anchor127">Run the Example</h3><p>Type the following to run the compiled executable. It should print out "hello world".</p><pre><code>./helloworld</code></pre><p>If you're running Windows, then type either</p><pre><code>helloworld</code></pre><p>or</p><pre><code>helloworld.exe</code></pre><p>Congratulations! You've successfully installed Stanza! Now try compiling and running the other examples in the <code>examples</code> directory.</p><h2 id="anchor1">Write a Program</h2><p></p><h3 id="anchor128">Basic Skeleton</h3><p>Create a folder called <code>stanzaprojects</code> and create a file called <code>hello.stanza</code> containing</p><pre><code>defpackage mypackage :<br> import core<br> <br>defn main () :<br> println("Timon")<br> println("and")<br> println("Pumbaa")<br><br>main()</code></pre><p>Make sure you don't forget the space between the <code>main</code> and the <code>()</code>! We will explain later why this is important. Compile and run it by typing</p><pre><code>stanza hello.stanza -o hello<br>./hello</code></pre><p>It should print out</p><pre><code>Timon<br>and<br>Pumbaa</code></pre><h3 id="anchor129">More println Statements</h3><p>Surround the call to <code>main</code> with the following print statements</p><pre><code>println("Simba")<br>main()<br>println("and Nala")</code></pre><p>Run the program again and it should print out</p><pre><code>Simba<br>Timon<br>and<br>Pumbaa<br>and Nala</code></pre><p>The program runs in the order that it sees the top-level statements.</p><h3 id="anchor130">Delete the Call to main</h3><p>Delete the call to <code>main</code> entirely.</p><pre><code>println("Simba")<br>println("and Nala")</code></pre><p>Now the program prints out</p><pre><code>Simba<br>and Nala</code></pre><p>If you don't call <code>main</code> then it never runs.</p><h3 id="anchor131">Rename main</h3><p>Rename the <code>main</code> function to <code>hakuna</code>. </p><pre><code>defpackage mypackage :<br> import core<br> <br>defn hakuna () :<br> println("Timon")<br> println("and")<br> println("Pumbaa")<br><br>hakuna()</code></pre><p>The program still prints out</p><pre><code>Timon<br>and<br>Pumbaa</code></pre><p>There is nothing special about the <code>main</code> function. Name it whatever you like.</p>
</td>
<td class="rest">
<img url="resources/spacer.gif"></img>
</td>
</tr>
<tr><td colspan="3" class="footer">
Site design by Luca Li. Copyright 2015.
</td></tr>
</table>
</body>
</html>