<?xml version="1.0"?>
<?xml-stylesheet type="text/xml" href="presenter.xsl"?>
<slideshow>
	<title>TI-89 BASIC Programming</title>

	<slide><title>TI-89 BASIC Programming</title><body>
		<p>By Karl Voelker</p>
	</body></slide>

	<slide><title>What is TI-89 BASIC?</title><body>
		<p>It's not really BASIC. That's just 
			what people call it.</p>
		<p>It's also not very similar to TI-83 
			or TI-86 BASIC.</p>
		<p>It is:</p>
		<ul>
		<li>Dynamically typed</li>
		<li>Strongly typed</li>
		<li>Procedural</li>
		</ul>
	</body></slide>

	<slide><title>Interactive Mode</title><body>
		<p>Many interpreters provide an "interactive mode" 
			where you enter individual lines of code and 
			see the result.</p>
		<p>On a TI-89, the "Home Screen" is the interactive mode 
		of the BASIC interpreter.</p>
	</body></slide>

	<slide><title>The I/O Screen</title><body>
		<p>Unlike the TI-83/86 home screen, the TI-89 home screen 
			is not the input/output console for programs.</p>
		<p>The TI-89 has a separate I/O Screen for this purpose.</p>
	</body></slide>

	<slide><title>Files</title><body>
		<p>Since the entire TI-89 environment is a BASIC interpreter, 
			files are just global variables.</p>
		<p>Global variables keep existing when you turn off the 
			calculator.</p>
	</body></slide>

	<slide><title>Folders</title><body>
		<p>TI-89 folders can also be used as namespaces for global 
			variables.</p>
		<p>TI-89 folders can not be nested.</p>
	</body></slide>

	<slide><title>Program Entry</title><body>
		<p>When you are entering a program, you can type function 
			names.</p>
		<p>Once you are a proficient typist, this will be faster than 
			finding functions in the menus.</p>
		<p>Function names are case-insensitive.</p>
		<p>Function name case is corrected when you run your program.
		</p>
	</body></slide>

	<slide><title>Typography</title><body>
		<p>The TI-89 font is strange. I will be using these 
			characters in place of actual TI-89 characters:</p>
		<table>
		<tr><td><tt>-></tt></td><td>Arrow</td></tr>
		<tr><td><tt>|></tt></td><td>Arrow-like triangle, used in names 
			of some conversion functions</td></tr>
		</table>
	</body></slide>

	<slide><title>The Colon</title><body>
		<p>The colon separates statements.</p>
		<p>In the Program Editor, each line implicitly begins 
			with a colon.</p>
	</body></slide>

	<slide><title>Data Types</title><body>
		<p>We will go into the details of each of these:</p>
		<ul>
		<li><tt>NUM</tt></li>
		<li><tt>STRING</tt></li>
		<li><tt>LIST</tt></li>
		<li><tt>MAT</tt></li>
		<li><tt>PRGM</tt></li>
		<li><tt>FUNC</tt></li>
		</ul>
	</body></slide>

	<slide><title><tt>NUM</tt></title><body>
		<p>This is the numeric type. It may hold:</p>
		<ul>
		<li>An integer</li>
		<li>An exact algebraic value</li>
		<li>An approximate decimal value</li>
		</ul>
	</body></slide>

	<slide><title><tt>STRING</tt></title><body>
		<p>A string is mostly what you'd expect.</p>
		<p>Strings are delimited by double quotes.</p>
	</body></slide>

	<slide><title><tt>LIST and MAT</tt></title><body>
		<ul>
		<li>List/matrix items must be scalar</li>
		<li>Lists and matrices can have a mix of scalar types</li>
		<li>Once created, a list/matrix is a fixed size</li>
		<li>Lists/matrix indices start at 1</li>
		</ul>
	</body></slide>

	<slide><title>Creating a list</title><body>
		<ul>
		<li><tt>{0, 0, 0}</tt></li>
		<li><tt>newList(3, 0)</tt></li>
		</ul>
	</body></slide>

	<slide><title>Creating a matrix</title><body>
		<ul>
		<li><tt>[[0, 0, 0][0, 0, 0]]</tt></li>
		<li><tt>[0, 0, 0; 0, 0, 0]</tt></li>
		<li><tt>newMat(3, 2, 0)</tt></li>
		</ul>
	</body></slide>

	<slide><title><tt>PRGM</tt></title><body>
		<p>A "program" can act as a program or subprogram.</p>
		<p>A program cannot return a value.</p>
		<p>A global program variable:</p>
		<pre>:foo(bar,baz)
:Prgm
:dostuff()
:EndPrgm</pre>
		<p>Note: use the Program Editor application to 
			create a new global program.</p>
	</body></slide>

	<slide><title>Variables</title><body>
		<p>Assign to a variable with <tt>-></tt>:</p>
		<pre>:4->x
:4+x->x</pre>
		<p>Variables are global by default!</p>
		<p>To declare a local variable:</p>
		<pre>:Local x
:4->x</pre>
	</body></slide>

	<slide><title>Local Subprograms</title><body>
		<p>You can create a subprogram in a local variable, but:</p>
		<ul>
		<li>Programs are secretly compiled when changed</li>
		<li>Compiled form of local program is lost when 
			it goes out of scope</li>
		<li>This is slow!</li>
		</ul>
		<p>A local program variable:</p>
		<pre>:Local foo
:Define foo(bar,baz)=Prgm
:dostuff()
:EndPrgm</pre>
	</body></slide>

	<slide><title><tt>FUNC</tt></title><body>
		<p>A function is like a program, but:</p>
		<ul>
		<li>It cannot modify non-local variables</li>
		<li>It must return a value</li>
		<li>It is delimited with <tt>Func</tt> and 
			<tt>EndFunc</tt></li>
		</ul>
		<p>To return a value:</p>
		<ul>
		<li>Explicitly, with <tt>Return x</tt></li>
		<li>Implicitly, as the value of the last executed 
			statement</li>
		</ul>
	</body></slide>

	<slide><title>The Conditional Statement</title><body>
		<p><em>TI-89 is not a part of the World Government conspiracy.
			</em></p>
		<p>An example:</p>
		<pre>:If x>5 Then
:5->x
:ElseIf x&lt;0 Then
:0->x
:Else
:2*x->x
:EndIf</pre>
	</body></slide>

	<slide><title>The Conditional Function</title><body>
		<p>The condition function is <tt>when</tt>:</p>
		<p><tt>:when(x>5,5,x)->x</tt></p>
	</body></slide>

	<slide><title>Loops</title><body>
		<p>The <tt>For</tt> loop:</p>
		<pre>:For i,begin,end,step
:dostuff()
:EndFor</pre>
		<p>The <tt>While</tt> loop:</p>
		<pre>:While more()
:dostuff()
:EndWhile</pre>
	</body></slide>

	<slide><title>More About Loops</title><body>
		<p>The infinite loop:</p>
		<pre>:Loop
:dostuff()
:EndLoop</pre>
		<p>Loop control:</p>
		<dl>
		<dt><tt>:Cycle</tt></dt>
		<dd>Skip to next iteration of loop</dd>
		<dt><tt>:Exit</tt></dt>
		<dd>Exit a loop</dd>
		</dl>
	</body></slide>

	<slide><title>Errors</title><body>
		<p>Trap errors with <tt>Try</tt>:</p>
		<pre>:Try
:foo/bar->x
:Else
:ClrErr
:0->x
:EndTry</pre>
	</body></slide>

	<slide><title>Errors, continued</title><body>
		<p>In the <tt>Else</tt> block, use one of these:</p>
		<dl>
		<dt><tt>ClrErr</tt></dt>
		<dd>The error was handled</dd>
		<dt><tt>PassErr</tt></dt>
		<dd>The error was not handled</dd>
		</dl>
		<p>The system variable <tt>errornum</tt> will contain an 
			error code.</p>
	</body></slide>

	<slide><title>Numeric operations</title><body>
		<p>There are many numeric operators and functions built-in.</p>
		<p>If you don't want exact algebraic values, 
			use <tt>approx</tt>.</p>
	</body></slide>

	<slide><title>Comparisons</title><body>
		<p>Individual characters exist for many comparisons:</p>
		<table>
		<tr><th>Comparison</th><th>Type</th></tr>
		<tr><td>Equal</td><td><tt>=</tt></td></tr>
		<tr><td>Not equal</td><td><tt>Diamond =</tt></td></tr>
		<tr><td>Less than</td><td><tt>2nd 0</tt></td></tr>
		<tr><td>Less than or equal</td><td><tt>Diamond 0</tt></td></tr>
		<tr><td>Greater than</td><td><tt>2nd .</tt></td></tr>
		<tr><td>Greater than or equal</td><td><tt>Diamond .</tt></td>
			</tr>
		</table>
		<p>These work on strings!</p>
	</body></slide>

	<slide><title>Logical Operators</title><body>
		<p>The logical operators are words (but still infix).</p>
		<p>They are:</p>
		<ul>
		<li><tt>and</tt></li>
		<li><tt>or</tt></li>
		<li><tt>xor</tt></li>
		<li><tt>not</tt> (also <tt>~</tt>) (prefix)</li>
		</ul>
	</body></slide>

	<slide><title>String Operations</title><body>
		<p>Concatenate strings with <tt>&amp;</tt>.</p>
		<p>Useful string functions:</p>
		<dl>
		<dt><tt>left("foobar", 3)</tt></dt>
		<dd>Substring from left</dd>
		<dt><tt>mid("foobar", 2, 2)</tt></dt>
		<dd>Substring from anywhere</dd>
		<dt><tt>right("foobar", 3)</tt></dt>
		<dd>Substring from right</dd>
		</dl>
	</body></slide>

	<slide><title>More String Operations</title><body>
		<dl>
		<dt><tt>dim("foo")</tt></dt>
		<dd>Length</dd>
		<dt><tt>inString("foobar", "oo")</tt></dt>
		<dd>Search for substring</dd>
		<dt><tt>expr("3+4")</tt></dt>
		<dd>Evaluate BASIC expression in a string</dd>
		<dt><tt>string(3)</tt></dt>
		<dd>String representation of a value</dd>
		</dl>
	</body></slide>

	<slide><title>List and Matrix Indices</title><body>
		<p>To access an item:</p>
		<ul>
		<li><tt>mylist[3]</tt></li>
		<li><tt>mymat[3,4]</tt></li>
		</ul>
		<p>Give only the first index for a matrix 	
			to get that row.</p>
	</body></slide>

	<slide><title>List and Matrix Functions</title><body>
		<dl>
		<dt><tt>augment</tt></dt>
		<dd>Concatenate lists or matrices</dd>
		<dt><tt>subMat</tt></dt>
		<dd>Extract any rectangular submatrix</dd>
		<dt><tt>dim, left, mid, right</tt></dt>
		<dd>Work on list items just like they do on 
			string characters</dd>
		<dt><tt>list|>mat</tt></dt>
		<dd>Convert a list to a matrix</dd>
		<dt><tt>mat|>list</tt></dt>
		<dd>Convert a matrix to a list</dd>
		</dl>
	</body></slide>

	<slide><title>Output Statements</title><body>
		<dl>
		<dt><tt>:Disp "foo"</tt></dt>
		<dd>Display a string, with trailing newline</dd>
		<dt><tt>:Output 0,0,"foo"</tt></dt>
		<dd>Display a string at a pixel location</dd>
		<dt><tt>:ClrIO</tt></dt>
		<dd>Clear the I/O screen</dd>
		</dl>
	</body></slide>

	<slide><title>Input Statements</title><body>
		<dl>
		<dt><tt>:Pause "message"</tt></dt>
		<dd>Wait for a keypress</dd>
		<dt><tt>:Input "message",x</tt></dt>
		<dd>Input an expression</dd>
		<dt><tt>:InputStr "message",x</tt></dt>
		<dd>Input a string</dd>
		</dl>
	</body></slide>

	<slide><title>Indirection</title><body>
		<p>The <tt>#</tt> operator (prefix) takes a string and 
			accesses the variable named by the string's contents.
		</p>
		<p>This gives you power similar to references or pointers.</p>
	</body></slide>

	<slide><title>Further Topics</title><body>
		<p>Someday, this presentation might cover these topics:</p>
		<ul>
		<li>Dialog boxes</li>
		<li>Menus</li>
		<li>Link communication</li>
		</ul>
		<p>For now, at least you know that they are possible in 
			TI-89 BASIC.</p>
	</body></slide>

	<slide><title>The End</title><body>
		<p>Questions?</p>
	</body></slide>

</slideshow>
