Yab2Cpp/Documentation/yabasic.html
2015-04-13 13:40:27 -07:00

2665 lines
369 KiB
HTML

<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"><title>Yabasic</title><meta name="generator" content="DocBook XSL Stylesheets V1.45"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book"><div class="titlepage"><div><h1 class="title"><a name="id2787149"></a>Yabasic</h1></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt>1. <a href="#chapter_intoduction">Introduction</a></dt><dd><dl><dt><a href="#id2787120">About this document</a></dt><dt><a href="#id2774095">About yabasic</a></dt></dl></dd><dt>2. <a href="#chapter_program_windows">The yabasic-program under Windows</a></dt><dd><dl><dt><a href="#id2726116">Starting yabasic</a></dt><dt><a href="#id2726405">Options</a></dt><dt><a href="#id2726920">The context Menu</a></dt></dl></dd><dt>3. <a href="#chapter_program_unix">The yabasic-program under Unix</a></dt><dd><dl><dt><a href="#id2727075">Starting yabasic</a></dt><dt><a href="#id2724578">Options</a></dt><dt><a href="#id2725188">Setting defaults</a></dt></dl></dd><dt>4. <a href="#chapter_topics">Some features of yabasic, explained by topic</a></dt><dd><dl><dt><a href="#id2725301"><tt>print</tt>, <tt>input</tt> and others</a></dt><dt><a href="#id2725430">Control statements: loops, <tt>if</tt> and <tt>switch</tt></a></dt><dt><a href="#id2787458">Drawing and painting</a></dt><dt><a href="#id2787636">Reading from and writing to files</a></dt><dt><a href="#id2787742">Subroutines and Libraries</a></dt><dt><a href="#id2787834">String processing</a></dt><dt><a href="#id2787987">Arithmetic</a></dt><dt><a href="#id2788126">Data and such</a></dt><dt><a href="#id2788182">Other interesting commands.</a></dt></dl></dd><dt>5. <a href="#chapter_topics_list">All commands and functions of yabasic listed by topic</a></dt><dd><dl><dt><a href="#top_numbers">Number processing and conversion</a></dt><dt><a href="#top_conditions">Conditions and control structures</a></dt><dt><a href="#top_data">Data keeping and processing</a></dt><dt><a href="#top_strings">String processing</a></dt><dt><a href="#top_io">File operations and printing</a></dt><dt><a href="#top_sub">Subroutines and libraries</a></dt><dt><a href="#top_other">Other commands</a></dt><dt><a href="#top_graphics">Graphics and printing</a></dt></dl></dd><dt>6. <a href="#chapter_ref_words">All commands and functions of yabasic grouped alphabetically</a></dt><dd><dl><dt><a href="#ref_a">A</a></dt><dt><a href="#ref_b">B</a></dt><dt><a href="#ref_c">C</a></dt><dt><a href="#ref_d">D</a></dt><dt><a href="#ref_e">E</a></dt><dt><a href="#ref_f">F</a></dt><dt><a href="#ref_g">G</a></dt><dt><a href="#ref_h">H</a></dt><dt><a href="#ref_i">I</a></dt><dt><a href="#ref_l">L</a></dt><dt><a href="#ref_m">M</a></dt><dt><a href="#ref_n">N</a></dt><dt><a href="#ref_o">O</a></dt><dt><a href="#ref_p">P</a></dt><dt><a href="#ref_r">R</a></dt><dt><a href="#ref_s">S</a></dt><dt><a href="#ref_t">T</a></dt><dt><a href="#ref_u">U</a></dt><dt><a href="#ref_v">V</a></dt><dt><a href="#ref_w">W</a></dt><dt><a href="#ref_x">X</a></dt><dt><a href="#ref_special_characters">Special characters</a></dt></dl></dd><dt>7. <a href="#chapter_ref_concepts">A grab-bag of some general concepts and terms</a></dt><dd><dl><dt><a href="#ref_logical_shortcuts">Logical shortcuts</a></dt><dt><a href="#ref_conditions_and_expressions">Conditions and expressions</a></dt><dt><a href="#ref_array_references">References on arrays</a></dt><dt><a href="#ref_windows_filenames">Specifying Filenames under Windows</a></dt><dt><a href="#ref_escape_sequences">Escape-sequences</a></dt><dt><a href="#ref_standalone">Creating a <span class="emphasis"><i>standalone</i></span> program from your yabasic-program</a></dt></dl></dd><dt>8. <a href="#chapter_examples">A few example programs</a></dt><dd><dl><dt><a href="#id2827243">A very simple program</a></dt><dt><a href="#id2827270">A part of the demo of yabasic</a></dt></dl></dd><dt>9. <a href="#chapter_copyright">The Copyright of yabasic</a></dt></dl></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_intoduction"></a>Chapter 1. Introduction</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2787120">About this document</a></dt><dt><a href="#id2774095">About yabasic</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787120"></a>About this document</h2></div></div><p>
This document describes yabasic.
You will find information about the yabasic
interpreter (the program <b>yabasic</b> under Unix or
<b>yabasic.exe</b> under Windows)
as well as the language itself.<p>
</p>
This document applies to version 2.750 of yabasic</p><p>
However, this document does not contain the latest news about yabasic or a FAQ.
As such information tends to change rapidly, it is presented online only
at <a href="http://www.yabasic.de" target="_top">www.yabasic.de</a>.</p><p>
Although basic has its reputation as a language for beginning programmers,
this is not an introduction to programming at large. Rather this text assumes, that
the reader has some (moderate) experience with writing and starting computer programs.</p><p>
</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2774095"></a>About yabasic</h2></div></div><p>yabasic is a traditional basic interpreter. It understands most of the typical basic-constructs, like <tt>goto</tt>, <tt>gosub</tt>, line numbers, <tt>read</tt>, <tt>data</tt> or string-variables with a trailing '<tt>$</tt>'. But on the other hand, yabasic implements some more advanced programming-constructs like subroutines or libraries (but <span class="emphasis"><i>not</i></span> objects). yabasic works much the same under Unix and Windows.</p><p>yabasic puts emphasis on giving results quickly and easily; therefore simple commands are provided to open a graphic window, print the graphics or control the console screen and get keyboard or mouse information. The example below opens a window, draws a circle and prints the graphic:</p><pre class="programlisting">
open window 100,100
open printer
circle 50,50,40
text 10,50,&quot;Press any key to get a printout&quot;
clear screen
inkey$
close printer
close window
</pre><p>This example has fewer lines, than it would have in many other programming languages. In the end however yabasic lacks behind more advanced and modern programming languages like C++ or Java. But as far as it goes it tends to give you results more quickly and easily.</p></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_program_windows"></a>Chapter 2. The yabasic-program under Windows</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2726116">Starting yabasic</a></dt><dt><a href="#id2726405">Options</a></dt><dt><a href="#id2726920">The context Menu</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2726116"></a><a name="windows_starting"></a>Starting yabasic</h2></div></div><p>Once, yabasic has been set up correctly, there are three ways to start it:</p><div class="orderedlist"><ol type="1"><li><p><span class="emphasis"><i>Rightclick on your desktop:</i></span> The desktop menu appears with a submenu named <span class="emphasis"><i>new</i></span>. From this submenu choose yabasic. This will create a new icon on your desktop. If you rightclick on this icon, its <a href="#windows_context_menu">context menu</a> will appear; choose Execute to execute the program.</p></li><li><p>As a variant of the way described above, you may simply <span class="emphasis"><i>create a file with the ending <tt>.yab</tt></i></span> (e.g. with your favorite editor). Everything else then works as described above.</p></li><li><p><span class="emphasis"><i>From the start-menu:</i></span> Choose yabasic from your start-menu. A console-window will open and you will be asked to type in your program. Once you are finished, you need to type <tt>return</tt> twice, and yabasic will parse and execute your program.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is <span class="emphasis"><i>not</i></span> the preferred way of starting yabasic ! Simply because the program, that you have typed, <span class="emphasis"><i>can not be saved</i></span> and will be lost inevitably ! There is no such thing as a <tt>save</tt>-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs.</p></div></li></ol></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2726405"></a><a name="windows_options"></a>Options</h2></div></div><p>Under Windows yabasic will mostly be invoked by double-clicking on an appropriate icon; this way you do not have a chance to specify any of the commandline options below. However, advanced users may add some of those options to the appropriate entries in the registry.</p><p>All the options below may be abbreviated, as long as the abbreviation does not become ambigous. For example, you may write <tt>-e</tt> instead of <tt>-execute</tt>.</p><div class="variablelist"><dl><dt><span class="term"><tt>-help</tt> or <tt>-?</tt></span></dt><dd><p>Prints a short help message, which itself describes two further help-options.</p></dd><dt><span class="term"><tt>-version</tt></span></dt><dd><p>Prints the version of yabasic.</p></dd><dt><span class="term"><tt>-geometry +<i><tt>X-POSITION</tt></i>+<i><tt>Y-POSITION</tt></i></tt></span></dt><dd><p>Sets the position of the graphic window, that is opened by <tt>open window</tt> (the <span class="emphasis"><i>size</i></span> of this window, of course, is specified within the <tt>open window</tt>-command). An example would be <tt>-geometry +20+10</tt>, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. This value cannot be changed, once yabasic has been started.</p></dd><dt><span class="term"><tt>-font <i><tt>NAME-OF-FONT</tt></i></tt></span></dt><dd><p>Name of the font, which will be used for graphic-text; can be any of <tt>decorative, dontcare, modern, roman, script, swiss</tt>. You may append a fontsize (measured in pixels) to any of those fontnames; for example <tt>-font swiss30</tt> chooses a swiss-type font with a size of 30 pixels.</p></dd><dt><span class="term"><tt>-bind <i><tt>NAME-OF-STANDALONE-PROGRAM</tt></i></tt></span></dt><dd><p>Create a standalone program (whose name is specified by <i><tt>NAME-OF-STANDALONE-PROGRAM</tt></i>) from the yabasic-program, that is specified on the commandline. See the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><i>standalone</i></span>-program</a> for details.</p></dd><dt><span class="term"><tt>-execute <i><tt>A-PROGRAM-AS-A-SINGLE-STRING</tt></i></tt></span></dt><dd><p>With this option you may specify some yabasic-code to be executed rigth away.This is useful for very short programs, which you do not want to save within a file. If this option is given, yabasic will not read any code from a file. Let's say, you have forgotten some of the square numbers between 1 and 10; in this case the command <tt>yabasic -e 'for a=1 to 10:print a*a:next a'</tt> will give you the answer immediately.</p></dd><dt><span class="term"><tt>-infolevel <i><tt>INFOLEVEL</tt></i></tt></span></dt><dd><p>Change the <span class="emphasis"><i>infolevel</i></span> of yabasic, where <i><tt>INFOLEVEL</tt></i> can be one of <tt>debug</tt>, <tt>note</tt>, <tt>warning</tt>, <tt>error</tt> and <tt>fatal</tt> (the default is <tt>warning</tt>). This option changes the amount of debugging-information yabasic produces. However, normally only the author of yabasic (<span class="emphasis"><i>me</i></span> !) would want to change this.</p></dd><dt><span class="term"><tt>-doc <i><tt>NAME-OF-A-PROGRAM</tt></i></tt></span></dt><dd><p>Print the <span class="emphasis"><i>embedded documentation</i></span> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <tt><a href="#ref_doc" title="doc">doc</a></tt>. This documentation can also be seen by choosing the corresponding entry from the context-menu of any yabasic-program.</p></dd><dt><span class="term"><tt>-librarypath <i><tt>DIRECTORY-WITH-LIBRARIES</tt></i></tt></span></dt><dd><p>Change the directory, wherein libraries will be searched and imported (with the <tt><a href="#ref_import" title="import">import</a></tt>-command). See also <tt><a href="#ref_import" title="import">this entry</a></tt> for more information about the way, libraries are searched.</p></dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2726920"></a><a name="windows_context_menu"></a>The context Menu</h2></div></div><p>Like every other icon under Windows, the icon of every yabasic-program has a <span class="emphasis"><i>context menu</i></span> offering the most frequent operations, that may be applied to a yabasic-program.</p><div class="variablelist"><dl><dt><span class="term">Execute</span></dt><dd><p>This will invoke yabasic to execute your program. The same happens, if you <span class="emphasis"><i>doubleclick</i></span> on the icon.</p></dd><dt><span class="term">Edit</span></dt><dd><p>notepad will be invoked, allowing you to edit your program.</p></dd><dt><span class="term">View docu</span></dt><dd><p>This will present the embedded documentation of your program. Embedded documentation is created with the special comment <tt><a href="#ref_doc" title="doc">doc</a></tt>.</p></dd></dl></div></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_program_unix"></a>Chapter 3. The yabasic-program under Unix</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2727075">Starting yabasic</a></dt><dt><a href="#id2724578">Options</a></dt><dt><a href="#id2725188">Setting defaults</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2727075"></a><a name="unix_starting"></a>Starting yabasic</h2></div></div><p>If your system administrator (vulgo <span class="emphasis"><i>root</i></span>) has installed yabasic correctly, there are three ways to start it:</p><div class="orderedlist"><ol type="1"><li><p>You may use your favorite editor (emacs, vi ?) to put your program into a file (e.g. <tt>foo</tt>). Make sure that the very first line starts with the characters '<tt>#!</tt>' followed by the full pathname of yabasic (e.g. '<tt>#!/usr/local/bin/yabasic</tt>'). This <span class="emphasis"><i>she-bang</i></span>-line ensures, that your Unix will invoke yabasic to execute your program (see also the entry for the <a href="#ref_hash" title="#">hash</a>-character). Moreover, you will need to change the permissions of your yabasic-program <tt>foo</tt>, e.g. <tt>chmod u+x foo</tt>. After that you may invoke yabasic to invoke your program by simply typing <tt>foo</tt> (without even mentioning yabasic). However, if your <tt>PATH</tt>-variable does not contain a single dot ('<tt>.</tt>') you will have to type the full pathname of your program: e.g. <tt>/home/ihm/foo</tt> (or at least <tt>./foo</tt>).</p></li><li><p>Save your program into a file (e.g. <tt>foo</tt>) and type <tt>yabasic foo</tt>. This assumes, that the directory, where yabasic resides, is contained within your <tt>PATH</tt>-variable.</p></li><li><p>Finally your may simply type <b><tt>yabasic</tt></b> (maybe it will be necessary to include its full pathname). This will make yabasic come up and you will be asked to type in your program. Once you are finished, you need to type <tt>return</tt> twice, and yabasic will parse and execute your program.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is <span class="emphasis"><i>not</i></span> the preferred way of starting yabasic ! Simply because the program, that you have typed, <span class="emphasis"><i>can not be saved</i></span> and will be lost inevitably ! There is no such thing as a <tt>save</tt>-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs, i.e. for using yabasic as some sort of fancy desktop calculator.</p></div></li></ol></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2724578"></a><a name="unix_options"></a>Options</h2></div></div><p>yabasic accepts a number of options on the commandline. All these options below may be abbreviated, as long as the abbreviation does not become ambigous. For example you may write <tt>-e</tt> instead of <tt>-execute</tt>.</p><div class="variablelist"><dl><dt><span class="term"><tt>-help</tt> or <tt>-?</tt></span></dt><dd><p>Prints a short help message, which itself describes two further help-options.</p></dd><dt><span class="term"><tt>-version</tt></span></dt><dd><p>Prints the version of yabasic.</p></dd><dt><span class="term"><tt>-fg <i><tt>FOREGROUND-COLOR</tt></i></tt> or <tt>-foreground <i><tt>FOREGROUND-COLOR</tt></i></tt></span></dt><dd><p>Define the foreground color for the graphics-window (that will be opened with <tt><a href="#ref_open_window" title="open window">open window</a></tt>). The usual X11 colornames, like <span class="emphasis"><i>red</i></span>, <span class="emphasis"><i>green</i></span>, &#8230; are accepted. This value cannot be changed, once yabasic has been started.</p></dd><dt><span class="term"><tt>-bg <i><tt>BACKGROUND-COLOR</tt></i></tt> or <tt>-background <i><tt>BACKGROUND-COLOR</tt></i></tt></span></dt><dd><p>Define the background color for the graphics-window. The usual X11 colornames are accepted. This value cannot be changed, once yabasic has been started.</p></dd><dt><span class="term"><tt>-geometry +<i><tt>X-POSITION</tt></i>+<i><tt>Y-POSITION</tt></i></tt></span></dt><dd><p>Sets the position of the graphic window, that is opened by <tt>open window</tt> (the <span class="emphasis"><i>size</i></span> of this window, of course, is specified with the <tt>open window</tt>-command). An example would be <tt>+20+10</tt>, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. Note, that the size of the window may not be specified here (well it may, but it will be ignored anyway). This value cannot be changed, once yabasic has been started.</p></dd><dt><span class="term"><tt>-display <i><tt>BACKGROUND-COLOR</tt></i></tt></span></dt><dd><p>Specify the <span class="emphasis"><i>display</i></span>, where the graphics window of yabasic should appear. Normally, however this value will be already present within the environment variable <tt>DISPLAY</tt>.</p></dd><dt><span class="term"><tt>-font <i><tt>NAME-OF-FONT</tt></i></tt></span></dt><dd><p>Name of the font, which will be used for text within the graphics window.</p></dd><dt><span class="term"><tt>-execute <i><tt>A-PROGRAM-AS-A-SINGLE-STRING</tt></i></tt></span></dt><dd><p>With this option you may specify some yabasic-code to be executed rigth away.This is useful for very short programs, which you do not want to save to a file. If this option is given, yabasic will not read any code from a file. E.g. <pre class="programlisting">yabasic -e 'for a=1 to 10:print a*a:next a'</pre> prints the square numbers from 1 to 10.
</p></dd><dt><span class="term"><tt>-bind <i><tt>NAME-OF-STANDALONE-PROGRAM</tt></i></tt></span></dt><dd><p>Create a standalone program (whose name is specified by <i><tt>NAME-OF-STANDALONE-PROGRAM</tt></i>) from the yabasic-program, that is specified on the commandline. See the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><i>standalone</i></span>-program</a> for details.</p></dd><dt><span class="term"><tt>-infolevel <i><tt>INFOLEVEL</tt></i></tt></span></dt><dd><p>Change the <span class="emphasis"><i>infolevel</i></span> of yabasic where <i><tt>INFOLEVEL</tt></i> can be one of <tt>debug</tt>, <tt>note</tt>, <tt>warning</tt>, <tt>error</tt> and <tt>fatal</tt> (the default is <tt>warning</tt>). This option changes the amount of debugging-information yabasic produces. However, normally only the author of yabasic (<span class="emphasis"><i>me</i></span> !) would want to change this.</p></dd><dt><span class="term"><tt>-doc <i><tt>NAME-OF-A-PROGRAM</tt></i></tt></span></dt><dd><p>Print the <span class="emphasis"><i>embedded documentation</i></span> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <tt><a href="#ref_doc" title="doc">doc</a></tt>.</p></dd><dt><span class="term"><tt>-librarypath <i><tt>DIRECTORY-WITH-LIBRARIES</tt></i></tt></span></dt><dd><p>Change the directory from which libraries will be imported (with the <tt><a href="#ref_import" title="import">import</a></tt>-command). See also this entry for more information about the way, libraries will be searched.</p></dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2725188"></a><a name="unix_setting_defaults"></a>Setting defaults</h2></div></div><p>If you want to set some options <span class="emphasis"><i>once for all</i></span>, you may put them into your X-Windows resource file. This is usually the file <tt>.Xresources</tt> or some such within your home directory (type <b><tt>man X</tt></b> for details).</p><p>Here is a sample section, which may appear within this file:</p><pre class="programlisting">
yabasic*foreground: blue
yabasic*background: gold
yabasic*geometry: +10+10
yabasic*font: 9x15
</pre><p>This will set the foreground color of the graphic-window to <span class="emphasis"><i>blue</i></span> and the background color to <span class="emphasis"><i>gold</i></span>. The window will appear at position <span class="emphasis"><i>10,10</i></span> and the text font will be <span class="emphasis"><i>9x15</i></span>.</p></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_topics"></a>Chapter 4. Some features of yabasic, explained by topic</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2725301"><tt>print</tt>, <tt>input</tt> and others</a></dt><dt><a href="#id2725430">Control statements: loops, <tt>if</tt> and <tt>switch</tt></a></dt><dt><a href="#id2787458">Drawing and painting</a></dt><dt><a href="#id2787636">Reading from and writing to files</a></dt><dt><a href="#id2787742">Subroutines and Libraries</a></dt><dt><a href="#id2787834">String processing</a></dt><dt><a href="#id2787987">Arithmetic</a></dt><dt><a href="#id2788126">Data and such</a></dt><dt><a href="#id2788182">Other interesting commands.</a></dt></dl></div><p>This chapter has sections for some of the major features of yabasic and names a few commands related with each area. So, depending on your interest, you find the most important commands of this area named; the other commands from this area may then be discovered through the links in the <span class="emphasis"><i>see also</i></span>-section.</p><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2725301"></a><tt>print</tt>, <tt>input</tt> and others</h2></div></div><p>The <tt><a href="#ref_print" title="print">print</a></tt>-command is used to put text on the text screen. Here, the term <i>text screen</i> stands for your terminal (under Unix) or the console window (under Windows).</p><p>At the bottom line, <tt>print</tt> simply outputs its argument to the text window. However, once you have called <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> you may use advanced features like printing colors or copying areas of text with <tt><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></tt> or <tt><a href="#ref_putscreen" title="putscreen">putscreen</a></tt>.</p><p>You may ask the user for input with the <tt><a href="#ref_input" title="input">input</a></tt>-command; use <tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt> to get each key as soon as it is pressed.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2725430"></a>Control statements: loops, <tt>if</tt> and <tt>switch</tt></h2></div></div><p>Of course, yabasic has the <tt><a href="#ref_goto" title="goto">goto</a></tt>- and <tt><a href="#ref_gosub" title="gosub">gosub</a></tt>-statements; you may go to a <tt><a href="#ref_label" title="label">label</a></tt> or a <span class="emphasis"><i>line number</i></span> (which is just a special kind of label). <tt><a href="#ref_goto" title="goto">goto</a></tt>, despite its bad reputation ([<tt>goto</tt> considered harmful]), has still its good uses; however in many cases you are probably better off with loops like <tt><a href="#ref_repeat" title="repeat">repeat</a></tt>-<tt><a href="#ref_until" title="until">until</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt>-<tt><a href="#ref_wend" title="wend">wend</a></tt> or <tt><a href="#ref_do" title="do">do</a></tt>-<tt><a href="#ref_loop" title="loop">loop</a></tt>; you may leave any of these loops with the <tt><a href="#ref_break" title="break">break</a></tt>-statement or start the next iteration immediately with <tt><a href="#ref_continue" title="continue">continue</a></tt>.</p><p>Decisions can be made with the <tt><a href="#ref_if" title="if">if</a></tt>-statement, which comes either in a <span class="emphasis"><i>short</i></span> and a <span class="emphasis"><i>long</i></span> form. The short form has no <tt><a href="#ref_then" title="then">then</a></tt>-keyword and extends up to the end of the line. The long form extends up to the final <tt><a href="#ref_endif" title="endif">endif</a></tt> and may use some of the keywords <tt><a href="#ref_then" title="then">then</a></tt> (which introduces the long form), <tt><a href="#ref_else" title="else">else</a></tt> or <tt><a href="#ref_elsif" title="elsif">elsif</a></tt>.</p><p>If you want to test the result of an expression against many different values, you should probably use the <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787458"></a>Drawing and painting</h2></div></div><p>You need to call <tt><a href="#ref_open_window" title="open window">open window</a></tt> before you may draw anything with either <tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_circle" title="circle">circle</a></tt> or <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt>; all of these statements may be decorated with <tt><a href="#ref_clear" title="clear">clear</a></tt> or <tt><a href="#ref_fill" title="fill">fill</a></tt>. Note however, that all graphics in yabasic is <span class="emphasis"><i>monochrome</i></span> (&quot;black on white&quot;). Moreover, there can only be a single window open at any given moment in time.</p><p>Evyerything you have drawn can be send to your printer too, if you use the <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt> command.</p><p>To allow for some (very) limited version of animated graphics, yabasic offers the commands <tt><a href="#ref_getbit" title="getbit$()">getbit$</a></tt> and <tt><a href="#ref_putbit" title="putbit">putbit</a></tt>, which retrieve rectangular regions from the graphics-window into a string or vice versa.</p><p>If you want to sense mouse-clicks, you may use the <tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>-function.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787636"></a>Reading from and writing to files</h2></div></div><p>Before you may read or write a file, you need to <tt><a href="#ref_open" title="open">open</a></tt> it; once you are done, you should <tt><a href="#ref_close" title="close">close</a></tt> it. Each open file is designated by a simple number, which might be stored within a variable and must be supplied if you want to access the file. This is simply done by putting a hash ('<tt>#</tt>') followd by the number of the file after the keyword <tt><a href="#ref_input" title="input">input</a></tt> (for reading from) or <tt><a href="#ref_print" title="print">print</a></tt> (for writing to a file) respectively.</p><p>If you need more control, you may consider reading and writing one byte at a time, using the multi-purpose commands <tt><a href="#ref_peek" title="peek">peek</a></tt> and <tt><a href="#ref_poke" title="poke">poke</a></tt>.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787742"></a>Subroutines and Libraries</h2></div></div><p>The best way to break any yabasic-program into smaller, more manageable chunks are <span class="emphasis"><i>subroutines</i></span> and <span class="emphasis"><i>libraries</i></span>. They are yabasic's most advanced means of structuring a program.</p><p>Subroutines are created with the command <tt><a href="#ref_sub" title="sub">sub</a></tt>. they accept parameters and may return a value. Subroutines can be called much like any builtin function of yabasic; therefore they allow to <span class="emphasis"><i>extend</i></span> the language itself.</p><p>Once you have created a set of related subroutines and you feel that they could be useful in other programs too, you may collect them into a <span class="emphasis"><i>library</i></span>. Such a library is contained within a separate file and may be included in any of your programs, using the keyword <tt><a href="#ref_import" title="import">import</a></tt>.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787834"></a>String processing</h2></div></div><p>yabasic has the usual functions to extract parts from a string: <tt><a href="#ref_left" title="left$()">left$</a></tt>, <tt><a href="#ref_mid" title="mid$()">mid$</a></tt> and <tt><a href="#ref_right" title="right$()">right$</a></tt>. Note, that all of them can be assigned to, i.e. they may <span class="emphasis"><i>change</i></span> part of a string.</p><p>If you want to split a string into tokens you should use the functions <tt><a href="#ref_token" title="token()">token</a></tt> or <tt><a href="#ref_split" title="split()">split</a></tt>.</p><p>There is quite a bunch of other string-processing functions like <tt><a href="#ref_upper" title="upper$()">upper$</a></tt> (converting to upper case), <tt><a href="#ref_instr" title="instr()">instr</a></tt> (finding one string within the other), <tt><a href="#ref_chr" title="chr$()">chr$</a></tt> (converting an ascii-code into a character), <tt><a href="#ref_glob" title="glob()">glob</a></tt> (testing a string against a pattern) and more. Just follow the links.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2787987"></a>Arithmetic</h2></div></div><p>Yabasic handles numbers and arithmetic: You may calculate trigonometric functions like <tt><a href="#ref_sin" title="sin()">sin</a></tt> or <tt><a href="#ref_atan" title="atan()">atan</a></tt>, or logarithms (with <tt><a href="#ref_log" title="log()">log</a></tt>). Bitwise operations, like <tt><a href="#ref_arithmetic_and" title="and()">and</a></tt> or <tt><a href="#ref_arithmetic_or" title="or()">or</a></tt> are available as well <tt><a href="#ref_min" title="min()">min</a></tt> or <tt><a href="#ref_max" title="max()">max</a></tt> (calculate the minimum or maximum of its argument) or <tt><a href="#ref_mod" title="mod()">mod</a></tt> or <tt><a href="#ref_int" title="int()">int</a></tt> (reminder of a division or integer part or a number).</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2788126"></a>Data and such</h2></div></div><p>You may store data within your program within <tt><a href="#ref_data" title="data">data</a></tt>-statements; during execution you will probably want to <tt><a href="#ref_read" title="read">read</a></tt> it into <span class="emphasis"><i>arrays</i></span>, which must have been <tt><a href="#ref_dim" title="dim">dim</a></tt>ed before.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2788182"></a>Other interesting commands.</h2></div></div><div class="itemizedlist"><ul><li><p>Yabasic programs may start other programs with the commands <tt><a href="#ref_system" title="system$()">system</a></tt> and <tt><a href="#ref_system2" title="system()">system$</a></tt>.</p></li><li><p><tt><a href="#ref_peek" title="peek">peek</a></tt> and <tt><a href="#ref_poke" title="poke">poke</a></tt> allow to get and set internal information; either for the operating system (i.e. Unix or Windows) or yabasic itself.</p></li><li><p>The current time or date can be retrieved with (guess what !) <tt><a href="#ref_time" title="time$">time$</a></tt> and <tt><a href="#ref_date" title="date$">date$</a></tt>.</p></li></ul></div></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_topics_list"></a>Chapter 5. All commands and functions of yabasic listed by topic</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#top_numbers">Number processing and conversion</a></dt><dt><a href="#top_conditions">Conditions and control structures</a></dt><dt><a href="#top_data">Data keeping and processing</a></dt><dt><a href="#top_strings">String processing</a></dt><dt><a href="#top_io">File operations and printing</a></dt><dt><a href="#top_sub">Subroutines and libraries</a></dt><dt><a href="#top_other">Other commands</a></dt><dt><a href="#top_graphics">Graphics and printing</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_numbers"></a>Number processing and conversion</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_abs" title="abs()">abs()</a></span></dt><dd>
returns the absolute value of its numeric argument
</dd><dt><span class="term"><a href="#ref_acos" title="acos()">acos()</a></span></dt><dd>
returns the arcus cosine of its numeric argument
</dd><dt><span class="term"><a href="#ref_arithmetic_and" title="and()">and()</a></span></dt><dd>
the bitwise arithmetic <tt>and</tt></dd><dt><span class="term"><a href="#ref_asin" title="asin()">asin()</a></span></dt><dd>
returns the arcus sine of its numeric argument
</dd><dt><span class="term"><a href="#ref_atan" title="atan()">atan()</a></span></dt><dd>
returns the arcus tangens of its numeric argument
</dd><dt><span class="term"><a href="#ref_bin" title="bin$()">bin$()</a></span></dt><dd>
converts a number into a sequence of binary digits
</dd><dt><span class="term"><a href="#ref_cos" title="cos()">cos()</a></span></dt><dd>
return the cosine of its single argument
</dd><dt><span class="term"><a href="#ref_dec" title="dec()">dec()</a></span></dt><dd>
convert a base 2 or base 16 number into decimal form
</dd><dt><span class="term"><a href="#ref_eor" title="eor()">eor()</a></span></dt><dd>
compute the bitwise <span class="emphasis"><i>exclusive or</i></span> of its two arguments
</dd><dt><span class="term"><a href="#ref_euler" title="euler">euler</a></span></dt><dd>
another name for the constant <tt>2.71828182864</tt></dd><dt><span class="term"><a href="#ref_exp" title="exp()">exp()</a></span></dt><dd>
compute the exponential function of its single argument
</dd><dt><span class="term"><a href="#ref_frac" title="frac()">frac()</a></span></dt><dd>
return the fractional part of its numeric argument
</dd><dt><span class="term"><a href="#ref_int" title="int()">int()</a></span></dt><dd>
return the integer part of its single numeric argument
</dd><dt><span class="term"><a href="#ref_log" title="log()">log()</a></span></dt><dd>
compute the natural logarithm
</dd><dt><span class="term"><a href="#ref_max" title="max()">max()</a></span></dt><dd>
return the larger of its two arguments
</dd><dt><span class="term"><a href="#ref_min" title="min()">min()</a></span></dt><dd>
return the smaller of its two arguments
</dd><dt><span class="term"><a href="#ref_mod" title="mod()">mod()</a></span></dt><dd>
compute the remainder of a division
</dd><dt><span class="term"><a href="#ref_arithmetic_or" title="or()">or()</a></span></dt><dd>
arithmetic or, used for bit-operations
</dd><dt><span class="term"><a href="#ref_pi" title="pi">pi</a></span></dt><dd>
a constant with the value <tt>3.14159</tt></dd><dt><span class="term"><a href="#ref_ran" title="ran()">ran()</a></span></dt><dd>
return a random number
</dd><dt><span class="term"><a href="#ref_sig" title="sig()">sig()</a></span></dt><dd>
return the sign of its argument
</dd><dt><span class="term"><a href="#ref_sin" title="sin()">sin()</a></span></dt><dd>
return the sine of its single argument
</dd><dt><span class="term"><a href="#ref_sqr" title="sqr()">sqr()</a></span></dt><dd>
compute the square of its argument
</dd><dt><span class="term"><a href="#ref_sqrt" title="sqrt()">sqrt()</a></span></dt><dd>
compute the square root of its argument
</dd><dt><span class="term"><a href="#ref_tan" title="tan()">tan()</a></span></dt><dd>
return the tangens of its argument
</dd><dt><span class="term"><a href="#ref_xor" title="xor()">xor()</a></span></dt><dd>
compute the exclusive or
</dd><dt><span class="term"><a href="#ref_pow" title="** or ^">** or ^</a></span></dt><dd>
raise its first argument to the power of its second
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_conditions"></a>Conditions and control structures</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_logical_and" title="and">and</a></span></dt><dd>
logical and, used in conditions
</dd><dt><span class="term"><a href="#ref_break" title="break">break</a></span></dt><dd>
breaks out of a switch statement or a loop
</dd><dt><span class="term"><a href="#ref_case" title="case">case</a></span></dt><dd>
mark the different cases within a <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement
</dd><dt><span class="term"><a href="#ref_continue" title="continue">continue</a></span></dt><dd>
start the next iteration of a <tt>for</tt>-, <tt>do</tt>-, <tt>repeat</tt>- or <tt>while</tt>-loop
</dd><dt><span class="term"><a href="#ref_default" title="default">default</a></span></dt><dd>
mark the <span class="emphasis"><i>default</i></span>-branch within a <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement
</dd><dt><span class="term"><a href="#ref_do" title="do">do</a></span></dt><dd>
start a (conditionless) <tt>do-loop</tt></dd><dt><span class="term"><a href="#ref_else" title="else">else</a></span></dt><dd>
mark an alternative within an <tt>if</tt>-statement
</dd><dt><span class="term"><a href="#ref_elsif" title="elsif">elsif</a></span></dt><dd>
starts an alternate condition within an <tt>if</tt>-statement
</dd><dt><span class="term"><a href="#ref_end" title="end">end</a></span></dt><dd>
terminate your program
</dd><dt><span class="term"><a href="#ref_endif" title="endif">endif</a></span></dt><dd>
ends an <tt>if</tt>-statement
</dd><dt><span class="term"><a href="#ref_false" title="false">false</a></span></dt><dd>
a constant with the value of 0
</dd><dt><span class="term"><a href="#ref_fi" title="fi">fi</a></span></dt><dd>
another name for <tt><a href="#ref_endif" title="endif">endif</a></tt></dd><dt><span class="term"><a href="#ref_for" title="for">for</a></span></dt><dd>
starts a <tt>for</tt>-loop
</dd><dt><span class="term"><a href="#ref_gosub" title="gosub">gosub</a></span></dt><dd>
continue execution at another point within your program (and return later)
</dd><dt><span class="term"><a href="#ref_goto" title="goto">goto</a></span></dt><dd>
continue execution at another point within your program (and never come back)
</dd><dt><span class="term"><a href="#ref_if" title="if">if</a></span></dt><dd>
evaluate a condition and execute statements or not, depending on the result
</dd><dt><span class="term"><a href="#ref_label" title="label">label</a></span></dt><dd>
mark a specific location within your program for <tt>goto</tt>, <tt>gosub</tt> or <tt>restore</tt></dd><dt><span class="term"><a href="#ref_loop" title="loop">loop</a></span></dt><dd>
marks the end of an infinite loop
</dd><dt><span class="term"><a href="#ref_next" title="next">next</a></span></dt><dd>
mark the end of a for loop
</dd><dt><span class="term"><a href="#ref_not" title="not">not</a></span></dt><dd>
negate an expression; can be written as <tt>!</tt></dd><dt><span class="term"><a href="#ref_on_gosub" title="on gosub">on gosub</a></span></dt><dd>
jump to one of multiple <tt>gosub</tt>-targets
</dd><dt><span class="term"><a href="#ref_on_goto" title="on goto">on goto</a></span></dt><dd>
jump to one of many <tt>goto</tt>-targets
</dd><dt><span class="term"><a href="#ref_on_interrupt" title="on interrupt">on interrupt</a></span></dt><dd>
change reaction on keyboard interrupts
</dd><dt><span class="term"><a href="#ref_logical_or" title="logical or">logical or</a></span></dt><dd>
logical or, used in conditions
</dd><dt><span class="term"><a href="#ref_pause" title="pause">pause</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_repeat" title="repeat">repeat</a></span></dt><dd>
start a <tt>repeat</tt>-loop
</dd><dt><span class="term"><a href="#ref_return" title="return">return</a></span></dt><dd>
return from a subroutine or a gosub
</dd><dt><span class="term"><a href="#ref_sleep" title="sleep">sleep</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_switch" title="switch">switch</a></span></dt><dd>
select one of many alternatives depending on a value
</dd><dt><span class="term"><a href="#ref_then" title="then">then</a></span></dt><dd>
tell the long from the short form of the <tt>if</tt>-statement
</dd><dt><span class="term"><a href="#ref_true" title="true">true</a></span></dt><dd>
a constant with the value of 1
</dd><dt><span class="term"><a href="#ref_until" title="until">until</a></span></dt><dd>
end a <tt>repeat</tt>-loop
</dd><dt><span class="term"><a href="#ref_wait" title="wait">wait</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_wend" title="wend">wend</a></span></dt><dd>
end a <tt><a href="#ref_while" title="while">while</a></tt>-loop
</dd><dt><span class="term"><a href="#ref_while" title="while">while</a></span></dt><dd>
start a <tt>while</tt>-loop
</dd><dt><span class="term"><a href="#ref_colon" title=":">:</a></span></dt><dd>
separate commands from each other
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_data"></a>Data keeping and processing</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_arraydim" title="arraydim()">arraydim()</a></span></dt><dd>
returns the dimension of the array, which is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a></dd><dt><span class="term"><a href="#ref_arraysize" title="arraysize()">arraysize()</a></span></dt><dd>
returns the size of a dimension of an array
</dd><dt><span class="term"><a href="#ref_data" title="data">data</a></span></dt><dd>
introduces a list of data-items
</dd><dt><span class="term"><a href="#ref_dim" title="dim">dim</a></span></dt><dd>
create an array prior to its first use
</dd><dt><span class="term"><a href="#ref_read" title="read">read</a></span></dt><dd>
read data from <tt>data</tt>-statements
</dd><dt><span class="term"><a href="#ref_redim" title="redim">redim</a></span></dt><dd>
create an array prior to its first use. A synonym for <tt>dim</tt></dd><dt><span class="term"><a href="#ref_restore" title="restore">restore</a></span></dt><dd>
reposition the <tt>data</tt>-pointer
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_strings"></a>String processing</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_asc" title="asc()">asc()</a></span></dt><dd>
accepts a string and returns the position of its first character within the ascii charset
</dd><dt><span class="term"><a href="#ref_chr" title="chr$()">chr$()</a></span></dt><dd>
accepts a number and returns the character at this position within the ascii charset
</dd><dt><span class="term"><a href="#ref_glob" title="glob()">glob()</a></span></dt><dd>
check if a string matches a simple pattern
</dd><dt><span class="term"><a href="#ref_hex" title="hex$()">hex$()</a></span></dt><dd>
convert a number into hexadecimal
</dd><dt><span class="term"><a href="#ref_instr" title="instr()">instr()</a></span></dt><dd>
searches its second argument within the first; returns its position if found
</dd><dt><span class="term"><a href="#ref_left" title="left$()">left$()</a></span></dt><dd>
return (<span class="emphasis"><i>or change</i></span>) left end of a string
</dd><dt><span class="term"><a href="#ref_len" title="len()">len()</a></span></dt><dd>
return the length of a string
</dd><dt><span class="term"><a href="#ref_lower" title="lower$()">lower$()</a></span></dt><dd>
convert a string to lower case
</dd><dt><span class="term"><a href="#ref_ltrim" title="ltrim$()">ltrim$()</a></span></dt><dd>
trim spaces at the left end of a string
</dd><dt><span class="term"><a href="#ref_mid" title="mid$()">mid$()</a></span></dt><dd>
return (<span class="emphasis"><i>or change</i></span>) characters from within a string
</dd><dt><span class="term"><a href="#ref_right" title="right$()">right$()</a></span></dt><dd>
return (<span class="emphasis"><i>or change</i></span>) the right end of a string
</dd><dt><span class="term"><a href="#ref_split" title="split()">split()</a></span></dt><dd>
split a string into many strings
</dd><dt><span class="term"><a href="#ref_str" title="str$()">str$()</a></span></dt><dd>
convert a number into a string
</dd><dt><span class="term"><a href="#ref_token" title="token()">token()</a></span></dt><dd>
split a string into multiple strings
</dd><dt><span class="term"><a href="#ref_trim" title="trim$()">trim$()</a></span></dt><dd>
remove leading and trailing spaces from its argument
</dd><dt><span class="term"><a href="#ref_upper" title="upper$()">upper$()</a></span></dt><dd>
convert a string to upper case
</dd><dt><span class="term"><a href="#ref_val" title="val()">val()</a></span></dt><dd>
converts a string to a number
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_io"></a>File operations and printing</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_at" title="at()">at()</a></span></dt><dd>
can be used in the <tt>print</tt>-command to place the output at a specified position
</dd><dt><span class="term"><a href="#ref_beep" title="beep">beep</a></span></dt><dd>
ring the bell within your computer; a synonym for <tt>bell</tt></dd><dt><span class="term"><a href="#ref_bell" title="bell">bell</a></span></dt><dd>
ring the bell within your computer (just as <tt>beep</tt>)
</dd><dt><span class="term"><a href="#ref_clear" title="clear">clear screen</a></span></dt><dd>
erases the text window
</dd><dt><span class="term"><a href="#ref_close" title="close">close</a></span></dt><dd>
close a file, which has been opened before
</dd><dt><span class="term"><a href="#ref_close" title="close">close printer</a></span></dt><dd>
stops printing of graphics
</dd><dt><span class="term"><a href="#ref_color" title="color">color</a></span></dt><dd>
print with color
</dd><dt><span class="term"><a href="#ref_colour" title="colour">colour</a></span></dt><dd>
see <tt><a href="#ref_color" title="color">color</a></tt></dd><dt><span class="term"><a href="#ref_eof" title="eof">eof</a></span></dt><dd>
check, if an open file contains data
</dd><dt><span class="term"><a href="#ref_getscreen" title="getscreen$()">getscreen$()</a></span></dt><dd>
returns a string representing a rectangular section of the text terminal
</dd><dt><span class="term"><a href="#ref_inkey" title="inkey$">inkey$</a></span></dt><dd>
wait, until a key is pressed
</dd><dt><span class="term"><a href="#ref_input" title="input">input</a></span></dt><dd>
read input from the user (or from a file) and assign it to a variable
</dd><dt><span class="term"><a href="#ref_line" title="line">line input</a></span></dt><dd>
read in a whole line of text and assign it to a variable
</dd><dt><span class="term"><a href="#ref_open" title="open">open</a></span></dt><dd>
open a file
</dd><dt><span class="term"><a href="#ref_open_printer" title="open printer">open printer</a></span></dt><dd>
open printer for printing graphics
</dd><dt><span class="term"><a href="#ref_print" title="print">print</a></span></dt><dd>
Write to terminal or file
</dd><dt><span class="term"><a href="#ref_putscreen" title="putscreen">putscreen</a></span></dt><dd>
draw a rectangle of characters into the text terminal
</dd><dt><span class="term"><a href="#ref_reverse" title="reverse">reverse</a></span></dt><dd>
print reverse (background and foreground colors exchanged)
</dd><dt><span class="term"><a href="#ref_screen" title="screen">screen</a></span></dt><dd>
as <tt>clear screen</tt> clears the text window
</dd><dt><span class="term"><a href="#ref_seek" title="seek()">seek()</a></span></dt><dd>
change the position within an open file
</dd><dt><span class="term"><a href="#ref_tell" title="tell">tell</a></span></dt><dd>
get the current position within an open file
</dd><dt><span class="term"><a href="#ref_using" title="using">using</a></span></dt><dd>
Specify the format for printing a number
</dd><dt><span class="term"><a href="#ref_hash" title="#">#</a></span></dt><dd>
either a comment or a marker for a file-number
</dd><dt><span class="term"><a href="#ref_at" title="at()">@</a></span></dt><dd>
synonymous to <tt><a href="#ref_at" title="at()">at</a></tt></dd><dt><span class="term"><a href="#ref_semicolon" title=";">;</a></span></dt><dd>
suppress the implicit newline after a <tt><a href="#ref_print" title="print">print</a></tt>-statement
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_sub"></a>Subroutines and libraries</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_end_sub" title="end sub">end sub</a></span></dt><dd>
ends a subroutine definition
</dd><dt><span class="term"><a href="#ref_export" title="export">export</a></span></dt><dd>
mark a function as globally visible
</dd><dt><span class="term"><a href="#ref_import" title="import">import</a></span></dt><dd>
import a library
</dd><dt><span class="term"><a href="#ref_local" title="local">local</a></span></dt><dd>
mark a variable as local to a subroutine
</dd><dt><span class="term"><a href="#ref_numparams" title="numparams">numparams</a></span></dt><dd>
return the number of parameters, that have been passed to a subroutine
</dd><dt><span class="term"><a href="#ref_return" title="return">return</a></span></dt><dd>
return from a subroutine or a gosub
</dd><dt><span class="term"><a href="#ref_static" title="static">static</a></span></dt><dd>
preserves the value of a variable between calls to a subroutine
</dd><dt><span class="term"><a href="#ref_step" title="step">step</a></span></dt><dd>
specifies the increment step in a for-loop
</dd><dt><span class="term"><a href="#ref_sub" title="sub">sub</a></span></dt><dd>
declare a user defined subroutine
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_other"></a>Other commands</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_bind" title="bind()">bind()</a></span></dt><dd>
Binds a yabasic-program and the yabasic-interpreter together into a <span class="emphasis"><i>standalone</i></span> program.
</dd><dt><span class="term"><a href="#ref_compile" title="compile">compile</a></span></dt><dd>
compile a string with yabasic-code <span class="emphasis"><i>on the fly</i></span></dd><dt><span class="term"><a href="#ref_date" title="date$">date$</a></span></dt><dd>
returns a string with various components of the current date
</dd><dt><span class="term"><a href="#ref_doc" title="doc">doc</a></span></dt><dd>
special comment, which might be retrieved by the program itself
</dd><dt><span class="term"><a href="#ref_docu" title="docu$">docu$</a></span></dt><dd>
special array, containing the contents of all docu-statement within the program
</dd><dt><span class="term"><a href="#ref_error" title="error">error</a></span></dt><dd>
raise an error and terminate your program
</dd><dt><span class="term"><a href="#ref_execute" title="execute()">execute$()</a></span></dt><dd>
execute a user defined subroutine, which must return a string
</dd><dt><span class="term"><a href="#ref_execute" title="execute()">execute()</a></span></dt><dd>
execute a user defined subroutine, which must return a number
</dd><dt><span class="term"><a href="#ref_exit" title="exit">exit</a></span></dt><dd>
terminate your program
</dd><dt><span class="term"><a href="#ref_pause" title="pause">pause</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_peek" title="peek">peek</a></span></dt><dd>
retrieve various internal informations
</dd><dt><span class="term"><a href="#ref_peek2" title="peek$">peek$</a></span></dt><dd>
retrieve various internal string-informations
</dd><dt><span class="term"><a href="#ref_poke" title="poke">poke</a></span></dt><dd>
change selected internals of yabasic</dd><dt><span class="term"><a href="#ref_rem" title="rem">rem</a></span></dt><dd>
start a comment
</dd><dt><span class="term"><a href="#ref_sleep" title="sleep">sleep</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_system" title="system$()">system$()</a></span></dt><dd>
hand a statement over to your operating system and return its output
</dd><dt><span class="term"><a href="#ref_system2" title="system()">system()</a></span></dt><dd>
hand a statement over to your operating system and return its exitcode
</dd><dt><span class="term"><a href="#ref_time" title="time$">time$</a></span></dt><dd>
return a string containing the current time
</dd><dt><span class="term"><a href="#ref_to" title="to">to</a></span></dt><dd>
this keyword appears as part of other statements
</dd><dt><span class="term"><a href="#ref_wait" title="wait">wait</a></span></dt><dd>
pause, sleep, wait for the specified number of seconds
</dd><dt><span class="term"><a href="#ref_double_slash" title="//">//</a></span></dt><dd>
starts a comment
</dd><dt><span class="term"><a href="#ref_colon" title=":">:</a></span></dt><dd>
separate commands from each other
</dd></dl></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="top_graphics"></a>Graphics and printing</h2></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_box" title="box">box</a></span></dt><dd>
draw a rectancle. A synonym for <tt>rectangle</tt></dd><dt><span class="term"><a href="#ref_circle" title="circle">circle</a></span></dt><dd>
draws a circle in the graphic-window
</dd><dt><span class="term"><a href="#ref_clear" title="clear">clear</a></span></dt><dd>
Erase <tt>circle</tt>s or <tt>rectangle</tt>s
</dd><dt><span class="term"><a href="#ref_clear_window" title="clear window">clear window</a></span></dt><dd>
clear the graphic window and begin a new page, if prining is under way
</dd><dt><span class="term"><a href="#ref_close" title="close">close curve</a></span></dt><dd>
close a curve, that has been drawn by the <tt>line</tt>-command
</dd><dt><span class="term"><a href="#ref_close" title="close">close window</a></span></dt><dd>
close the graphics-window
</dd><dt><span class="term"><a href="#ref_dot" title="dot">dot</a></span></dt><dd>
draw a dot in the graphic-window
</dd><dt><span class="term"><a href="#ref_fill" title="fill">fill</a></span></dt><dd>
draw a filled <tt>circle</tt>s or <tt>rectangle</tt>s
</dd><dt><span class="term"><a href="#ref_getbit" title="getbit$()">getbit$()</a></span></dt><dd>
return a string representing the bit pattern of a rectangle within the graphic window
</dd><dt><span class="term"><a href="#ref_line" title="line">line</a></span></dt><dd>
draw a line
</dd><dt><span class="term"><a href="#ref_mouseb" title="mouseb">mouseb</a></span></dt><dd>
extract the state of the mousebuttons from a string returned by <tt>inkey$</tt></dd><dt><span class="term"><a href="#ref_mousemod" title="mousemod">mousemod</a></span></dt><dd>
return the state of the modifier keys during a mouseclick
</dd><dt><span class="term"><a href="#ref_mousex" title="mousex">mousex</a></span></dt><dd>
return the x-position of a mouseclick
</dd><dt><span class="term"><a href="#ref_mousey" title="mousey">mousey</a></span></dt><dd>
return the y-position of a mouseclick
</dd><dt><span class="term"><a href="#ref_new_curve" title="new curve">new curve</a></span></dt><dd>
start a new curve, that will be drawn with the <tt>line</tt>-command
</dd><dt><span class="term"><a href="#ref_open_window" title="open window">open window</a></span></dt><dd>
open a graphic window
</dd><dt><span class="term"><a href="#ref_putbit" title="putbit">putbit</a></span></dt><dd>
draw a rectangle of pixels into the graphic window
</dd><dt><span class="term"><a href="#ref_rectangle" title="rectangle">rectangle</a></span></dt><dd>
draw a rectangle
</dd><dt><span class="term"><a href="#ref_text" title="text">text</a></span></dt><dd>
write text into your graphic-window
</dd><dt><span class="term"><a href="#ref_origin" title="window origin">window origin</a></span></dt><dd>
move the origin of a window
</dd></dl></div></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_ref_words"></a>Chapter 6. All commands and functions of yabasic grouped alphabetically</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_a">A</a></dt><dt><a href="#ref_b">B</a></dt><dt><a href="#ref_c">C</a></dt><dt><a href="#ref_d">D</a></dt><dt><a href="#ref_e">E</a></dt><dt><a href="#ref_f">F</a></dt><dt><a href="#ref_g">G</a></dt><dt><a href="#ref_h">H</a></dt><dt><a href="#ref_i">I</a></dt><dt><a href="#ref_l">L</a></dt><dt><a href="#ref_m">M</a></dt><dt><a href="#ref_n">N</a></dt><dt><a href="#ref_o">O</a></dt><dt><a href="#ref_p">P</a></dt><dt><a href="#ref_r">R</a></dt><dt><a href="#ref_s">S</a></dt><dt><a href="#ref_t">T</a></dt><dt><a href="#ref_u">U</a></dt><dt><a href="#ref_v">V</a></dt><dt><a href="#ref_w">W</a></dt><dt><a href="#ref_x">X</a></dt><dt><a href="#ref_special_characters">Special characters</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_a"></a>A</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_abs">abs()</a> - returns the absolute value of its numeric argument</dt><dt><a href="#ref_acos">acos()</a> - returns the arcus cosine of its numeric argument</dt><dt><a href="#ref_logical_and">and</a> - logical and, used in conditions</dt><dt><a href="#ref_arithmetic_and">and()</a> - the bitwise arithmetic and</dt><dt><a href="#ref_arraydim">arraydim()</a> - returns the dimension of the array, which is passed as an array reference</dt><dt><a href="#ref_arraysize">arraysize()</a> - returns the size of a dimension of an array</dt><dt><a href="#ref_asc">asc()</a> - accepts a string and returns the position of its first character within the ascii charset</dt><dt><a href="#ref_asin">asin()</a> - returns the arcus sine of its numeric argument</dt><dt><a href="#ref_at">at()</a> - can be used in the print-command to place the output at a specified position</dt><dt><a href="#ref_atan">atan()</a> - returns the arcus tangens of its numeric argument</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_abs"></a>abs()</h1><div class="refnamediv"><h2>Name</h2><p>abs() &#8212; returns the absolute value of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">y=abs(x)</pre></div><div class="refsect1"><h2>Description</h2><p>If the argument of the <tt>abs</tt>-function is positive (e.g. 2) it is returned unchanged, if the argument is negative (e.g. -1) it is returned as a positive value (e.g. 1).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print abs(-2),abs(2)
</pre><p>This example will print <tt>2 2</tt></p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_sig" title="sig()"><tt>sig</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_acos"></a>acos()</h1><div class="refnamediv"><h2>Name</h2><p>acos() &#8212; returns the arcus cosine of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">x=acos(angle)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>acos</tt> is the arcus cosine-function, i.e. the inverse of the <a href="#ref_cos" title="cos()"><tt>cos</tt></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the cosine-function will produce the argument passed to the <tt>acos</tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print acos(0.5),acos(cos(pi))
</pre><p>This example will print <tt>1.0472 3.14159</tt> which are &#960;/3 and &#960; respectively.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_cos" title="cos()"><tt>cos</tt></a>, <a href="#ref_asin" title="asin()"><tt>asin</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_logical_and"></a>and</h1><div class="refnamediv"><h2>Name</h2><p>and &#8212; logical and, used in conditions</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a and b) &#8230;
while (a and b) &#8230;
</pre></div><div class="refsect1"><h2>Description</h2><p>Used in conditions (e.g within <tt><a href="#ref_if" title="if">if</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt> or <tt><a href="#ref_until" title="until">until</a></tt>) to join two expressions. Returns <tt>true</tt>, if and only if its left and right argument are both <tt>true</tt> and <tt>false</tt> otherwise.</p><p>Note, that <a href="#ref_logical_shortcuts" title="Logical shortcuts"><span class="emphasis"><i>logical shortcuts</i></span></a>may take place.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number&quot; a
if (a&gt;=1 and a&lt;=9) print &quot;your input is between 1 and 9&quot;
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_logical_or" title="logical or"><tt>or</tt></a>,<a href="#ref_not" title="not"><tt>not</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_arithmetic_and"></a>and()</h1><div class="refnamediv"><h2>Name</h2><p>and() &#8212; the bitwise arithmetic <tt>and</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=and(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>Used to compute the bitwise <tt>and</tt> of both its argument. Both arguments are treated as binary numbers (i.e. a series of 0 and 1); a bit of the resulting value will then be 1, if both arguments have a 1 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <tt>and</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print and(6,3)
</pre><p>This will print <tt>2</tt>. This result is clear, if you note, that the binary representation of 6 and 3 are 110 and 011 respectively; this will yield 010 in binary representaion or 2 as decimal.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arithmetic_or" title="or()"><tt>or</tt></a>, <a href="#ref_eor" title="eor()"><tt>eor</tt></a> and <a href="#ref_not" title="not"><tt>not</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_arraydim"></a>arraydim()</h1><div class="refnamediv"><h2>Name</h2><p>arraydim() &#8212; returns the dimension of the array, which is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a=arraydim(b())</pre></div><div class="refsect1"><h2>Description</h2><p>If you apply the <tt>arraydim()</tt>-function on a one-dimensional array (i.e. a vector) it will return <tt>1</tt>, on a two-dimensional array (i.e. a matrix) it will return 2, and so on.</p><p>This is mostly used within subroutines, which expect an array among their parameters. Such subroutines tend to use the <tt>arraydim</tt>-funtion to check, if the array which has been passed, has the right dimension. E.g. a subroutine to multiply two matrices may want to check, if it really is invoked with two 2-dimensional arrays.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim a(10,10),b(10)
print arraydim(a()),arraydim(b())
</pre><p>This will print <tt>2 1</tt>, which are the dimension of the arrays <tt>a()</tt> and <tt>b()</tt>. You may check out the function <a href="#ref_arraysize" title="arraysize()"><tt>arraysize</tt></a> for a full-fledged example.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><tt>arraysize</tt></a> and <a href="#ref_dim" title="dim"><tt>dim</tt></a>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_arraysize"></a>arraysize()</h1><div class="refnamediv"><h2>Name</h2><p>arraysize() &#8212; returns the size of a dimension of an array</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">x=arraysize(a(),b)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>arraysize</tt>-function computes the size of a specified dimension of a specified array. Here, <span class="emphasis"><i>size</i></span> stands for the maximum number, that may be used as an index for this array. The first argument to this function must be an <a href="#ref_array_references" title="References on arrays">reference to an array</a>, the second one specifies, which of the multiple dimensions of the array should be taken to calculate the size.</p><p>An Example involving subroutines: Let's say, an array has been declared as <tt>dim a(10,20)</tt> (that is a two-dimensional array or a matrix). If this array is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a> to a subroutine, this sub will not know, what sort of array has been passed. With the <tt>arraydim</tt>-function the sub will be able to find the dimension of the array, with the <tt>arraysize</tt>-function it will be able to find out the size of this array in its two dimensions, which will be 10 and 20 respectively.</p><p>Our sample array is two dimensional; if you envision it as a matrix this matrix has 10 lines and 20 columns (see the <tt>dim</tt>-statement above. To state it more formally: The first dimension (lines) has a size of 10, the second dimension (columns) has a size of 20; these mumbers are those returned by <tt>arraysize(a(),1)</tt> and <tt>arraysize(a(),2)</tt> respectively. Refer to the example below for a typical usage.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
rem
rem This program adds two matrices elementwise.
rem
dim a(10,20),b(10,20),c(10,20)
rem initialization of the arrays a() and b()
for y=1 to 10:for x=1 to 20
a(y,x)=int(ran(4)):b(y,x)=int(ran(4))
next x:next y
matadd(a(),b(),c())
print &quot;Result:&quot;
for x=1 to 20
for y=10 to 1 step -1
print c(y,x),&quot; &quot;;
next y
print
next x
sub matadd(m1(),m2(),r())
rem This sub will add the matrices m1() and m2()
rem elementwise and store the result within r()
rem This is not very useful but easy to implement.
rem However, this sub excels in checking its arguments
rem with arraydim() and arraysize()
local x:local y
if (arraydim(m1())&lt;&gt;2 or arraydim(m2())&lt;&gt;2 or arraydim(r())&lt;&gt;2) then
error &quot;Need two dimensional arrays as input&quot;
endif
y=arraysize(m1(),1):x=arraysize(m1(),2)
if (arraysize(m2(),1)&lt;&gt;y or arraysize(m2(),2)&lt;&gt;x) then
error &quot;The two matrices cannot be added elementwise&quot;
endif
if (arraysize(r(),1)&lt;&gt;y or arraysize(r(),2)&lt;&gt;x) then
error &quot;The result cannot be stored in the third argument&quot;
endif
local xx:local yy
for xx=1 to x
for yy=1 to y
r(yy,xx)=m1(yy,xx)+m2(yy,xx)
next yy
next xx
end sub
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arraydim" title="arraydim()"><tt>arraydim</tt></a> and <a href="#ref_dim" title="dim"><tt>dim</tt></a>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_asc"></a>asc()</h1><div class="refnamediv"><h2>Name</h2><p>asc() &#8212; accepts a string and returns the position of its first character within the ascii charset</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a=asc(char$)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>asc</tt>-function accepts a string, takes its first character and looks it up within the ascii-charset; this position will be returned. The <tt>asc</tt>-function is the opposite of the <tt><a href="#ref_chr" title="chr$()">chr$</a></tt>-function. There are valid uses for <tt>asc</tt>, however, comparing strings (i.e. to bring them into alphabetical sequence) is <span class="emphasis"><i>not</i></span> among them; in such many cases you might consider to compare strings directly with <tt>&lt;</tt>, <tt>=</tt> and <tt>&gt;</tt> (rather than converting a string to a number and comparing this number).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a letter between 'a' and 'y': &quot; a$
if (a$&lt;&quot;a&quot; or a$&gt;&quot;y&quot;) print a$,&quot; is not in the proper range&quot;:end
print &quot;The letter after &quot;,a$,&quot; is &quot;,chr$(asc(a$)+1)
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_chr" title="chr$()"><tt>chr$</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_asin"></a>asin()</h1><div class="refnamediv"><h2>Name</h2><p>asin() &#8212; returns the arcus sine of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">angle=asin(x)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>acos</tt> is the arcus sine-function, i.e. the inverse of the <a href="#ref_sin" title="sin()"><tt>sin</tt></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the sine-function will produce the argument passed to the <tt>asin</tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print asin(0.5),asin(sin(pi))
</pre><p>This will print <tt>0.523599 -2.06823e-13</tt> which is &#960; and almost 0 respectively.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_sin" title="sin()"><tt>sin</tt></a>, <a href="#ref_acos" title="acos()"><tt>acos</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_at"></a>at()</h1><div class="refnamediv"><h2>Name</h2><p>at() &#8212; can be used in the <tt>print</tt>-command to place the output at a specified position</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
&#8230;
print at(a,b)
print @(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>at</tt>-clause takes two numeric arguments (e.g. <tt>at(2,3)</tt>) and can be inserted after the <tt>print</tt>-keyword. <tt>at()</tt> can be used only if <a href="#ref_clear_screen" title="clear screen"><tt>clear screen</tt></a> has been executed at least once within the program (otherwise you will get an error).</p><p>The two numeric arguments of the <tt>at</tt>-function may range from 0 to the width of your terminal minus 1, and from 0 to the height of your terminal minus 1; if any argument exceeds these values, it will be truncated accordingly. However, yabasic has no influence on the size of your terminal (80x25 is a common, but not mandatory), the size of your terminal and the maximum values acceptable within the <tt>at</tt>-clause may vary. To get the size of your terminal you may use the <a href="#ref_peek" title="peek"><tt>peek</tt></a>-function: <tt>peek(&quot;screenwidth&quot;)</tt> returns the width of your terminal and <tt>peek(&quot;screenheight&quot;)</tt> its height.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
maxx=peek(&quot;screenwidth&quot;)-1:maxy=peek(&quot;screenheight&quot;)-1
for x=0 to maxx
print at(x,maxy*(0.5+sin(2*pi*x/maxx)/2)) &quot;*&quot;
next x
</pre><p>This example plots a full period of the sine-function across the screen.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_print" title="print"><tt>print</tt></a>, <a href="#ref_clear_screen" title="clear screen"><tt>clear screen</tt></a>, <a href="#ref_color" title="color"><tt>color</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_atan"></a>atan()</h1><div class="refnamediv"><h2>Name</h2><p>atan() &#8212; returns the arcus tangens of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
angle=atan(a,b)
angle=atan(a)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>atan</tt> is the arcus-tangens-function, i.e. the inverse of the <a href="#ref_tan" title="tan()"><tt>tan</tt></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the <tt>tan</tt>-function will produce the argument passed to the <tt>atan</tt>-function.</p><p>The <tt>atan</tt>-function has a second form, which accepts two arguments: <tt>atan(a,b)</tt> which is (mostly) equivilantly to <tt>atan(a/b)</tt> <span class="emphasis"><i>except</i></span> for the fact, that the two-argument-form returns an angle in the range -&#960; to &#960;, whereas the one-argument-form returns an angle in the range -&#960;/2 to &#960;/2. To understand this you have to be good at math.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print atan(1),atan(tan(pi)),atan(-0,-1),atan(-0,1)
</pre><p>This will print <tt>0.463648 2.06823e-13 -3.14159 3.14159</tt> which is &#960;/4, almost 0, -&#960; and &#960; respectively.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_tan" title="tan()">tan</a></tt>, <tt><a href="#ref_sin" title="sin()">sin</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_b"></a>B</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_beep">beep</a> - ring the bell within your computer; a synonym for bell</dt><dt><a href="#ref_bell">bell</a> - ring the bell within your computer (just as beep)</dt><dt><a href="#ref_bin">bin$()</a> - converts a number into a sequence of binary digits</dt><dt><a href="#ref_bind">bind()</a> - Binds a yabasic-program and the yabasic-interpreter together into a standalone program.</dt><dt><a href="#ref_box">box</a> - draw a rectancle. A synonym for rectangle</dt><dt><a href="#ref_break">break</a> - breaks out of a switch statement or a loop</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_beep"></a>beep</h1><div class="refnamediv"><h2>Name</h2><p>beep &#8212; ring the bell within your computer; a synonym for <tt>bell</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">beep</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>bell</tt>-command rings the bell within your computer once. This command is <span class="emphasis"><i>not</i></span> a sound-interface, so you can neither vary the length or the height of the sound (technically, it just prints <tt>\a</tt>). <tt>bell</tt> is exactly the same as <tt><a href="#ref_beep" title="beep">beep</a></tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
beep:print &quot;This is a problem ...&quot;
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_beep" title="beep">beep</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_bell"></a>bell</h1><div class="refnamediv"><h2>Name</h2><p>bell &#8212; ring the bell within your computer (just as <tt>beep</tt>)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">bell</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>beep</tt>-command rings the bell within your computer once. <tt>beep</tt> is a synonym for <tt><a href="#ref_bell" title="bell">bell</a></tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;This is a problem ...&quot;:beep
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_bell" title="bell">bell</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_bin"></a>bin$()</h1><div class="refnamediv"><h2>Name</h2><p>bin$() &#8212; converts a number into a sequence of binary digits</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">hexadecimal$=bin$(decimal)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>bin$</tt>-function takes a single numeric argument an converts it into a string of binary digits (i.e. zeroes and ones). If you pass a negative number to <tt>bin$</tt>, the resulting string will be preceeded by a '-'.</p><p>If you want to convert the other way around (i.e. from binary to decimal) you may use the <tt><a href="#ref_dec" title="dec()">dec</a></tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
print bin$(a)
next a
</pre><p>This example prints the binary representation of all digits between 1 and 100.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_hex" title="hex$()">hex$</a></tt>, <tt><a href="#ref_dec" title="dec()">dec</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_bind"></a>bind()</h1><div class="refnamediv"><h2>Name</h2><p>bind() &#8212; Binds a yabasic-program and the yabasic-interpreter together into a <span class="emphasis"><i>standalone</i></span> program.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">bind(&quot;foo.exe&quot;)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>bind</tt>-command combines your own yabasic-program (plus all the libraries it does <tt>import</tt>) and the interpreter by copying them into a new file, whose name is passed as an argument. This new program may then be executed on any computer, even if it does not have yabasic installed.</p><p>Please see the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><i>standalone</i></span>-program</a> for details.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (!peek(&quot;isbound&quot;)) then
bind &quot;foo&quot;
print &quot;Successfully created the standalone executable 'foo' !&quot;
exit
endif
print &quot;Hello World !&quot;
</pre><p>This example creates a standalone program <tt>foo</tt> from itself.</p></div></div><div class="refsect1"><h2>See also</h2><p>The section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><i>standalone</i></span>-program</a>, the <a href="#ref_peek" title="peek"><tt>peek</tt></a>-function and the commandline options for <a href="#unix_options">Unix</a> and <a href="#windows_options">Windows</a>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_box"></a>box</h1><div class="refnamediv"><h2>Name</h2><p>box &#8212; draw a rectancle. A synonym for <tt>rectangle</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
See the <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt>-command.
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>box</tt>-command does exactly the same as the <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt>-command; it is just a <span class="emphasis"><i>synonym</i></span>. Therefore you should refer to the entry for the <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt>-command for further information.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_break"></a>break</h1><div class="refnamediv"><h2>Name</h2><p>break &#8212; breaks out of a switch statement or a loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">break</pre></div><div class="refsect1"><h2>Description</h2><p><tt>break</tt> transfers control immediately outside the enclosing loop or switch statement. This is the preferred way of leaving a such a statement (rather than <tt>goto</tt>, which is still possible in most cases).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
break
print &quot;Hi&quot;
next a
while(1)
break
print &quot;Hi&quot;
wend
repeat
break
print &quot;Hi&quot;
until(0)
switch 1
case 1:break
case 2:case 3:print &quot;Hi&quot;
end switch
</pre><p>This example prints nothing at all, because each of the loops (and the <tt>switch</tt>-statement) does an immediate <tt>break</tt> (before it could print any &quot;Hi&quot;).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_for" title="for">for</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt>, <tt><a href="#ref_repeat" title="repeat">repeat</a></tt> and <tt><a href="#ref_switch" title="switch">switch</a></tt>.</p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_c"></a>C</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_case">case</a> - mark the different cases within a switch-statement</dt><dt><a href="#ref_chr">chr$()</a> - accepts a number and returns the character at this position within the ascii charset</dt><dt><a href="#ref_circle">circle</a> - draws a circle in the graphic-window</dt><dt><a href="#ref_clear">clear</a> - Erase circles or rectangles</dt><dt><a href="#ref_clear_screen">clear screen</a> - erases the text window</dt><dt><a href="#ref_clear_window">clear window</a> - clear the graphic window and begin a new page, if prining is under way</dt><dt><a href="#ref_close">close</a> - close a file, which has been opened before</dt><dt><a href="#ref_close_curve">close curve</a> - close a curve, that has been drawn by the line-command</dt><dt><a href="#ref_close_printer">close printer</a> - stops printing of graphics</dt><dt><a href="#ref_close_window">close window</a> - close the graphics-window</dt><dt><a href="#ref_color">color</a> - print with color</dt><dt><a href="#ref_colour">colour</a> - see color</dt><dt><a href="#ref_compile">compile</a> - compile a string with yabasic-code on the fly</dt><dt><a href="#ref_continue">continue</a> - start the next iteration of a for-, do-, repeat- or while-loop</dt><dt><a href="#ref_cos">cos()</a> - return the cosine of its single argument</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_case"></a>case</h1><div class="refnamediv"><h2>Name</h2><p>case &#8212; mark the different cases within a <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a
case 1
case 2
&#8230;
end switch
&#8230;
switch a$
case &quot;a&quot;
case &quot;b&quot;
&#8230;
end switch
</pre></div><div class="refsect1"><h2>Description</h2><p>Please see the <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input a
switch(a)
case 1:print &quot;one&quot;:break
case 2:print &quot;two&quot;:break
default:print &quot;more&quot;
end switch
</pre><p>Depending on your input (a number is expected) this code will print <tt>one</tt> or <tt>two</tt> or otherwise <tt>more</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_switch" title="switch">switch</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_chr"></a>chr$()</h1><div class="refnamediv"><h2>Name</h2><p>chr$() &#8212; accepts a number and returns the character at this position within the ascii charset</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">character$=chr$(ascii)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>chr$</tt>-function is the opposite of the <tt><a href="#ref_asc" title="asc()">asc</a></tt>-function. It looks up and returns the character at the given position within the ascii-charset. It's typical use is to construct <span class="emphasis"><i>nonprintable</i></span> characters which do not occur on your keyboard.</p><p>Nevertheless you won't use <tt>chr$</tt> as often as you might think, because the most important nonprintable characters can be constructed using <span class="emphasis"><i><a href="#ref_escape_sequences" title="Escape-sequences">escape-sequences</a></i></span> using the \-character (e.g. you might use \n instead of <tt>chr$(10)</tt> wherever you want to use the newline-character).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;a&quot;,chr$(10),&quot;b&quot;
</pre><p>This will print the letters 'a' and 'b' in different lines because of the intervening newline-character, which is returned by <tt>chr$(10)</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_asc" title="asc()">asc</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_circle"></a>circle</h1><div class="refnamediv"><h2>Name</h2><p>circle &#8212; draws a circle in the graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
circle x,y,r
clear circle x,y,r
fill circle x,y,r
clear fill circle x,y,r
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>circle</tt>-command accepts three parameters: The x- and y-coordinates of the center and the radius of the circle.</p><p>Some more observations related with the <tt>circle</tt>-command:</p><div class="itemizedlist"><ul><li><p>The graphic-window must have been opened already.</p></li><li><p>The circle may well extend over the boundaries of the window.</p></li><li><p>If you have issued <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt> before, the circle will finally appear in the printed hardcopy of the window.</p></li><li><p><tt>fill circle</tt> will draw a filled (with black ink) circle.</p></li><li><p><tt>clear circle</tt> will erase (or clear) the outline of the circle.</p></li><li><p><tt>clear fill circle</tt> or <tt>fill clear circle</tt> will erase the full area of the circle.</p></li></ul></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
for n=1 to 2000
x=ran(200)
y=ran(200)
fill circle x,y,10
clear fill circle x,y,8
next n
</pre><p>This code will open a window and draw 2000 overlapping circles within. Each circle is drawn in two steps: First it is filled with black ink (<tt>fill circle x,y,10</tt>), then most of this circle is erased again (<tt>clear fill circle x,y,8</tt>). As a result each circle is drawn with an opaque white interior and a 2-pixel outline (2-pixel, because the radii differ by two).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_window" title="open window">open window</a></tt>, <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt>, <tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_clear"></a>clear</h1><div class="refnamediv"><h2>Name</h2><p>clear &#8212; Erase <tt>circle</tt>s or <tt>rectangle</tt>s</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear rectangle 10,10,90,90
clear fill circle 50,50,20
</pre></div><div class="refsect1"><h2>Description</h2><p>May be used within the <tt><a href="#ref_circle" title="circle">circle</a></tt> or <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt> command and causes these shapes to be erased (i.e. be drawn in the colour of the background).</p><p><tt>fill</tt> can be used in conjunction with and whereever the <tt><a href="#ref_fill" title="fill">fill</a></tt>-clause may appear. Used alone, <tt>clear</tt> will erase the outline (not the interior) of the shape (circle or rectangle); together with <tt>fill</tt> the whole shape (including its interior) is erased.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
</pre><p>This opens a window and draws a pacman-like figure.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_clear" title="clear">clear</a></tt>, <tt><a href="#ref_circle" title="circle">circle</a></tt>, <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_clear_screen"></a>clear screen</h1><div class="refnamediv"><h2>Name</h2><p>clear screen &#8212; erases the text window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>clear screen</tt> erases the text window (the window where the output of <tt>print</tt> appears).</p><p>It must be issued at least once, before some advanced screen-commands (e.g. <tt>print at</tt> or <tt>inkey$</tt>) may be called; this requirement is due to some limititations of the <tt>curses</tt>-library, which is used by yabasic under Unix for some commands.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
print &quot;Please press a key : &quot;;
a$=inkey$
print a$
</pre><p>The <tt>clear screen</tt> command is essential here; if it would be omitted, yabasic would issue an error (&quot;<tt>need to call 'clear screen' first</tt>&quot;) while trying to execute the <tt>inkey$</tt>-function.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_clear_window"></a>clear window</h1><div class="refnamediv"><h2>Name</h2><p>clear window &#8212; clear the graphic window and begin a new page, if prining is under way</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">clear window</pre></div><div class="refsect1"><h2>Description</h2><p><tt>clear window</tt> clears the graphic window. If you have started prining the graphic via <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt>, the <tt>clear window</tt>-command starts a new page as well.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer &quot;t.ps&quot;
for a=1 to 10
if (a&gt;1) clear window
text 100,100,&quot;Hallo &quot;+str$(a)
next a
close printer
close window
</pre><p>This example prints 10 pages, with the text &quot;Hello 1&quot;, &quot;Hello 2&quot;, &#8230; and so on. The <tt>clear screen</tt>-command clears the graphics window and starts a new page.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_window" title="open window">open window</a></tt>, <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_close"></a>close</h1><div class="refnamediv"><h2>Name</h2><p>close &#8212; close a file, which has been opened before</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
close filenum
close # filenum
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>close</tt>-command closes an open file. You should issue this command as soon as you are done with reading from or writing to a file.</p><p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open &quot;my.data&quot; for reading as 1
input #1 a
print a
close 1
</pre><p>This program opens the file <tt>&quot;my.data&quot;</tt>, reads a number from it, prints this number and closes the file again.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open" title="open">open</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_close_curve"></a>close curve</h1><div class="refnamediv"><h2>Name</h2><p>close curve &#8212; close a curve, that has been drawn by the <tt>line</tt>-command</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
new curve
line to x1,y1
&#8230;
close curve
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>close curve</tt>-command closes a sequence of lines, that has been drawn by repeated <tt>line to</tt>-commands.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
new curve
line to 100,50
line to 150,150
line to 50,150
close curve
</pre><p>This example draws a triangle: The three <tt>line to</tt>-commands draw two lines; the final line is however not drawn explicitly, but drawn by the <tt>close curve</tt>-command.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_new_curve" title="new curve">new curve</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_close_printer"></a>close printer</h1><div class="refnamediv"><h2>Name</h2><p>close printer &#8212; stops printing of graphics</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">close printer</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>close printer</tt>-command ends the printing graphics. Between <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt> and <tt>close printer</tt> everything you draw (e.g. circles, lines &#8230;) is sent to your printer. <tt>close printer</tt> puts an end to printing and will make your printer eject the page.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer
circle 100,100,50
close printer
close window
</pre><p>As soon as <tt>close printer</tt> is executed, your printer will eject a page with a circle on it.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_printer" title="open printer">open printer</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_close_window"></a>close window</h1><div class="refnamediv"><h2>Name</h2><p>close window &#8212; close the graphics-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">close window</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>close window</tt>-command closes the graphics-window, i.e. it makes it disappear from your screen. It includes an implicit <tt>close printer</tt>, if a printer has been opened previously.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
circle 100,100,50
close window
</pre><p>This example will open a window, draw a circle and close the window again; all this without any pause or delay, so the window will be closed before you may regard the circle..</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_printer" title="open printer">open window</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_color"></a>color</h1><div class="refnamediv"><h2>Name</h2><p>color &#8212; print with color</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print color(fore$) text$
print color(fore$,back$) text$
</pre></div><div class="refsect1"><h2>Description</h2><p>Not a seperate command, but part of the <tt>print</tt>-command; may be included just after <tt>print</tt> and can only be issued after <tt>clear screen</tt> has been executed.</p><p><tt>color()</tt> takes one or two string-arguments, specifying the color of the text and (optionally) the background.</p><p>The one or two strings passed to <tt>color()</tt> can be one of these: <tt>&quot;black&quot;</tt>, <tt>&quot;white&quot;</tt>, <tt>&quot;red&quot;</tt>, <tt>&quot;blue&quot;</tt>, <tt>&quot;green&quot;</tt>, <tt>&quot;yellow&quot;</tt>, <tt>&quot;cyan&quot;</tt> and <tt>&quot;magenta&quot;</tt> (which can be abbreviated as <tt>&quot;bla&quot;</tt>, <tt>&quot;whi&quot;</tt>, <tt>&quot;red&quot;</tt>, <tt>&quot;blu&quot;</tt>, <tt>&quot;gre&quot;</tt>, <tt>&quot;yel&quot;</tt>, <tt>&quot;cya&quot;</tt> and <tt>&quot;mag&quot;</tt> respectively).</p><p><tt>color()</tt> can only be used, if <tt><a href="#ref_clear_screen" title="clear screen">clear scren</a></tt> has been issued at least once.</p><p>Note, that <tt>color()</tt> can be written as <tt>colour()</tt> too.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
dim col$(7):for a=0 to 7:read col$(a):next a
do
print color(col$(ran(7)),col$(ran(7))) &quot; Hallo &quot;;
pause 0.01
loop
data &quot;black&quot;,&quot;white&quot;,&quot;red&quot;,&quot;blue&quot;
data &quot;green&quot;,&quot;yellow&quot;,&quot;cyan&quot;,&quot;magenta&quot;
</pre><p>This prints the word <tt>&quot; Hallo &quot;</tt> in all colors accross your screen.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt>, <tt><a href="#ref_at" title="at()">at</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_colour"></a>colour</h1><div class="refnamediv"><h2>Name</h2><p>colour &#8212; see <tt><a href="#ref_color" title="color">color</a></tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print colour(fore$) text$
print colour(fore$,back$) text$
</pre></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_color" title="color">color</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_compile"></a>compile</h1><div class="refnamediv"><h2>Name</h2><p>compile &#8212; compile a string with yabasic-code <span class="emphasis"><i>on the fly</i></span></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">compile(code$)</pre></div><div class="refsect1"><h2>Description</h2><p>This is an advanced command (closely related with the <tt><a href="#ref_execute" title="execute()">execute</a></tt>-command). It allows you to compile a string of yabasic-code (which is the only argument). Afterwards the compiled code is a normal part of your program.</p><p>Note, that there is no way to <span class="emphasis"><i>remove</i></span> the compiled code.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
compile(&quot;sub mysub(a):print a:end sub&quot;)
mysub(2)
</pre><p>This example creates a function named <tt>mysub</tt>, which simply prints its single argument.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_execute" title="execute()">execute</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_continue"></a>continue</h1><div class="refnamediv"><h2>Name</h2><p>continue &#8212; start the next iteration of a <tt>for</tt>-, <tt>do</tt>-, <tt>repeat</tt>- or <tt>while</tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">continue</pre></div><div class="refsect1"><h2>Description</h2><p>You may use <tt>continue</tt> within any loop to start the next iteration immediately. Depending on the type of the loop, the loop-condition will or will not be checked. Especially: <tt>for</tt>- and <tt>while</tt>-loops will evaluate their respective conditions, <tt>do</tt>- and <tt>repeat</tt>-loops will not.</p><i>Remark: Another way to change the flow of execution within a loop, is the <tt>break</tt>-command.</i></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
if mod(a,2)=0 continue
print a
next a
</pre><p>This example will print all odd numbers between 1 and 100.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_for" title="for">for</a></tt>, <tt><a href="#ref_do" title="do">do</a></tt>, <tt><a href="#ref_repeat" title="repeat">repeat</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt>, <tt><a href="#ref_break" title="break">break</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_cos"></a>cos()</h1><div class="refnamediv"><h2>Name</h2><p>cos() &#8212; return the cosine of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=cos(angle)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>cos</tt>-function expects an angle (in radian) and returns its cosine.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print cos(pi)
</pre><p>This example will print <tt>-1</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_acos" title="acos()">acos</a></tt>, <tt><a href="#ref_sin" title="sin()">sin</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_d"></a>D</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_data">data</a> - introduces a list of data-items</dt><dt><a href="#ref_date">date$</a> - returns a string with various components of the current date</dt><dt><a href="#ref_dec">dec()</a> - convert a base 2 or base 16 number into decimal form</dt><dt><a href="#ref_default">default</a> - mark the default-branch within a switch-statement</dt><dt><a href="#ref_dim">dim</a> - create an array prior to its first use</dt><dt><a href="#ref_do">do</a> - start a (conditionless) do-loop</dt><dt><a href="#ref_doc">doc</a> - special comment, which might be retrieved by the program itself</dt><dt><a href="#ref_docu">docu$</a> - special array, containing the contents of all docu-statement within the program</dt><dt><a href="#ref_dot">dot</a> - draw a dot in the graphic-window</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_data"></a>data</h1><div class="refnamediv"><h2>Name</h2><p>data &#8212; introduces a list of data-items</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
data 9,&quot;world&quot;
&#8230;
read b,a$
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>data</tt>-keyword introduces a list of comma-seperated list of strings or numbers, which may be retrieved with the <tt><a href="#ref_read" title="read">read</a></tt>-command.</p><p>The <tt>data</tt>-command itself does nothing; it just stores data. A single <tt>data</tt>-command may precede an arbitrarily long list of values, in which strings or numbers may be mixed at will.</p><p>yabasic internally uses a <tt>data-pointer</tt> to keep track of the current location within the <tt>data</tt>-list; this pointer may be reset with the <tt><a href="#ref_restore" title="restore">restore</a></tt>-command.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
restore
for a=1 to 4
read num$,num
print num$,&quot;=&quot;,num
next a
loop
data &quot;eleven&quot;,11,&quot;twelve&quot;,12,&quot;thirteen&quot;,13,&quot;fourteen&quot;,14
</pre><p>This example just prints a series of lines <tt>eleven=11</tt> up to <tt>fourteen=14</tt> and so on without end.</p><p>The <tt>restore</tt>-command ensures that the list of <tt>data</tt>-items is read from the start with every iteration.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_read" title="read">read</a></tt>, <tt><a href="#ref_restore" title="restore">restore</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_date"></a>date$</h1><div class="refnamediv"><h2>Name</h2><p>date$ &#8212; returns a string with various components of the current date</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a$=date$</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>date$</tt>-function (which <span class="emphasis"><i>must</i></span> be called without parantheses; i.e. <tt>date$()</tt> would be an error) returns a string containing various components of a date; an example would be <tt>4-05-27-2004-Thu-May</tt>. This string consists of various fields seperated by hyphens (&quot;<tt>-</tt>&quot;):</p><div class="itemizedlist"><ul><li><p>The day within the week as a number in the range 0 (=sunday) to 6 (=saturday) (in the example above: <tt>4</tt>, i.e. thursday).</p></li><li><p>The month as a number in the range 1 (=january) to 12 (=december) (in the example: <tt>5</tt> which stands for may).</p></li><li><p>The day within the month as a number in the range 1 to 31 (in the example: <tt>27</tt>).</p></li><li><p>The full, 4-digit year (in the example: <tt>2004</tt>, which reminds me that I should adjust the clock within my computer &#8230;).</p></li><li><p>The abbreviated name of the day within the week (<tt>Mon</tt> to <tt>Sun</tt>).</p></li><li><p>The abbreviated name of the month (<tt>Jan</tt> to <tt>Dec</tt>).</p></li></ul></div><p>Therefore the whole example above (<tt>4-05-27-2004-Thu-May</tt>) would read: day 4 in the week (counting from 0), May 27 in the year 2004, which is a thursday in May.</p><p>Note, that all fields within the string returned by <tt>date$</tt> have a fixed with (numbers are padded with zeroes); therefore it is easy to extract the various fields of a date format with <tt>mid$</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
rem Two ways to print the same ...
print mid$(date$,3,10)
dim fields$(6)
a=split(date$,fields$(),&quot;-&quot;)
print fields$(2),&quot;-&quot;,fields$(3),&quot;-&quot;,fields$(4)
</pre><p>This example shows two different techniques to extract components from the value returned by <tt>date$</tt>. The <tt>mid$</tt>-function is the preferred way, but you could just as well <tt>split</tt> the return-value of <tt>date$</tt> at every &quot;-&quot; and store the result within an array of strings.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_time" title="time$">time$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_dec"></a>dec()</h1><div class="refnamediv"><h2>Name</h2><p>dec() &#8212; convert a base 2 or base 16 number into decimal form</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=dec(number$)
a=dec(number$,base)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>dec</tt>-function takes the string-representation of a base-2 or base-16 (which is the default) number and converts it into a decimal number. The optional second argument (<tt>base</tt>) might be used to specify a base other than 16. However, currently only base 2 or base 16 are supported.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a binary number: &quot; a$
print a$,&quot; is &quot;,dec(a$)
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_bin" title="bin$()"><tt>bin$</tt></a>, <a href="#ref_hex" title="hex$()"><tt>hex$</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_default"></a>default</h1><div class="refnamediv"><h2>Name</h2><p>default &#8212; mark the <span class="emphasis"><i>default</i></span>-branch within a <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a+3
case 1
&#8230;
case 2
&#8230;
default
&#8230;
end switch
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>default</tt>-clause is an optional part of the <tt><a href="#ref_switch" title="switch">switch</a></tt>-statement (see there for more information). It introduces a series of statements, that should be executed, if none of the casese matches, that have been specified before (each with its own <tt><a href="#ref_case" title="case">case</a></tt>-clause).</p><p>So <tt>default</tt> specifies a default to be executed, if none of the explicitly named cases matches; hence its name.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Please enter a number between 0 and 6,&quot;
print &quot;specifying a day in the week.&quot;
input d
switch d
case 0:print &quot;Monday&quot;:break
case 1:print &quot;Tuesday&quot;:break
case 2:print &quot;Wednesday&quot;:break
case 3:print &quot;Thursday&quot;:break
case 4:print &quot;Friday&quot;:break
case 5:print &quot;Saturday&quot;:break
case 6:print &quot;Sunday&quot;:break
default:print &quot;Hey you entered something invalid !&quot;
end switch
</pre><p>This program translates a number between 0 and 6 into the name of a weekday; the <tt>default</tt>-case is used to detect (and complain about) invalid input.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_sub" title="sub"><tt>sub</tt></a>, <a href="#ref_case" title="case"><tt>case</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_dim"></a>dim</h1><div class="refnamediv"><h2>Name</h2><p>dim &#8212; create an array prior to its first use</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim array(x,y)
dim array$(x,y)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>dim</tt>-command prepares one or more arrays (of either strings or numbers) for later use. This command can also be used to enlarges an existing array.</p><p>When an array is created with the <tt>dim</tt>-statement, memory is allocated and all elements are initialized with either 0 (for numerical arrays) or &quot;&quot; (for string arrays).</p><p>If the array already existed, and the <tt>dim</tt>-statement specifies a larger size than the current size, the array is enlarged and any old content is preserved.</p><p>Note, that <tt>dim</tt> cannot be used to shrink an array: If you specify a size, that is smaller than the current size, the <tt>dim</tt>-command does nothing.</p><p>Finally: To create an array, that is only known within a single subroutine, you should use the command <tt><a href="#ref_local" title="local">local</a></tt>, which creates local variables as well as local arrays.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim a(5,5)
for x=1 to 5:for y=1 to 5
a(x,y)=int(ran(100))
next y:next x
printmatrix(a())
dim a(7,7)
printmatrix(a())
sub printmatrix(ar())
local x,y,p,q
x=arraysize(ar(),1)
y=arraysize(ar(),2)
for q=1 to y
for p=1 to y
print ar(p,q),&quot;\t&quot;;
next p
print
next q
end sub
</pre><p>This example creates a 2-dimenional array (i.e. a <span class="emphasis"><i>matrix</i></span>) with the <tt>dim</tt>-statement and fills it with random numbers. The second <tt>dim</tt>-statement enlarges the array, all new elements are filled with 0.</p><p>The subroutine <tt>printmatrix</tt> just does, what its name says.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><tt>arraysize</tt></a>, <a href="#ref_arraydim" title="arraydim()"><tt>arraydim</tt></a>, <tt><a href="#ref_local" title="local">local</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_do"></a>do</h1><div class="refnamediv"><h2>Name</h2><p>do &#8212; start a (conditionless) <tt>do-loop</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
do
&#8230;
loop</pre></div><div class="refsect1"><h2>Description</h2><p>Starts a loop, which is terminated by <tt>loop</tt>; everything between <tt>do</tt> and <tt>loop</tt> will be repeated forever. This loop has no condition, so it is an infinite loop; note however, that a <tt><a href="#ref_break" title="break">break</a></tt>- or <tt><a href="#ref_goto" title="goto">goto</a></tt>-statement might be used to leave this loop anytime.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
a=a+1
print a
if (a&gt;100) break
loop
</pre><p>This example prints the numbers between 1 and 101. The <tt>break</tt>-statement is used to leave the loop.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_loop" title="loop"><tt>loop</tt></a>, <a href="#ref_repeat" title="repeat"><tt>repeat</tt></a>, <a href="#ref_while" title="while"><tt>while</tt></a>, <a href="#ref_break" title="break"><tt>break</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_doc"></a>doc</h1><div class="refnamediv"><h2>Name</h2><p>doc &#8212; special comment, which might be retrieved by the program itself</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
doc This is a comment
docu This is another comment
</pre></div><div class="refsect1"><h2>Description</h2><p>Introduces a comment, which spans up to the end of the line. But other than the <a href="#ref_rem" title="rem"><tt>rem</tt></a>-comment, any <tt>docu</tt>-comment is collected within the special <tt><a href="#ref_docu" title="docu$">docu$</a></tt>-array and might be retrieved later on. Moreover you might invoke yabasic -docu foo.yab on the <span class="emphasis"><i>commandline</i></span> to retrieve the embedded documentation within the program <tt>foo.yab</tt>.</p><p>Instead of <tt>doc</tt> you may just as well write <tt>docu</tt> or even <tt>documentation</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
rem Hi, this has been written by me
rem
doc This program asks for a number and
doc prints this number multiplied with 2
rem
rem Print out rhe above message
for a=1 to arraysize(docu$()):print docu$(a):next a
rem Read and print the number
input &quot;Please input a number: &quot; x
print x*2
</pre><p>This program uses the comments within its code to print out a help message for the user.</p><p>The contents of the <tt>doc</tt>-lines are retrieved from the <tt>docu$</tt>-array; if you do not want a comment to be collected within this array, use the <tt>rem</tt>-statement instead.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_docu" title="docu$"><tt>docu$</tt></a>, <a href="#ref_rem" title="rem"><tt>rem</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_docu"></a>docu$</h1><div class="refnamediv"><h2>Name</h2><p>docu$ &#8212; special array, containing the contents of all docu-statement within the program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a$=docu$(1)</pre></div><div class="refsect1"><h2>Description</h2><p>Before your program is executed, yabasic collects the content of all the <tt>doc</tt>-statements within your program within this 1-dimensional array (well only those within the main-program, libraries are skipped).</p><p>You may use the <tt>arraysize</tt> function to find out, how many lines it contains.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
docu
docu This program reads two numbers
docu and adds them.
docu
rem retrieve and print the embedded documentation
for a=1 to arraysize(docu$(),1)
print docu$(a)
next a
input &quot;First number: &quot; b
input &quot;Second number: &quot; c
print &quot;The sum of &quot;,b,&quot; and &quot;,c,&quot; is &quot;,b+c
</pre><p>This program uses the embedded documentation to issue a usage-message.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><tt>arraydim</tt></a>, <a href="#ref_rem" title="rem"><tt>rem</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_dot"></a>dot</h1><div class="refnamediv"><h2>Name</h2><p>dot &#8212; draw a dot in the graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dot x,y
clear dot x,y
</pre></div><div class="refsect1"><h2>Description</h2><p>Draws a dot at the specified coordinates within your graphic-window. If <a href="#ref_open_printer" title="open printer">printing</a> is in effect, the dot appears on your printout too.</p><p>Use the functions <a href="#ref_peek" title="peek"><tt>peek(&quot;winheight&quot;)</tt></a> or <a href="#ref_peek" title="peek"><tt>peek(&quot;winwidth&quot;)</tt></a> to get the size of your window and hence the boundaries of the coordinates specified for the <tt>dot</tt>-command.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
circle 100,100,100
do
x=ran(200):y=ran(200)
dot x,y
total=total+1
if (sqrt((x-100)^2+(y-100)^2)&lt;100) in=in+1
print 4*in/total
loop
</pre><p>This program uses a well known algorithm to compute &#960;.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_line" title="line"><tt>line</tt></a>, <a href="#ref_open_window" title="open window"><tt>open window</tt></a></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_e"></a>E</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_else">else</a> - mark an alternative within an if-statement</dt><dt><a href="#ref_elsif">elsif</a> - starts an alternate condition within an if-statement</dt><dt><a href="#ref_end">end</a> - terminate your program</dt><dt><a href="#ref_endif">endif</a> - ends an if-statement</dt><dt><a href="#ref_end_sub">end sub</a> - ends a subroutine definition</dt><dt><a href="#ref_eof">eof</a> - check, if an open file contains data</dt><dt><a href="#ref_eor">eor()</a> - compute the bitwise exclusive or of its two arguments</dt><dt><a href="#ref_error">error</a> - raise an error and terminate your program</dt><dt><a href="#ref_euler">euler</a> - another name for the constant 2.71828182864</dt><dt><a href="#ref_execute2">execute$()</a> - execute a user defined subroutine, which must return a string</dt><dt><a href="#ref_execute">execute()</a> - execute a user defined subroutine, which must return a number</dt><dt><a href="#ref_exit">exit</a> - terminate your program</dt><dt><a href="#ref_exp">exp()</a> - compute the exponential function of its single argument</dt><dt><a href="#ref_export">export</a> - mark a function as globally visible</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_else"></a>else</h1><div class="refnamediv"><h2>Name</h2><p>else &#8212; mark an alternative within an <tt>if</tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (&#8230;) then
&#8230;
else
&#8230;
endif
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>else</tt>-statement introduces the alternate branch of an <tt>if</tt>-statement. I.e. it starts the sequence of statements, which is executed, if the condition of the <tt>if</tt>-statement is <span class="emphasis"><i>not</i></span> true.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number: &quot; a
if (mod(a,2)=1) then
print a,&quot; is odd.&quot;
else
print a,&quot; is even.&quot;
endif
</pre><p>This program detects, if the number you have entered is even or odd.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_if" title="if"><tt>if</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_elsif"></a>elsif</h1><div class="refnamediv"><h2>Name</h2><p>elsif &#8212; starts an alternate condition within an <tt>if</tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (&#8230;) then
&#8230;
elseif (&#8230;)
&#8230;
elsif (&#8230;) then
&#8230;
else
&#8230;
endif
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>elsif</tt>-statement is used to select a single alternative among a series of choices.</p><p>With each <tt>elsif</tt>-statement you may specify a condition, which is tested, if the main condition (specified with the <tt>if</tt>-statement) has failed. Note that <tt>elsif</tt> might be just as well written as <tt>elseif</tt>.</p><p>Within the example below, two variables <tt>a</tt> and <tt>b</tt> are tested against a range of values. The variable <tt>a</tt> is tested with the <tt>elsif</tt>-statement. The very same tests are performed for the variable <tt>b</tt> too; but here an involved series of <tt>if</tt>-<tt>else</tt>-statements is employed, making the tests much more obscure.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number: &quot; a
if (a&lt;0) then
print &quot;less than 0&quot;
elseif (a&lt;=10) then
print &quot;between 0 and 10&quot;
elsif (a&lt;=20)
print &quot;between 11 and 20&quot;
else
print &quot;over 20&quot;
endif
input &quot;Please enter another number: &quot; b
if (b&lt;0) then
print &quot;less than 0&quot;
else
if (b&lt;=10) then
print &quot;between 0 and 10&quot;
else
if (b&lt;=20) then
print &quot;between 11 and 20&quot;
else
print &quot;over 20&quot;
endif
endif
endif
</pre><p>Note, that the very same tests are performed for the variables <tt>a</tt> and <tt>b</tt>, but can be stated much more clearly with the <tt>elsif</tt>-statement.</p><p>Note, that <tt>elsif</tt> might be written as <tt>elseif</tt> too, and that the keyword <tt>then</tt> is optional.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_if" title="if"><tt>if</tt></a>, <a href="#ref_else" title="else"><tt>else</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_end"></a>end</h1><div class="refnamediv"><h2>Name</h2><p>end &#8212; terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
end
</pre></div><div class="refsect1"><h2>Description</h2><p>Terminate your program. Much (but not exactly) like the <tt><a href="#ref_exit" title="exit">exit</a></tt> command.</p><p>Note, that <tt>end</tt> may not end your program immediately; if you have opened a window or called <tt>clear screen</tt>, yabasic assumes, that your user wants to study the output of your program after it has ended; therfore it issues the line <tt>---Program done, press RETURN---</tt> and waits for a key to be pressed. If you do not like this behaviour, consider using <tt><a href="#ref_exit" title="exit">exit</a></tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Do you want to continue ?&quot;
input &quot;Please answer y(es) or n(o): &quot; a$
if (lower$(left$(a$,1))=&quot;n&quot;) then
print &quot;bye&quot;
end
fi
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_exit" title="exit">exit</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_endif"></a>endif</h1><div class="refnamediv"><h2>Name</h2><p>endif &#8212; ends an <tt>if</tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (&#8230;) then
&#8230;
endif
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>endif</tt>-statement closes (or ends) an <tt>if</tt>-statement.</p><p>Note, that <tt>endif</tt> may be written in a variety of other ways: <tt>end if</tt>, <tt>end-if</tt> or even <tt>fi</tt>.</p><p>The <tt>endif</tt>-statement must be omitted, if the <tt>if</tt>-statement does not contain the keyword <tt>then</tt> (see the example below). Such an <a href="#ref_if" title="if"><tt>if</tt></a>-statement without <tt>endif</tt> extends only over a single line.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;A number please: &quot; a
if (a&lt;10) then
print &quot;Your number is less than 10.&quot;
endif
REM and now without endif
input &quot;A number please: &quot; a
if (a&lt;10) print &quot;Your number is less than 10.&quot;
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_if" title="if"><tt>if</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_end_sub"></a>end sub</h1><div class="refnamediv"><h2>Name</h2><p>end sub &#8212; ends a subroutine definition</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo(&#8230;)
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>Marks the end of a subroutine-definition (which starts with the <tt>sub</tt>-keyword).
The whole concept of subroutines is explained within the entry for <a href="#ref_sub" title="sub"><tt>sub</tt></a>.
</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print foo(3)
sub foo(a)
return a*2
end sub
</pre><p>This program prints out <tt>6</tt>. The subroutine <tt>foo</tt> simply returns twice its argument.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_sub" title="sub"><tt>sub</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_eof"></a>eof</h1><div class="refnamediv"><h2>Name</h2><p>eof &#8212; check, if an open file contains data</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open 1,&quot;foo.bar&quot;
if (eof(1)) then
&#8230;
end if
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>eof</tt>-function checks, if there is still data left within an open file. As an argument it expects the file-number as returned by (or used within) the <tt>open</tt>-function (or statement).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a=open(&quot;foo.bar&quot;)
while(not eof(a))
input #a,a$
print a$
end while
</pre><p>This example will print the contents of the file &quot;foo.bar&quot;. The <tt>eof</tt>-function will terminate the loop, if there is no more data left within the file. </p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_open" title="open"><tt>open</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_eor"></a>eor()</h1><div class="refnamediv"><h2>Name</h2><p>eor() &#8212; compute the bitwise <span class="emphasis"><i>exclusive or</i></span> of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print eor(a,b)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>eor</tt>-function takes two arguments and computes their bitwise <span class="emphasis"><i>exclusive or</i></span>. See your favorite introductory text on informatics for an explanation of this function.</p><p>The <tt>xor</tt>-function is the same as the <tt>eor</tt> function; both are synonymous; however they have each their own description, so you may check out the entry of <tt><a href="#ref_xor" title="xor()">xor</a></tt> for a slightly different view.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 3
for b=0 to 3
print fill$(bin$(a)),&quot; eor &quot;,fill$(bin$(b)),&quot; = &quot;,fill$(bin$(eor(a,b)))
next b
next a
sub fill$(a$)
return right$(&quot;0&quot;+a$,2)
end sub
</pre><p>This example prints a table, from which you may figure, how the <tt>eor</tt>-function is computed.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arithmetic_and" title="and()"><tt>and</tt></a>, <a href="#ref_arithmetic_or" title="or()"><tt>or</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_error"></a>error</h1><div class="refnamediv"><h2>Name</h2><p>error &#8212; raise an error and terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">error &quot;Wrong, wrong, wrong !!&quot;</pre></div><div class="refsect1"><h2>Description</h2><p>Produces the same kind or error messages, that yabasic itself produces (e.g. in case of a syntax-error). The single argument is issued along with the current line-number.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number between 1 and 10: &quot; a
if (a&lt;1 or a&gt;10) error &quot;Oh no ...&quot;
</pre><p>This program is very harsh in checking the users input; instead of just asking again, the program terminates with an error, if the user enters something wrong.</p><p>The error message would look like this:</p><pre class="programlisting">
---Error in t.yab, line 2: Oh no ...
---Error: Program stopped due to an error
</pre></div></div><div class="refsect1"><h2>See also</h2><p>Well, there <span class="emphasis"><i>should</i></span> be a corresponding called <tt>warning</tt>; unfortunately ther is none yet.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_euler"></a>euler</h1><div class="refnamediv"><h2>Name</h2><p>euler &#8212; another name for the constant <tt>2.71828182864</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">foo=euler</pre></div><div class="refsect1"><h2>Description</h2><p><tt>euler</tt> is the well known constant named after <span class="emphasis"><i>Leonard Euler</i></span>; its value is <tt>2.71828182864</tt>. <tt>euler</tt> is <span class="emphasis"><i>not</i></span> a function, so parens are not allowed (i.e. <tt>euler()</tt> will produce an error). Finally, you may not assign to <tt>euler</tt>; it wouldn't sense anyway, because it is a constant.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print euler
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_pi" title="pi">pi</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_execute2"></a>execute$()</h1><div class="refnamediv"><h2>Name</h2><p>execute$() &#8212; execute a user defined subroutine, which must return a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print execute$(&quot;foo$&quot;,&quot;arg1&quot;,&quot;arg2&quot;)</pre></div><div class="refsect1"><h2>Description</h2><p><tt>execute$</tt> can be used to execute a user defined subroutine, whose name may be specified as a string expression.</p><p>This feature is the only way to execute a subroutine, whose name is not known by the time you write your program. This might happen, if you want to execute a subroutine, which is compiled (using the <tt><a href="#ref_compile" title="compile">compile</a></tt> command) during the course of execution of your program.</p><p>Note however, that the <tt>execute$</tt>-function is <span class="emphasis"><i>not</i></span> the preferred method to execute a user defined subroutine; almost all cases you should just execute a subroutine by writing down its name within your yabasic program (see the example).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print execute$(&quot;foo$&quot;,&quot;Hello&quot;,&quot;world !&quot;)
sub foo$(a$,b$)
return a$+&quot; &quot;+b$
end sub
</pre><p>The example simply prints <tt>Hello world !</tt>, which is the return value of the user defined subroutine <tt>foo$</tt>. The same could be achieved by executing:</p><pre class="programlisting">
print foo$(a$,b$)
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_compile" title="compile">compile</a></tt>, <tt><a href="#ref_execute" title="execute()">execute</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_execute"></a>execute()</h1><div class="refnamediv"><h2>Name</h2><p>execute() &#8212; execute a user defined subroutine, which must return a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print execute(&quot;bar&quot;,&quot;arg1&quot;,&quot;arg2&quot;)</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>execute</tt>-function is the counterpart of the <tt><a href="#ref_execute2" title="execute$()">execute$</a></tt>-function (please see there for some caveats). <tt>execute</tt> executes subroutines, which returns a number.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print execute(&quot;bar&quot;,2,3)
sub bar(a,b)
return a+b
end sub
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_compile" title="compile">compile</a></tt>, <tt><a href="#ref_execute2" title="execute$()">execute$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_exit"></a>exit</h1><div class="refnamediv"><h2>Name</h2><p>exit &#8212; terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
exit
exit 1
</pre></div><div class="refsect1"><h2>Description</h2><p>Terminate your program and return any given value to the operating system. <tt>exit</tt> is similar to <tt><a href="#ref_end" title="end">end</a></tt>, but it will terminate your program immediately, no matter what.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Do you want to continue ?&quot;
input &quot;Please answer y(es) or n(o): &quot; a$
if (lower$(left$(a$,1))=&quot;n&quot;) exit 1
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_end" title="end">end</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_exp"></a>exp()</h1><div class="refnamediv"><h2>Name</h2><p>exp() &#8212; compute the exponential function of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo=exp(bar)
</pre></div><div class="refsect1"><h2>Description</h2><p>This function computes <span class="emphasis"><i>e</i></span> to the power of its argument, where <span class="emphasis"><i>e</i></span> is the well known euler constant <tt>2.71828182864</tt>.</p><p>The <tt>exp</tt>-function is the inverse of the <tt>log</tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 100,100
for x=0 to 100
dot x,100-100*exp(x/100)/euler
next x
</pre><p>This program plots part of the <tt>exp</tt>-function, however the range is rather small, so that you may not recognize the function from this plot.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_log" title="log()">log</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_export"></a>export</h1><div class="refnamediv"><h2>Name</h2><p>export &#8212; mark a function as globally visible</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
export sub foo(bar)
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>export</tt>-statement is used within libraries to mark a user defined subroutine as visible outside the library wherein it is defined. Subroutines, which are not exported, must be qualified with the name of the library, e.g. <tt>foo.baz</tt> (where <tt>foo</tt> is the name of the library and <tt>baz</tt> the name of the subroutine); <span class="emphasis"><i>exported</i></span> subroutines may be used without specifying the name of the library, e.g. <tt>bar</tt>.</p><p>Therefore <tt>export</tt> may only be useful within libraries.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><p>The library <tt>foo.bar</tt> (which is listed below) defines two functions <tt>bar</tt> and <tt>baz</tt>, however only the function <tt>bar</tt> is <span class="emphasis"><i>exported</i></span> and therefore visible even outside the library; <tt>baz</tt> is <span class="emphasis"><i>not</i></span> exported and may only be used within the library <tt>foo.yab</tt>:</p><pre class="programlisting">
export sub bar()
print &quot;Hello&quot;
end sub
sub baz()
print &quot;World&quot;
end sub
</pre><p>Now within your main program <tt>cux.yab</tt> (which <tt><a href="#ref_import" title="import">import</a></tt>s the library foo.yab); note that this program produces an error:</p><pre class="programlisting">
import foo
print &quot;Calling subroutine foo.bar (okay) ...&quot;
foo.bar()
print &quot;done.&quot;
print &quot;Calling subroutine bar (okay) ...&quot;
bar()
print &quot;done.&quot;
print &quot;Calling subroutine foo.baz (okay) ...&quot;
foo.baz()
print &quot;done.&quot;
print &quot;Calling subroutine baz (NOT okay) ...&quot;
baz()
print &quot;done.&quot;
</pre><p>The output when executing <b>yabasic foo.yab</b> is this:</p><pre class="programlisting">
Calling subroutine foo.bar (okay) ...
Hello
done.
Calling subroutine bar (okay) ...
Hello
done.
Calling subroutine foo.baz (okay) ...
World
done.
Calling subroutine baz (NOT okay) ...
---Error in main.yab, line 16: can't find subroutine 'baz'
---Dump: sub baz() called in main.yab,16
---Error: Program stopped due to an error
</pre><p>As the error message above shows, the subroutine <tt>baz</tt> must be qualified with the name of the library, if used outside the library, wherein it is defined (e.g. <tt>foo.baz</tt>. I.e. outside the library <tt>foo.yab</tt> you need to write <tt>foo.baz</tt>. <tt>baz</tt> alone would be an error.</p><p>The subroutine <tt>bar</tt> (without adding the name of the library) however may (and probably should) be used in any program, which imports the library <tt>foo.yab</tt>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>In some sense the set of exported subroutines constitutes the <span class="emphasis"><i>interface</i></span> of a library.</p></div></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sub" title="sub">sub</a></tt>, <tt><a href="#ref_import" title="import">import</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_f"></a>F</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_false">false</a> - a constant with the value of 0</dt><dt><a href="#ref_fi">fi</a> - another name for endif</dt><dt><a href="#ref_fill">fill</a> - draw a filled circles or rectangles</dt><dt><a href="#ref_for">for</a> - starts a for-loop</dt><dt><a href="#ref_frac">frac()</a> - return the fractional part of its numeric argument</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_false"></a>false</h1><div class="refnamediv"><h2>Name</h2><p>false &#8212; a constant with the value of 0</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
okay=false
</pre></div><div class="refsect1"><h2>Description</h2><p>The constant <tt>false</tt> can be assigned to variables which later appear in conditions (e.g. within an <tt>if</tt>-statement.</p><p><tt>false</tt> may also be written as <tt>FALSE</tt> or even <tt>FaLsE</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number between 1 and 10: &quot; a
if (check_input(a)) print &quot;Okay&quot;
sub check_input(x)
if (x&gt;10 or x&lt;1) return false
return true
end sub
</pre><p>The subroutine <tt>check_input</tt> checks its argument and returns <tt>true</tt> or <tt>false</tt> according to the outcome of the check..</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_true" title="true">true</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_fi"></a>fi</h1><div class="refnamediv"><h2>Name</h2><p>fi &#8212; another name for <tt><a href="#ref_endif" title="endif">endif</a></tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (&#8230;)
&#8230;
fi
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>fi</tt> marks the end of an <tt>if</tt>-statement and is exactly equivilent to <tt><a href="#ref_endif" title="endif">endif</a></tt>, please see there for further information.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;A number please: &quot; a
if (a&lt;10) then
print &quot;Your number is less than 10.&quot;
fi
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_endif" title="endif">endif</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_fill"></a>fill</h1><div class="refnamediv"><h2>Name</h2><p>fill &#8212; draw a filled <tt>circle</tt>s or <tt>rectangle</tt>s</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
fill rectangle 10,10,90,90
fill circle 50,50,20
</pre></div><div class="refsect1"><h2>Description</h2><p>The keyword <tt>fill</tt> may be used within the <tt><a href="#ref_circle" title="circle">circle</a></tt> or <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt> command and causes these shapes to be filled.</p><p><tt>fill</tt> can be used in conjunction with and whereever the <tt><a href="#ref_clear" title="clear">clear</a></tt>-clause may appear. Used alone, <tt>fill</tt> will fill the interior of the shape (circle or rectangle); together with <tt>clear</tt> the whole shape (including its interior) is erased.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
</pre><p>This opens a window and draws a pacman-like figure.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_clear" title="clear">clear</a></tt>, <tt><a href="#ref_circle" title="circle">circle</a></tt>, <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_for"></a>for</h1><div class="refnamediv"><h2>Name</h2><p>for &#8212; starts a <tt>for</tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 100 step 2
&#8230;
next a
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>for</tt>-loop lets its numerical variable (<tt>a</tt> in the synopsis) assume all values within the given range. The optional <tt>step</tt>-clause may specify a value (default: 1) by which the variable will be incremented (or decremented, if <tt>step</tt> is negative).</p><p>Any <tt>for</tt>-statement can be replaced by a set of <tt>if</tt>s and <tt>goto</tt>s; as you may infer from the example below this is normally not feasable. However if you want to know in detail how the <tt>for</tt>-statement works, you should study this example, which presents a <tt>for</tt>-statement and an <span class="emphasis"><i>exactly equivilant</i></span> series of <tt>if</tt>s and <tt>goto</tt>s.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10 step 2:print a:next
a=1
label check
if (a&gt;10) goto done
print a
a=a+2
goto check
label done
</pre><p>This example simply prints the numbers 1, 3, 5, 7 and 9. It does this twice: First with a simple <tt>for</tt>-statment and then with <tt>if</tt>s and <tt>goto</tt>s.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_step" title="step">step</a></tt>, <tt><a href="#ref_next" title="next">next</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_frac"></a>frac()</h1><div class="refnamediv"><h2>Name</h2><p>frac() &#8212; return the fractional part of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=frac(y)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>frac</tt>-function takes its argument, removes all the digits to the left of the comma and just returns the digits right of the comma, i.e. the fractional part.</p><p>Refer to the example to learn how to rewrite <tt>frac</tt> by employing the <tt>int</tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
print frac(sqr(a))
print sqr(a)-int(sqr(a))
next a
</pre><p>The example prints the fractional part of the square root of the numbers between 1 and 10. Each result is computed (and printed) twice: Once by employing the <tt>frac</tt>-function and once by employing the <tt><a href="#ref_int" title="int()">int</a></tt>-function.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_int" title="int()">int</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_g"></a>G</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_getbit">getbit$()</a> - return a string representing the bit pattern of a rectangle within the graphic window</dt><dt><a href="#ref_getscreen">getscreen$()</a> - returns a string representing a rectangular section of the text terminal</dt><dt><a href="#ref_glob">glob()</a> - check if a string matches a simple pattern</dt><dt><a href="#ref_gosub">gosub</a> - continue execution at another point within your program (and return later)</dt><dt><a href="#ref_goto">goto</a> - continue execution at another point within your program (and never come back)</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_getbit"></a>getbit$()</h1><div class="refnamediv"><h2>Name</h2><p>getbit$() &#8212; return a string representing the bit pattern of a rectangle within the graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=getbit$(10,10,20,20)
a$=getbit$(10,10 to 20,20)
</pre></div><div class="refsect1"><h2>Description</h2><p>The function <tt>getbit</tt> returns a string, which contains the encoded bit-pattern of a rectangle within graphic window; the four arguments represent the borders of the rectangle. The string returned might later be fed to the <tt><a href="#ref_putbit" title="putbit">putbit</a></tt>-command. </p><p>The <tt>getbit$</tt>-function might be used for simple animations (as in the example below).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 40,40
fill circle 20,20,18
circle$=getbit$(0,0,40,40)
close window
open window 200,200
for x=1 to 200
putbit circle$,x,80
next x
</pre><p>This example features a circle moving from left to right over the window.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_putbit" title="putbit">putbit</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_getscreen"></a>getscreen$()</h1><div class="refnamediv"><h2>Name</h2><p>getscreen$() &#8212; returns a string representing a rectangular section of the text terminal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=getscreen$(2,2,20,20)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>getscreen$</tt> function returns a string representing the area of the screen as specified by its four arguments (which specify two corners). I.e. everything you have printed within this rectangle will be encoded in the string returned (including any colour-information).</p><p>Like most other commands dealing with advanced text output, <tt>getscreen$</tt> requires, that you have called <tt>clear screen</tt> before.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
for a=1 to 1000:
print color(&quot;red&quot;) &quot;1&quot;;
print color(&quot;green&quot;) &quot;2&quot;;
print color(&quot;blue&quot;) &quot;3&quot;;
next a
screen$=getscreen$(10,10,40,10)
print at(10,10) &quot; Please Press 'y' or 'n' ! &quot;
a$=inkey$
putscreen screen$,10,10
</pre><p>This program fills the screen with coloured digits and afterwards asks the user for a choice (<tt> Please press 'y' or 'n' ! </tt>). Afterwards the area of the screen, which has been overwritten by the question will be restored with its previous contents, whhch had been saved via <tt>getscreen$</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt>putscreen$</tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_glob"></a>glob()</h1><div class="refnamediv"><h2>Name</h2><p>glob() &#8212; check if a string matches a simple pattern</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (glob(string$,pattern$)) &#8230;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>glob</tt>-function takes two arguments, a string and a (glob-) pattern, and checks if the string matches the pattern. However <tt>glob</tt> does <span class="emphasis"><i>not</i></span> employ the powerful rules of regular expressions; rather it has only two <span class="emphasis"><i>special</i></span> characters: <tt>*</tt> (which matches any number (even zero) of characters) and <tt>?</tt> (which matches exactly a single character).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
read string$,pattern$
if (glob(string$,pattern$)) then
print string$,&quot; matches &quot;,pattern$
else
print string$,&quot; does not match &quot;,pattern$
endif
next a
data &quot;abc&quot;,&quot;a*&quot;
data &quot;abc&quot;,&quot;a?&quot;
data &quot;abc&quot;,&quot;a??&quot;
data &quot;abc&quot;,&quot;*b*&quot;
data &quot;abc&quot;,&quot;*&quot;
data &quot;abc&quot;,&quot;???&quot;
data &quot;abc&quot;,&quot;?&quot;
data &quot;abc&quot;,&quot;*c&quot;
data &quot;abc&quot;,&quot;A*&quot;
data &quot;abc&quot;,&quot;????&quot;
</pre><p>This program checks the string <tt>abc</tt> against various patterns and prints the result. The output is:</p><pre class="screen">
abc matches a*
abc does not match a?
abc matches a??
abc matches *b*
abc matches *
abc matches ???
abc does not match ?
abc matches *c
abc does not match A*
abc does not match ????
</pre></div></div><div class="refsect1"><h2>See also</h2><p>There are no related commands.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_gosub"></a>gosub</h1><div class="refnamediv"><h2>Name</h2><p>gosub &#8212; continue execution at another point within your program (and return later)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
gosub foo
&#8230;
label foo
&#8230;
return
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>gosub</tt> remembers the current position within your program and then passes the flow of execution to another point (which is normally marked with a <tt><a href="#ref_label" title="label">label</a></tt>). Later, when a <tt>return</tt>-statement is encountered, the execution is resumed at the previous location.</p><p><tt>gosub</tt> is the traditional command for calling code, which needs to be executed from various places within your program. However, with <span class="emphasis"><i>subroutines</i></span> yabasic offers a much more flexible way to achieve this (and more). Therefore <tt>gosub</tt> must to be considered obsolete.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Do you want to exit ? &quot;
gosub ask
if (r$=&quot;y&quot;) exit
label ask
input &quot;Please answer yes or no, by typing 'y' or 'n': &quot;,r$
return
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_return" title="return">return</a></tt>, <tt><a href="#ref_goto" title="goto">goto</a></tt>, <tt><a href="#ref_sub" title="sub">sub</a></tt>, <tt><a href="#ref_label" title="label">label</a></tt>, <tt><a href="#ref_on_gosub" title="on gosub">on gosub</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_goto"></a>goto</h1><div class="refnamediv"><h2>Name</h2><p>goto &#8212; continue execution at another point within your program (and never come back)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
goto foo
&#8230;
label foo
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>goto</tt>-statement passes the flow of execution to another point within your program (which is normally marked with a <tt><a href="#ref_label" title="label">label</a></tt>).</p><p><tt>goto</tt> is normally considered obsolete and harmful, however in yabasic it may be put to the good use of leaving loops (e.g. <tt>while</tt> or <tt>for</tt>) prematurely. Note however, that subroutines may <span class="emphasis"><i>not</i></span> be left with the <tt>goto</tt>-statement.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Please press any key to continue.&quot;
print &quot;(program will continue by itself within 10 seconds)&quot;
for a=1 to 10
if (inkey$(1)&lt;&gt;&quot;&quot;) then goto done
next a
label done
print &quot;Hello World !&quot;
</pre><p>Here the <tt>goto</tt>-statment is used to leave the <tt>for</tt>-loop prematurely.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_gosub" title="gosub">gosub</a></tt>, <tt><a href="#ref_on_goto" title="on goto">on goto</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_h"></a>H</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_hex">hex$()</a> - convert a number into hexadecimal</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_hex"></a>hex$()</h1><div class="refnamediv"><h2>Name</h2><p>hex$() &#8212; convert a number into hexadecimal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print hex$(foo)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>hex$</tt>-function converts a number into a string with its hexadecimal representation. <tt>hex$</tt> is the inverse of the <tt>dec</tt>-function.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open 1,&quot;foo&quot;
while(!eof(1))
print right$(&quot;0&quot;+hex$(peek(1)),2),&quot; &quot;;
i=i+1
if (mod(i,10)=0) print
end while
print
</pre><p>This program reads the file <tt>foo</tt> and prints its output as a <span class="emphasis"><i>hex</i></span>-dump using the <tt>hex</tt>-function.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_dec" title="dec()">dec</a></tt><tt><a href="#ref_bin" title="bin$()">bin</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_i"></a>I</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_if">if</a> - evaluate a condition and execute statements or not, depending on the result</dt><dt><a href="#ref_import">import</a> - import a library</dt><dt><a href="#ref_inkey">inkey$</a> - wait, until a key is pressed</dt><dt><a href="#ref_input">input</a> - read input from the user (or from a file) and assign it to a variable</dt><dt><a href="#ref_instr">instr()</a> - searches its second argument within the first; returns its position if found</dt><dt><a href="#ref_int">int()</a> - return the integer part of its single numeric argument</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_if"></a>if</h1><div class="refnamediv"><h2>Name</h2><p>if &#8212; evaluate a condition and execute statements or not, depending on the result</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (&#8230;) then
&#8230;
endif
if (&#8230;) &#8230;
if (&#8230;) then
&#8230;
else
&#8230;
endif
if (&#8230;) then
&#8230;
elsif (&#8230;)
&#8230;
elsif (&#8230;) then
&#8230;
else
&#8230;
endif
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>if</tt>-statement is used to evaluate a conditions and take actions accordingly. (As an aside, please note that there is no real difference between <a href="#ref_conditions_and_expressions" title="Conditions and expressions">conditions and expressions</a>.)</p><p>There are two major forms of the <tt>if</tt>-statement:</p><div class="itemizedlist"><ul><li><p>The <span class="emphasis"><i>one-line</i></span>-form <span class="emphasis"><i>without</i></span> the keyword <tt>then</tt>: <pre class="programlisting">if (&#8230;) &#8230;</pre> This form evaluates the condition and if the result is <tt>true</tt> executes all commands (seperated by colons) upt to the end of the line. There is neither an <tt>endif</tt> keyword nor an <tt>else</tt>-branch.</p></li><li><p>The <span class="emphasis"><i>multi-line</i></span>-form <span class="emphasis"><i>with</i></span> the keyword <tt>then</tt>: <pre class="programlisting">if (&#8230;) then &#8230; elsif (&#8230;) &#8230; else &#8230; endif</pre> (where <tt>elsif</tt> and <tt>else</tt> are optional, whereas <tt>endif</tt> is not.</p><p>According to the requirements of your program, you may specify:</p><div class="itemizedlist"><ul><li><p><tt>elsif(&#8230;)</tt>, which specifies a condition, that will be evaluated only if the condition(s) whithin <tt>if</tt> or any preceeding <tt>elsif</tt> did not match.</p></li><li><p><tt>else</tt>, which introduces a sequence of commands, that will be executed, if none of the conditions above did match. </p></li><li><p><tt>endif</tt> is required and ends the <tt>if</tt>-statement.</p></li></ul></div></li></ul></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number between 1 and 4: &quot; a
if (a&lt;=1 or a&gt;=4) error &quot;Wrong, wrong !&quot;
if (a=1) then
print &quot;one&quot;
elsif (a=2)
print &quot;two&quot;
elsif (a=3)
print &quot;three&quot;
else
print &quot;four&quot;
endif
</pre><p>The input-number between 1 and 4 is simply echoed as text (<tt>one</tt>, <tt>two</tt>, &#8230;). The example demonstrates both forms (<span class="emphasis"><i>short</i></span> and <span class="emphasis"><i>long</i></span>) of the <tt>if</tt>-statement (Note however, that the same thing can be done, probably somewhat more elegant, with the <tt>switch</tt>-statement).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_else" title="else">else</a></tt>, <tt><a href="#ref_elsif" title="elsif">elsif</a></tt>, <tt><a href="#ref_endif" title="endif">endif</a></tt>, <tt><a href="#ref_conditions_and_expressions" title="Conditions and expressions">conditions and expressions</a></tt>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_import"></a>import</h1><div class="refnamediv"><h2>Name</h2><p>import &#8212; import a library</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
import foo
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>import</tt>-statment imports a library. It expects a single argument, which must be the name of a library (without the trailing <tt>.yab</tt>). This library will then be read and parsed and its subroutines (and variables) will be made available within the main program.</p><p>Libraries will first be searched within the current directory (i.e. the directory within which you have invoked yabasic), then within a special directory, whose exact location depends on your system. Typical values would be <tt>/usr/lib</tt> under Unix or <tt>C:\yabasic\lib</tt> under Windows. However only <b><tt>yabasic -help-usage</tt></b> may tell the truth. The location of this second directory may be changed with the option <tt>-library</tt> (either under <a href="#windows_options">Windows</a> or <a href="#unix_options">Unix</a>).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><p>Lets say you have a yabasic-program <tt>foo.yab</tt>, which imports a library <tt>lib.yab</tt>. <tt>foo.yab</tt> reads:</p><pre class="programlisting">
import lib
rem This works ...
lib.x(0)
rem This works too ..
x(1)
rem And this.
lib.y(2)
rem But this not !
y(3)
</pre><p>Now the library <tt>lib.yab</tt> reads:</p><pre class="programlisting">
rem Make the subroutine x easily available outside this library
export sub x(a)
print a
return
end sub
rem sub y must be referenced by its full name
rem outside this library
sub y(a)
print a
return
end sub
</pre><p>This program produces an error:</p><p>
<pre class="programlisting">
0
1
2
---Error in foo.yab, line 13: can't find subroutine 'y'
---Dump: sub y() called in foo.yab,13
---Error: Program stopped due to an error
</pre>
As you may see from the error message, yabasic is unable to find the subroutine <tt>y</tt> without specifying the name of the library (i.e. <tt>lib.y</tt>). The reason for this is, that <tt>y</tt>, other than <tt>x</tt>, is <span class="emphasis"><i>not</i></span> exported from the library <tt>lib.yab</tt> (using the <tt>export</tt>-statement).
</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_export" title="export">export</a></tt>, <tt><a href="#ref_sub" title="sub">sub</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_inkey"></a>inkey$</h1><div class="refnamediv"><h2>Name</h2><p>inkey$ &#8212; wait, until a key is pressed</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
foo$=inkey$
inkey$
foo$=inkey$(bar)
inkey$(bar)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>inkeys$</tt>-function waits, until the user presses a key on the keyboard or a button of his mouse, and returns this very key. An optional argument specifies the number of seconds to wait; if omitted, <tt>inkey$</tt> will wait indefinitely.</p><p><tt>inkey$</tt> may only be used, if <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> has been called at least once.</p><p>For normal keys, yabasic simply returns the key, e.g. <tt>a</tt>, <tt>1</tt> or <tt>!</tt>. For function keys you will get <tt>f1</tt>, <tt>f2</tt> and so on. Other special keys will return these strings respectively: <tt>enter</tt>, <tt>backspace</tt>, <tt>del</tt>, <tt>esc</tt>, <tt>scrnup</tt> (for <span class="emphasis"><i>screen up</i></span>), <tt>scrndown</tt> and <tt>tab</tt>. Modifier keys (e.g. <tt>ctrl</tt>, <tt>alt</tt> or <tt>shift</tt>) by themself can <span class="emphasis"><i>not</i></span> be detected (however, if you press <tt>shift</tt> and e.g. <tt>a</tt> simultaniously, <tt>inkey$</tt> will return the letter <tt>A</tt> instead of <tt>a</tt> of course).</p><p>If a graphical window has been opened (via <tt>open window</tt>) any mouseclick within this window will be returned by <tt>inkey$</tt> too. The string returned (e.g. <tt>MB1d+0:0028,0061</tt>, <tt>MB2u+0:0028,0061</tt> or <tt>MB1d+1:0028,0061</tt>) is constructed as follows: </p><div class="itemizedlist"><ul><li><p>Every string associated with a mouseclick will start with the fixed string <tt>MB</tt></p></li><li><p>The next digit (<tt>1</tt>, <tt>2</tt> or <tt>3</tt>) specifies the mousebutton pressed.</p></li><li><p>A single letter, <tt>d</tt> or <tt>u</tt>, specifies, if the mousebutton has been pressed or released: <tt>d</tt> stands for <span class="emphasis"><i>down</i></span>, i.e. the mousebutton has been pressed; <tt>u</tt> means <span class="emphasis"><i>up</i></span>, i.e. the mousebutton has been released.</p></li><li><p>The plus-sign ('<tt>+</tt>'), which follows is always fixed.</p></li><li><p>The next digit (in the range 0 to 7) encodes the modifier keys pressed, where <tt>1</tt> stands for <tt>shift</tt>, <tt>2</tt> stands for <tt>alt</tt> and <tt>4</tt> stands for <tt>ctrl</tt>.</p></li><li><p>The next four digits (e.g. <tt>0028</tt>) contain the x-position, where the mousebutton has been pressed.</p></li><li><p>The comma to follow is always fixed.</p></li><li><p>The last four digits (e.g. <tt>0061</tt>) contain the y-position, where the mousebutton has been pressed.</p></li></ul></div><p>All those fields are of fixed length, so you may use functions like <tt>mid$</tt> to extract certain fields. However, note that with <tt>mousex</tt>, <tt>mousey</tt>, <tt>mouseb</tt> and <tt>mousemod</tt> there are specialized functions to return detailed information about the mouseclick. Finally it should be noted, that <tt>inkey$</tt> will only register mouseclicks within the graphic-window; mouseclicks in the text-window cannot be detected.</p><p><tt>inkey$</tt> accepts an optional argument, specifying a timeout in seconds; if no key has been pressed within this span of time, an empty string is returned. If the timeout-argument is omitted, <tt>inkey$</tt> will wait for ever.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
open window 100,100
print &quot;Press any key or press 'q' to stop.&quot;
repeat
a$=inkey$
print a$
until(a$=&quot;q&quot;)
</pre><p>This program simply returns the key pressed. You may use it, to learn, which strings are returned for the special keys on your keyboard (e.g. function-keys).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt>,<tt><a href="#ref_mousex" title="mousex">mousex</a></tt>, <tt><a href="#ref_mousey" title="mousey">mousey</a></tt>, <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt>, <tt><a href="#ref_mousemod" title="mousemod">mousemod</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_input"></a>input</h1><div class="refnamediv"><h2>Name</h2><p>input &#8212; read input from the user (or from a file) and assign it to a variable</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
input a
input a,b,c
input a$
input &quot;Hello&quot; a
input #1 a$
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>input</tt> reads the new contents of one or many (numeric- or string-) variables, either from the keyboard (i.e. from <span class="emphasis"><i>you</i></span>) or from a file. An optional first string-argument specifies a prompt, which will be issued before reading any contents.</p><p>If you want to read from an open file, you need to specify a hash ('#'), followed by the number, under which the file has been opened.</p><p>Note, that the input is split at spaces, i.e. if you enter a whole line consisting of many space-seperated word, the first <tt>input</tt>-statement will only return the first word; the other words will only be returned on subsequent calls to <tt>input</tt>; the same applies, if a single <tt>input</tt> reads multiple variables: The first variable gets only the first word, the second one the second word, and so on. If you don't like this behaviour, you may use <tt>line input</tt>, which returns a whole line (including embedded spaces) at once.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter the name of a file to read: &quot; a$
open 1,a$
while(!eof(1))
input #1 b$
print b$
wend
</pre><p>If this program is stored within a file <tt>test.yab</tt> and you enter this name when prompted for a file to read, you will see this output:</p><p><pre class="screen">Please enter the name of a file to read: t.yab
input
&quot;Please
enter
the
name
of
a
file
to
read:
&quot;
a$
open
1,a$
while(!eof(1))
input
#1
b$
print
b$
wend
</pre>
</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_line_input" title="line input">line input</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_instr"></a>instr()</h1><div class="refnamediv"><h2>Name</h2><p>instr() &#8212; searches its second argument within the first; returns its position if found</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print instr(a$,b$)
if (instr(a$,b$)) &#8230;
pos=instr(a$,b$,x)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>instr</tt>-functions requires two string arguments and searches the second argument within the first. If the second argument can be found within the first, the position is returned (counting from one). If it can not be found, the <tt>instr</tt>-function returns 0; this makes this function usable within the condition of an <tt>if</tt>-statement (see the example below).</p><p>If you supply a third, numeric argument to the <tt>instr</tt>-function, it will be used as a starting point for the search. Therefore <tt>instr(&quot;abcdeabcdeabcde&quot;,&quot;e&quot;,8)</tt> will return 10, because the search for an &quot;<tt>e</tt>&quot; starts at position 8 and finds the &quot;<tt>e</tt>&quot; at position 10 (and not the one at position 5).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a text containing the string 'bumf': &quot; a$
if (instr(a$,&quot;bumf&quot;)) then
print &quot;Well done !&quot;
else
print &quot;not so well ...&quot;
endif
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_rinstr" title="rinstr()">rinstr</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_int"></a>int()</h1><div class="refnamediv"><h2>Name</h2><p>int() &#8212; return the integer part of its single numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print int(a)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>int</tt>-function returns only the digits before the comma; <tt>int(2.5)</tt> returns <tt>2</tt> and <tt>int(-2.3)</tt> returns <tt>-2</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a whole number between 1 and 10: &quot; a
if (a=int(a) and a&gt;=1 and a&lt;=10) then
print &quot;Thanx !&quot;
else
print &quot;Never mind ...&quot;
endif
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_frac" title="frac()">frac</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_l"></a>L</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_label">label</a> - mark a specific location within your program for goto, gosub or restore</dt><dt><a href="#ref_left">left$()</a> - return (or change) left end of a string</dt><dt><a href="#ref_len">len()</a> - return the length of a string</dt><dt><a href="#ref_line">line</a> - draw a line</dt><dt><a href="#ref_line_input">line input</a> - read in a whole line of text and assign it to a variable</dt><dt><a href="#ref_local">local</a> - mark a variable as local to a subroutine</dt><dt><a href="#ref_log">log()</a> - compute the natural logarithm</dt><dt><a href="#ref_loop">loop</a> - marks the end of an infinite loop</dt><dt><a href="#ref_lower">lower$()</a> - convert a string to lower case</dt><dt><a href="#ref_ltrim">ltrim$()</a> - trim spaces at the left end of a string</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_label"></a>label</h1><div class="refnamediv"><h2>Name</h2><p>label &#8212; mark a specific location within your program for <tt>goto</tt>, <tt>gosub</tt> or <tt>restore</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
label foo
&#8230;
goto foo
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>label</tt>-command can be used to give a name to a specific location within your program. Such a position might be referred from one of three commands: <tt>goto</tt>, <tt>gosub</tt> and <tt>restore</tt>.</p><p>You may use labels safely within libraries, because a label (e.g. <tt>foo</tt>) does not collide with a label with the same name within the main program or within another library; yabasic will not mix them up.</p><p>As an aside, please note, that line numbers are a special (however deprecated) case of labels; see the second example below.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
if (rand(10)&gt;5) goto done
next a
label done
10 for a=1 to 100
20 if (rand(10)&gt;5) goto 40
30 next a
40
</pre><p>Within this example, the <tt>for</tt>-loop will probably be left prematurely with a <tt>goto</tt>-statement. This task is done <span class="emphasis"><i>twice</i></span>: First with labels and then again with line numbers.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_gosub" title="gosub">gosub</a></tt>, <tt><a href="#ref_goto" title="goto">goto</a></tt>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_left"></a>left$()</h1><div class="refnamediv"><h2>Name</h2><p>left$() &#8212; return (<span class="emphasis"><i>or change</i></span>) left end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print left$(a$,2)
left$(b$,3)=&quot;foobar&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>left$</tt>-function accepts two arguments (a string and a number) and returns the part from the left end of the string, whose length is specified by its second argument. Loosely spoken, it simply returns the requested number of chars from the left end of the given string.</p><p>Note, that the <tt>left$</tt>-function can be assigned to, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <tt>left$</tt>-function. Note, that that way the <span class="emphasis"><i>length</i></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please answer yes or no: &quot; a$
l=len(a$):a$=lower$(a$):print &quot;Your answer is &quot;;
if (left$(&quot;yes&quot;,l)=a$ and l&gt;=1) then
print &quot;yes&quot;
elsif (left$(&quot;no&quot;,l)=a$ and l&gt;=1) then
print &quot;no&quot;
else
print &quot;?&quot;
endif
</pre><p>This example asks a simple yes/no question and goes some way to accept even incomplete input, while still beeing able to reject invalid input.</p><p>This second example demonstrates the capability to <span class="emphasis"><i>assign</i></span> to the <tt>left$</tt>-function.</p><pre class="programlisting">
a$=&quot;Heiho World !&quot;
print a$
left$(a$,5)=&quot;Hello&quot;
print a$
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_right" title="right$()">right$</a></tt>, <tt><a href="#ref_mid" title="mid$()">mid$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_len"></a>len()</h1><div class="refnamediv"><h2>Name</h2><p>len() &#8212; return the length of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=len(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>len</tt>-function returns the length of its single string argument.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a password: &quot; a$
if (len(a$)&lt;6) error &quot;Password too short !&quot;
</pre><p>This example checks the length of the password, that the user has entered.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_left" title="left$()">left$</a></tt>, <tt><a href="#ref_right" title="right$()">right$</a></tt> and <tt><a href="#ref_mid" title="mid$()">mid$</a></tt>, </p></div></div><div class="refentry"><h1 class="title"><a name="ref_line"></a>line</h1><div class="refnamediv"><h2>Name</h2><p>line &#8212; draw a line</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 100,100
line 0,0,100,100
line 0,0 to 100,100
new curve
line 100,100
line to 100,100
open window 100,100
clear line 0,0,100,100
clear line 0,0 to 100,100
new curve
clear line 100,100
clear line to 100,100
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>line</tt>-command draws a line. Simple as this is, the <tt>line</tt>-command has a large variety of forms as they are listed in the synopsis above. Lets look at them a little closer:</p><div class="itemizedlist"><ul><li><p>A line has a starting and an end point; therefore the <tt>line</tt>-command (normally) needs four numbers as arguments, representing these two points. This is the first form appearing within the synopsis. </p></li><li><p>You may seperate the two points with either '<tt>,</tt>' or <tt>to</tt>, which accounts for the second form of the <tt>line</tt>-command.</p></li><li><p>The <tt>line</tt>-command may be used to draw a connected sequence of lines with a sequence of commands like <tt>line x,y</tt>; Each command will draw a line from the point where the last <tt>line</tt>-command left off, to the point specified in the arguments. Note, that you need to use the command <tt>new curve</tt> before you may issue such a <tt>line</tt>-command. See the example below.</p></li><li><p>You may insert the word <tt>to</tt> for beauty: <tt>line to x,y</tt>, which does exactly the same as <tt>line x,y</tt></p></li><li><p>Finally, you may choose not to draw, but to erase the lines; this can be done by prepending the phrase <tt>clear</tt>. This account for all the other forms of the <tt>line</tt>-command.</p></li></ul></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
line 10,10 to 10,190
line 10,190 to 190,190
new curve
for a=0 to 360
line to 10+a*180/360,100+60*sin(a*pi/180)
next a
</pre><p>This example draws a sine-curve (with an offset in x- and y-direction). Note, that the first <tt>line</tt>-command after <tt>new curve</tt> does not draw anything. Only the coordinates will be stored. The second iteration of the loop then uses these coordinates as a starting point for the first line.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_new_curve" title="new curve">new curve</a></tt>, <tt><a href="#ref_close_curve" title="close curve">close curve</a></tt>, <tt><a href="#ref_open_window" title="open window">open window</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_line_input"></a>line input</h1><div class="refnamediv"><h2>Name</h2><p>line input &#8212; read in a whole line of text and assign it to a variable</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
line input a
line input a$
line input &quot;Hello&quot; a
line input #1 a$
</pre></div><div class="refsect1"><h2>Description</h2><p>In most respects <tt>line input</tt> is like the <tt><a href="#ref_input" title="input">input</a></tt>-command: It reads the new contents of a variable, either from keyboard or from a file. However, <tt>line input</tt> always reads a complete line and assigns it to its variable. <tt>line input</tt> does not stop reading at spaces and is therefore the best way to read in a string which might contain whitespace. Note, that the final newline is stripped of.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input &quot;Please enter your name (e.g. Frodo Beutelin): &quot; a$
print &quot;Hello &quot;,a$
</pre><p>Note that the usage of <tt>line input</tt> is essential in this example; a simple <tt>input</tt>-statement would only return the string up to the first space, e.g. <tt>Frodo</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_input" title="input">input</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_local"></a>local</h1><div class="refnamediv"><h2>Name</h2><p>local &#8212; mark a variable as local to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo()
local a,b,c$,d(10),e$(5,5)
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>local</tt>-command can (and should be) used to mark a variable (or array) as <span class="emphasis"><i>local</i></span> to the containing subroutine. This means, that a local variable in your subroutine is totally different from a variable with the same name within your main program. Variables which are known everywhere within your program are called <span class="emphasis"><i>global</i></span> in contrast.</p><p>Declaring variables within the subroutine as <span class="emphasis"><i>local</i></span> helps to avoid hard to find bugs; therefore local variables should be used whenever possible.</p><p>Note, that the parameters of your subroutines are always local.</p><p>As you may see from the example, local arrays may be created without using the keyword <tt>dim</tt> (which is required only for global arrays).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a=1
b=1
print a,b
foo()
print a,b
sub foo()
local a
a=2
b=2
end sub
</pre><p>This example demonstrates the difference between <tt>local</tt> and global variables; it produces this output:</p><p>
<pre class="screen">1 1
1 2
</pre>
</p><p>As you may see, the content of the global variable <tt>a</tt> is unchanged after the subroutine <tt>foo</tt>; this is because the assignment <tt>a=2</tt> within the subroutine affects the <span class="emphasis"><i>local</i></span> variable <tt>a</tt> only and not the global one. However, the variable <tt>b</tt> is never declared local and therefore the subroutine changes the global variable, which is reflected in the output of the second print-statement.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sub" title="sub">sub</a></tt>, <tt><a href="#ref_static" title="static">static</a></tt>, <tt><a href="#ref_dim" title="dim">dim</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_log"></a>log()</h1><div class="refnamediv"><h2>Name</h2><p>log() &#8212; compute the natural logarithm</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=log(x)
a=log(x,base)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>log</tt>-function computes the logarithm of its first argument. The optional second argument gives the base for the logarithm; if this second argument is omitted, the <span class="emphasis"><i>euler</i></span>-constant 2.71828&#8230; will be taken as the base.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
for x=10 to 190 step 10:for y=10 to 190 step 10
r=3*log(1+x,1+y)
if (r&gt;10) r=10
if (r&lt;1) r=1
fill circle x,y,r
next y:next x
</pre><p>This draws another nice plot.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_exp" title="exp()">exp</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_loop"></a>loop</h1><div class="refnamediv"><h2>Name</h2><p>loop &#8212; marks the end of an infinite loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
do
&#8230;
loop
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>loop</tt>-command marks the ends of a loop (which is started by <tt>do</tt>), wherein all statements within the loop are repeated forever. In this respect the <tt>do loop</tt>-loop is infinite, however, you may leave it anytime via <tt>break</tt> or <tt>goto</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Hello, I will throw dice, until I get a 2 ...&quot;
do
r=int(rand(6))+1
print r
if (r=2) break
loop
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_do" title="do">do</a></tt>, <tt><a href="#ref_for" title="for">for</a></tt>, <tt><a href="#ref_repeat" title="repeat">repeat</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt>, <tt><a href="#ref_break" title="break">break</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_lower"></a>lower$()</h1><div class="refnamediv"><h2>Name</h2><p>lower$() &#8212; convert a string to lower case</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
l$=lower$(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>lower$</tt>-function accepts a single string-argument and converts it to all lower case.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a password: &quot; a$
if (a$=lower$(a$)) error &quot;Your password is NOT mixed case !&quot;
</pre><p>This example prompts for a password and checks, if it is really lower case.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_upper" title="upper$()">upper$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_ltrim"></a>ltrim$()</h1><div class="refnamediv"><h2>Name</h2><p>ltrim$() &#8212; trim spaces at the left end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=ltrim$(b$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>ltrim$</tt>-function removes all whitespace from the left end of a string and returns the result.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please answer 'yes' or 'no' : &quot; a$
a$=lower$(ltrim$(rtrim$(a$)))
if (len(a$)&gt;0 and a$=left$(&quot;yes&quot;,len(a$))) then
print &quot;Yes ...&quot;
else
print &quot;No ...&quot;
endif
</pre><p>This example prompts for an answer and removes any spaces, which might precede the input; therefore it is even prepared for the (albeit somewhat patological case, that the user first hits <span class="emphasis"><i>space</i></span> before entering his answer.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_rtrim" title="rtrim$()">rtrim$</a></tt>, <tt><a href="#ref_trim" title="trim$()">trim$</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_m"></a>M</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_max">max()</a> - return the larger of its two arguments</dt><dt><a href="#ref_mid">mid$()</a> - return (or change) characters from within a string</dt><dt><a href="#ref_min">min()</a> - return the smaller of its two arguments</dt><dt><a href="#ref_mod">mod()</a> - compute the remainder of a division</dt><dt><a href="#ref_mouseb">mouseb</a> - extract the state of the mousebuttons from a string returned by inkey$</dt><dt><a href="#ref_mousemod">mousemod</a> - return the state of the modifier keys during a mouseclick</dt><dt><a href="#ref_mousex">mousex</a> - return the x-position of a mouseclick</dt><dt><a href="#ref_mousey">mousey</a> - return the y-position of a mouseclick</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_max"></a>max()</h1><div class="refnamediv"><h2>Name</h2><p>max() &#8212; return the larger of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print max(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>Return the <span class="emphasis"><i>maximum</i></span> of its two arguments.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim m(10)
for a=1 to 1000
m=0
For b=1 to 10
m=max(m,ran(10))
next b
m(m)=m(m)+1
next a
for a=1 to 9
print a,&quot;: &quot;,m(a)
next a
</pre><p>Within the inner <tt>for</tt>-loop (the one with the loop-variable <tt>b</tt>), the example computes the maximum of 10 random numbers. The outer loop (with the loop variable <tt>a</tt>) now repeats this process 1000 times and counts, how often each maximum appears. The last loop finally reports the result.</p><p>Now, the interesting question would be, which will be approached, when we increase the number of iterations from thousend to infinity. Well, maybe someone could just tell me <tt>:-)</tt></p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_min" title="min()">min</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mid"></a>mid$()</h1><div class="refnamediv"><h2>Name</h2><p>mid$() &#8212; return (<span class="emphasis"><i>or change</i></span>) characters from within a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print mid$(a$,2,1)
print mid$(a$,2)
mid$(a$,5,3)=&quot;foo&quot;
mid$(a$,5)=&quot;foo&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mid$</tt>-function requires three arguments: a string and two numbers, where the first number specifies a position within the string and the second one gives the number of characters to be returned; if you omit the second argument, the <tt>mid$</tt>-function returns all characters up to the end of the string.</p><p>Note, that you may assign to the <tt>mid$</tt>-function, i.e. <tt>mid$</tt> may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <tt>mid$</tt>-function. Note, that that way the <span class="emphasis"><i>length</i></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a string: &quot; a$
for a=1 to len(a$)
if (instr(&quot;aeiou&quot;,lower$(mid$(a$,a,1)))) mid$(a$,a,1)=&quot;e&quot;
next a
print &quot;When you turn everything to lower case and&quot;
print &quot;replace every vowel with 'e', your input reads:&quot;
print
print a$
</pre><p>This example transforms the input string a bit, using the <tt>mid$</tt>-function to retrieve a character from within the string as well as to change it.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_left" title="left$()">left$</a></tt> and <tt><a href="#ref_right" title="right$()">right$</a></tt>.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_min"></a>min()</h1><div class="refnamediv"><h2>Name</h2><p>min() &#8212; return the smaller of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print min(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>Return the <span class="emphasis"><i>minimum</i></span> of its two argument.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim m(10)
for a=1 to 1000
m=min(ran(10),ran(10))
m(m)=m(m)+1
next a
for a=1 to 9
print a,&quot;: &quot;,m(a)
next a
</pre><p>For each iteration of the loop, the lower of two random number is recorded. The result is printed at the end.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_max" title="max()">max</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mod"></a>mod()</h1><div class="refnamediv"><h2>Name</h2><p>mod() &#8212; compute the remainder of a division</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print mod(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mod</tt>-function divides its two arguments and computes the remainder. Note, that <tt>a/b-int(a/b)</tt> and <tt>mod(a,b)</tt> are always equal.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
print at(10,10) &quot;Please wait &quot;;
p$=&quot;-\|/&quot;
for a=1 to 100
rem ... do something lengthy here, or simply sleep :-)
pause(1)
print at(22,10) mid$(p$,1+mod(a,4))
next a
</pre><p>This example executes some time consuming action within a loop (in fact, it simply sleeps) and gives the user some indication of progress by displaying a turning bar (thats where the <tt>mod()</tt>-function comes into play).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_int" title="int()">int</a></tt>, <tt><a href="#ref_frac" title="frac()">frac</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mouseb"></a>mouseb</h1><div class="refnamediv"><h2>Name</h2><p>mouseb &#8212; extract the state of the mousebuttons from a string returned by <tt>inkey$</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mouseb()
print mouseb
a$=inkey$
print mouseb(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mouseb</tt>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <tt>inkey$</tt>-function. If a mousebutton has been pressed, the <tt>mouseb</tt>-function returns the number (1,2 or 3) of the mousebutton, when it is pressed and returns its negative (-1,-2 or -3), when it is released.</p><p>The <tt>mouseb</tt>-function accepts zero or one arguments. A single argument should be a string returned by the <tt>inkey$</tt>-function; if <tt>mouseb</tt> is called without any arguments, it returns the values from the last call to <tt>inkey$</tt>, which are stored implicitly and internally by yabasic.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Note however, that the value returned by the <tt>mouseb</tt>-function does <span class="emphasis"><i>not</i></span> reflect the <span class="emphasis"><i>current</i></span> state of the mousebuttons. It rather extracts the information from the string passed as an argument (or from the last call to the <tt>inkey$</tt>-function, if no argument is passed). So the value returned by <tt>mouseb</tt> reflects the state of the mousebuttons at the time the <tt>inkey$</tt>-function has been called; as opposed to the time the <tt>mouseb</tt>-function is called.</p></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
print &quot;Please draw lines; press (and keep it pressed)&quot;
print &quot;the left mousebutton for the starting point,&quot;
print &quot;release it for the end-point.&quot;
do
if (mouseb(release$)=1) press$=release$
release$=inkey$
if (mouseb(release$)=-1) then
line mousex(press$),mousey(press$) to mousex(release$),mousey(release$)
endif
loop
</pre><p>This is a maybe the most simplistic line-drawing program possible, catching presses as well as releases of the first mousebutton.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>, <tt><a href="#ref_mousex" title="mousex">mousex</a></tt>, <tt><a href="#ref_mousey" title="mousey">mousey</a></tt> and <tt><a href="#ref_mousemod" title="mousemod">mousemod</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mousemod"></a>mousemod</h1><div class="refnamediv"><h2>Name</h2><p>mousemod &#8212; return the state of the modifier keys during a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousemod()
print mousemod
a$=inkey$
print mousemod(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mousemod</tt>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <tt>inkey$</tt>-function if a mousebutton has been pressed. It returns the state of the keyboard modifiers (<tt>shift</tt>, <tt>ctrl</tt> or <tt>alt</tt>): If the <tt>shift</tt>-key is pressed, <tt>mousemod</tt> returns 1, for the <tt>alt</tt>-key 2 and for the <tt>ctrl</tt>-key 4. If more than one key is pressed, the sum of these values is returned, e.g. <tt>mousemod</tt> returns 5, if <tt>shift</tt> and <tt>ctrl</tt> are pressed simultanously.</p><p>The <tt>mousemod</tt>-function accepts zero or one arguments. A single argument should be a string returned by the <tt>inkey$</tt>-function; if <tt>mousemod</tt> is called without any arguments, it returns the values from the last call to <tt>inkey$</tt> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt>-function.</p></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
a$=inkey$
if (left$(a$,2)=&quot;MB&quot;) then
x=mousex(a$)
y=mousey(a$)
if (mousemod(a$)=0) then
circle x,y,20
else
fill circle x,y,20
endif
endif
loop
</pre><p>This program draws a circle, whenever a mousebutton is pressed; the circles are filled, when any modifier is pressed, and empty if not.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>, <tt><a href="#ref_mousex" title="mousex">mousex</a></tt>, <tt><a href="#ref_mousey" title="mousey">mousey</a></tt> and <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mousex"></a>mousex</h1><div class="refnamediv"><h2>Name</h2><p>mousex &#8212; return the x-position of a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousex()
print mousex
a$=inkey$
print mousex(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mousex</tt>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <tt>inkey$</tt>-function; It returns the x-position of the mouse as encoded within its argument.</p><p>The <tt>mousex</tt>-function accepts zero or one arguments. A single argument should be a string returned by the <tt>inkey$</tt>-function; if <tt>mousex</tt> is called without any arguments, it returns the values from the last call to <tt>inkey$</tt> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt>-function.</p></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
a$=inkey$
if (left$(a$,2)=&quot;MB&quot;) then
line mousex,0 to mousex,200
endif
loop
</pre><p>This example draws vertical lines at the position, where the mousebutton has been pressed.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>, <tt><a href="#ref_mousemod" title="mousemod">mousemod</a></tt>, <tt><a href="#ref_mousey" title="mousey">mousey</a></tt> and <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_mousey"></a>mousey</h1><div class="refnamediv"><h2>Name</h2><p>mousey &#8212; return the y-position of a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousey()
print mousey
a$=inkey$
print mousey(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>mousey</tt>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <tt>inkey$</tt>-function. <tt>mousey</tt> returns the y-position of the mouse as encoded within its argument.</p><p>The <tt>mousey</tt>-function accepts zero or one arguments. A single argument should be a string returned by the <tt>inkey$</tt>-function; if <tt>mousey</tt> is called without any arguments, it returns the values from the last call to <tt>inkey$</tt> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt>-function.</p></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
a$=inkey$
if (left$(a$,2)=&quot;MB&quot;) then
line 0,mousey to 200,mousey
endif
loop
</pre><p>This example draws horizontal lines at the position, where the mousebutton has been pressed.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>, <tt><a href="#ref_mousemod" title="mousemod">mousemod</a></tt>, <tt><a href="#ref_mousey" title="mousey">mousex</a></tt> and <tt><a href="#ref_mouseb" title="mouseb">mouseb</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_n"></a>N</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_new_curve">new curve</a> - start a new curve, that will be drawn with the line-command</dt><dt><a href="#ref_next">next</a> - mark the end of a for loop</dt><dt><a href="#ref_not">not</a> - negate an expression; can be written as !</dt><dt><a href="#ref_numparams">numparams</a> - return the number of parameters, that have been passed to a subroutine</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_new_curve"></a>new curve</h1><div class="refnamediv"><h2>Name</h2><p>new curve &#8212; start a new curve, that will be drawn with the <tt>line</tt>-command</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
new curve
line to x,y
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>new curve</tt>-function starts a new sequence of lines, that will be drawn by repeated <tt>line to</tt>-commands.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
ellipse(100,50,30,60)
ellipse(150,100,60,30)
sub ellipse(x,y,xr,yr)
new curve
for a=0 to 2*pi step 0.2
line to x+xr*cos(a),y+yr*sin(a)
next a
close curve
end sub
</pre><p>This example defines a subroutine <tt>ellipse</tt> that draws an ellipse. Within this subroutine, the ellipse is drawn as a sequence of lines started with the <tt>new curve</tt> command and closed with <tt>close curve</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_close_curve" title="close curve">close curve</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_next"></a>next</h1><div class="refnamediv"><h2>Name</h2><p>next &#8212; mark the end of a for loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 10
next a
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>next</tt>-keyword marks the end of a <tt>for</tt>-loop. All statements up to the <tt>next</tt>-keyword will be repeated as specified with the <tt>for</tt>-clause. Note, that the name of the variable is optional; so instead of <tt>next a</tt> you may write <tt>next</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 300000
for b=1 to 21+20*sin(pi*a/20)
print &quot;*&quot;;
next b
print
sleep 0.1
next a
</pre><p>This example simply plots a sine-curve until you fall asleep.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_for" title="for">for</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_not"></a>not</h1><div class="refnamediv"><h2>Name</h2><p>not &#8212; negate an expression; can be written as <tt>!</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (not a&lt;b) then &#8230;
bad=!okay
</pre></div><div class="refsect1"><h2>Description</h2><p>The keyword <tt>not</tt> (or <tt>!</tt> for short) is mostly used within conditions (e.g. within <tt>if</tt>- or <tt>while</tt>-statements). There it is employed to negate the condition or expression (i.e. turn <tt>TRUE</tt> into <tt>FALSE</tt> and vice versa)</p><p>However <tt>not</tt> can be used within arithmetic calculations too., simply because there is no difference between arithmetic and logical expressions.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter three ascending numbers: &quot; a,b,c
if (not (a&lt;b and b&lt;c)) error &quot; the numbers you have entered are not ascending ...&quot;
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_logical_and" title="and"><tt>and</tt></a>,<a href="#ref_logical_or" title="logical or"><tt>or</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_numparams"></a>numparams</h1><div class="refnamediv"><h2>Name</h2><p>numparams &#8212; return the number of parameters, that have been passed to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo(a,b,c)
if (numparams=1) &#8230;
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>Within a subroutine the local variable <tt>numparam</tt> or <tt>numparams</tt> contains the number of parameters, that have been passed to the subroutine. This information can be useful, because the subroutine may have been called with fewer parameters than actually declared. The number of values that actually have been passed while calling the subroutine, can be found in <tt>numparams</tt>.</p><p>Note, that arguments which are used in the definition of a subroutine but are left out during a call to it (thereby reducing the value of <tt>numparams</tt>) receive a value of <tt>0</tt> or <tt>&quot;&quot;</tt> (empty string) respectively.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a$=&quot;123456789&quot;
print part$(a$,4)
print part$(a$,3,7)
sub part$(a$,f,t)
if (numparams=2) then
return mid$(a$,f)
else
return mid$(a$,f,t-f+1)
end if
end sub
</pre><p>When you run this example, it will print <tt>456789</tt> and <tt>34567</tt>. Take a look at the subroutine <tt>part$</tt>, which returns part of the string which has been passed as an argument. If (besides the string) two numbers are passed, they define the starting and end position of the substring, that will be returned. However, if only one number is passed, the rest of the string, starting from this position will be returned. Each of these cases is recognized with the help of the <tt>numparams</tt> variable.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sub" title="sub">sub</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_o"></a>O</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_on_gosub">on gosub</a> - jump to one of multiple gosub-targets</dt><dt><a href="#ref_on_goto">on goto</a> - jump to one of many goto-targets</dt><dt><a href="#ref_on_interrupt">on interrupt</a> - change reaction on keyboard interrupts</dt><dt><a href="#ref_open">open</a> - open a file</dt><dt><a href="#ref_open_printer">open printer</a> - open printer for printing graphics</dt><dt><a href="#ref_open_window">open window</a> - open a graphic window</dt><dt><a href="#ref_logical_or">logical or</a> - logical or, used in conditions</dt><dt><a href="#ref_arithmetic_or">or()</a> - arithmetic or, used for bit-operations</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_on_gosub"></a>on gosub</h1><div class="refnamediv"><h2>Name</h2><p>on goto &#8212; jump to one of multiple <tt>gosub</tt>-targets</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on a gosub foo,bar,baz
&#8230;
label foo
&#8230;
return
label bar
&#8230;
return
label baz
&#8230;
return
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>on gosub</tt> statement uses its numeric argument (the one between <tt>on</tt> and <tt>gosub</tt>) to select an element from the list of labels, which follows after the <tt>gosub</tt>-keyword: If the number is 1, the program does a <tt>gosub</tt> to the first label; if the number is 2, to the second and, so on. if the number is zero or less, the program continues at the position of the first label; if the number is larger than the total count of labels, the execution continues at the position of the last label; i.e. the first and last label in the list constitute some kind of fallback-slot.</p><p>Note, that the <tt>on gosub</tt>-command can no longer be considered <span class="emphasis"><i>state of the art</i></span>; people (not me !) may even start to mock you, if you use it.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
print &quot;Please enter a number between 1 and 3: &quot;
print
input &quot;Your choice &quot; a
on a gosub bad,one,two,three,bad
loop
label bad
print &quot;No. Please between 1 and 3&quot;
return
label one
print &quot;one&quot;
return
label two
print &quot;two&quot;
return
label three
print &quot;three&quot;
return
</pre><p>Note, how invalid input (a number less than 1, or larger than 3) is automatically detected.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_goto" title="goto">goto</a></tt>, <tt><a href="#ref_on_gosub" title="on gosub">on gosub/function&gt;</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_on_goto"></a>on goto</h1><div class="refnamediv"><h2>Name</h2><p>on goto &#8212; jump to one of many <tt>goto</tt>-targets</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on a goto foo,bar,baz
&#8230;
label foo
&#8230;
label bar
&#8230;
label baz
&#8230;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>on goto</tt> statement uses its numeric argument (the one between <tt>on</tt> and <tt>goto</tt> to select an element from the list of labels, which follows after the <tt>goto</tt>-keyword: If the number is 1, the execution continues at the first label; if the number is 2, at the second, and so on. if the number is zero or less, the program continues at the position of the first label; if the number is larger than the total count of labels, the execution continues at the position of the last label; i.e. the first and last label in the list constitute some kind of fallback-slot.</p><p>Note, that (unlike the <tt>goto</tt>-command) the <tt>on goto</tt>-command can no longer be considered <span class="emphasis"><i>state of the art</i></span>; people may (not me !) even start to mock you, if you use it.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
label over
print &quot;Please Select one of these choices: &quot;
print
print &quot; 1 -- show time&quot;
print &quot; 2 -- show date&quot;
print &quot; 3 -- exit&quot;
print
input &quot;Your choice &quot; a
on a goto over,show_time,show_date,terminate,over
label show_time
print time$()
goto over
label show_date
print date$()
goto over
label terminate
exit
</pre><p>Note, how invalid input (a number less than 1, or larger than 3) is automatically detected; in such a case the question is simply issued again.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_goto" title="goto">goto</a></tt>, <tt><a href="#ref_on_gosub" title="on gosub">on gosub/function&gt;</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_on_interrupt"></a>on interrupt</h1><div class="refnamediv"><h2>Name</h2><p>on interrupt &#8212; change reaction on keyboard interrupts</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on interrupt break
&#8230;
on interrupt continue
</pre></div><div class="refsect1"><h2>Description</h2><p>With the <tt>on interrupt</tt>-command you may change the way, how yabasic reacts on a keyboard interrupt; it comes in two variants: <tt>on interrupt break</tt> and <tt>on interrupt continue</tt>. A keyboard interrupt is produced, if you press <b><tt>ctrl-C</tt></b> on your keyboard; normally (and certainly after you have called <tt>on interrupt break</tt>), yabasic will terminate with an error message. However after the command <tt>on interrupt continue</tt> yabasic ignores any keyboard interrupt. This may be useful, if you do not want your program beeing interruptible during certain critical operations (e.g. updating of files).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Please stand by while writing a file with random data ...&quot;
on interrupt continue
open &quot;random.data&quot; for writing as #1
for a=1 to 100
print #1 ran(100)
print a,&quot; percent done.&quot;
sleep 1
next a
close #1
on interrupt continue
</pre><p>This program writes a file with 100 random numbers. The <tt>on interrupt continue</tt> command insures, that the program will not be terminated on a keyboard interrupt and the file will be written entirely in any case. The <tt>sleep</tt>-command just stretches the process arificially to give you a chance to try a <b><tt>ctrl-C</tt></b>.</p></div></div><div class="refsect1"><h2>See also</h2><p>There is no related command.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_open"></a>open</h1><div class="refnamediv"><h2>Name</h2><p>open &#8212; open a file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open a,&quot;file&quot;,&quot;r&quot;
open #a,&quot;file&quot;,&quot;w&quot;
open #a,printer
open &quot;file&quot; for reading as a
open &quot;file&quot; for writing as #a
a=open(&quot;file&quot;)
a=open(&quot;file&quot;,&quot;r&quot;)
if (open(a,&quot;file&quot;)) &#8230;
if (open(a,&quot;file&quot;,&quot;w&quot;)) &#8230;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>open</tt>-command opens a file for reading or writing or a printer for printing text. <tt>open</tt> comes in a wide variety of ways; it requires these arguments:</p><div class="variablelist"><dl><dt><span class="term">filenumber</span></dt><dd><p>In the synopsis this is <tt>a</tt> or <tt>#a</tt>. In yabasic each file is associated with a number between 1 and a maximum value, which depends on the operating system. For historical reasons the filenumber can be preceded by a hash ('<tt>#</tt>'). Note, that specifying a filenumber is optional; if it is omitted, the <tt>open</tt>-function will return a filenumber, which should then be stored in a variable for later reference. This filenumber can be a simple number or an arbitrary complex arithmetic expression, in which case braces might be necessary to save yabasic from getting confused.</p></dd><dt><span class="term">filename</span></dt><dd><p>In the synopsis above this is <tt>&quot;file&quot;</tt>. This string specifies the name of the file to open (note the important <a href="#ref_windows_filenames" title="Specifying Filenames under Windows">caveat</a> on specifying these filenames).</p></dd><dt><span class="term">accessmode</span></dt><dd><p>In the synopsis this is <tt>&quot;r&quot;</tt>, <tt>&quot;w&quot;</tt>, <tt>for reading</tt> or <tt>for writing</tt>. This string or clause specifies the mode in which the file is opened; it may be one of:
<div class="variablelist"><dl><dt><span class="term">&quot;r&quot;</span></dt><dd><p>Open the file for reading (may also be written as <tt>for reading</tt>). If the file does not exist, the command will fail. This mode is the default, i.e. if no mode is specified with the <tt>open</tt>-command, the file will be opened with this mode.</p></dd><dt><span class="term">&quot;w&quot;</span></dt><dd><p>Open the file for writing (may also be written as <tt>for writing</tt>). If the file does not exist, it will be created.</p></dd><dt><span class="term">&quot;a&quot;</span></dt><dd><p>Open the file for appending, i.e. what you write to the file will be appended after its initial contents. If the file does not exist, it will be created.</p></dd><dt><span class="term">&quot;b&quot;</span></dt><dd><p>This letter may not appear alone, but may be combined with the other letters (e.g. <tt>&quot;rb&quot;</tt>) to open a file in binary mode (as opposed to text mode).</p></dd></dl></div>
</p></dd></dl></div><p>As you may see from the synopsis, the <tt>open</tt>-command may either be called as a command (without braces) or as a function (with braces). If called as a function, it will return the filenumber or zero if the operation fails. Therefore the <tt>open</tt>-function may be used within the condition of an <tt>if</tt>-statement.</p><p>If the <tt>open</tt>-command fails, you may use <tt><a href="#ref_peek" title="peek">peek(&quot;error&quot;)</a></tt> to retrieve the exact nature of the error.</p><p>Furthermore note, that there is another, somewhat separate usage of the <tt>open</tt>-command; if you specify the bareword <tt>printer</tt> instead of a filename, the command opens a printer for printing text. Every text (and only text) you print to this file will appear on your printer. Note, that this is very different from printing graphics, as can be done with <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt>.</p><p>Finally you may read the description for <tt><a href="#ref_peek" title="peek">peek(&quot;error&quot;)</a></tt> to learn which errors may have happened during an <tt>open</tt>-call.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open &quot;foo.bar&quot; for writing as #1
print #1 &quot;Hallo !&quot;
close #1
if (not open(1,&quot;foo.bar&quot;)) error &quot;Could not open 'foo.bar' for reading&quot;
while(not eof(1))
line input #1 a$
print a$
wend
</pre><p>This example simply opens the file <tt>foo.bar</tt>, writes a single line, reopens it and reads its contents again.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_close" title="close">close</a></tt>, <tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt>, <tt><a href="#ref_peek" title="peek">peek(&quot;error&quot;)</a></tt> and <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_open_printer"></a>open printer</h1><div class="refnamediv"><h2>Name</h2><p>open printer &#8212; open printer for printing graphics</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open printer
open printer &quot;file&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>open printer</tt>-command opens a printer for printing graphics. The command requires, that a graphic window has been opened before. Everything that is drawn into this window will then be sent to the printer too.</p><p>A new piece of paper may be started with the <tt>clear window</tt>-command; the final (or only) page will appear after the <tt>close printer</tt>-command.</p><p>Note, that you may specify a filename with <tt>open printer</tt>; in that case the printout will be sent to a filename instead to a printer. Your program or the user will be responsible for sending this file to the printer afterwards.</p><p>If you use yabasic under Unix, you will need a postscript printer (because yabasic produces postscript output). Alternatively you may use <span class="emphasis"><i>ghostscript</i></span> to transfrom the postscript file into a form suitable for your printer; but that is beyond the responsibility of yabasic.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer
line 0,0 to 200,200
text 100,100,&quot;Hallo&quot;
close window
close printer
</pre><p>This example will open a window, draw a line and print some text within; everything will appear on your printer too.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_close_printer" title="close printer">close printer</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_open_window"></a>open window</h1><div class="refnamediv"><h2>Name</h2><p>open window &#8212; open a graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window x,y
open window x,y,&quot;font&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>open window</tt>-command opens a window of the specified size. Only one window can be opened at any given moment of time.</p><p>An optional third argument specifies a font to be used for any <a href="#ref_text" title="text">text</a> within the window. Please note, that if you open a window several times with varying font-arguments, only the first one will take effect, all others will be ignored; that means that you may onle use a single font for all windows in your program.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=200 to 400 step 10
open window a,a
for b=0 to a
line 0,b to a,b
line b,0 to b,a
sleep 0.1
close window
next a
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_close_window" title="close window">close window</a></tt>, <tt><a href="#ref_text" title="text">text</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_logical_or"></a>logical or</h1><div class="refnamediv"><h2>Name</h2><p>or &#8212; logical or, used in conditions</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a or b) &#8230;
while (a or b) &#8230;
</pre></div><div class="refsect1"><h2>Description</h2><p>Used in conditions (e.g within <tt><a href="#ref_if" title="if">if</a></tt> or <tt><a href="#ref_while" title="while">while</a></tt>) to join two expressions. Returns <tt>true</tt>, if either its left or its right or both arguments are <tt>true</tt>; returns <tt>false</tt> otherwise.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number&quot;
if (a&gt;9 or a&lt;1) print &quot;a is not between 1 and 9&quot;
</pre></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_logical_and" title="and"><tt>and</tt></a>,<a href="#ref_not" title="not"><tt>not</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_arithmetic_or"></a>or()</h1><div class="refnamediv"><h2>Name</h2><p>or() &#8212; arithmetic or, used for bit-operations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=or(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>Used to compute the bitwise <tt>or</tt> of both its argument. Both arguments are treated as binary numbers (i.e. a series of 0 and 1); a bit of the resulting value will then be 1, if any of its arguments has 1 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <tt>or</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print or(14,3)
</pre><p>This will print <tt>15</tt>. This result is clear, if you note, that the binary representation of 14 and 3 are 1110 and 0011 respectively; this will yield 1111 in binary representaion or 15 as decimal.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_arithmetic_and" title="and()"><tt>oand</tt></a>, <a href="#ref_eor" title="eor()"><tt>eor</tt></a> and <a href="#ref_not" title="not"><tt>not</tt></a></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_p"></a>P</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_pause">pause</a> - pause, sleep, wait for the specified number of seconds</dt><dt><a href="#ref_peek">peek</a> - retrieve various internal informations</dt><dt><a href="#ref_peek2">peek$</a> - retrieve various internal string-informations</dt><dt><a href="#ref_pi">pi</a> - a constant with the value 3.14159</dt><dt><a href="#ref_poke">poke</a> - change selected internals of yabasic</dt><dt><a href="#ref_print">print</a> - Write to terminal or file</dt><dt><a href="#ref_putbit">putbit</a> - draw a rectangle of pixels into the graphic window</dt><dt><a href="#ref_putscreen">putscreen</a> - draw a rectangle of characters into the text terminal</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_pause"></a>pause</h1><div class="refnamediv"><h2>Name</h2><p>pause &#8212; pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
pause 5
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>pause</tt>-command has many different names: You may write <tt>pause</tt>, <tt>sleep</tt> or <tt>wait</tt> interchangable; whatever you write, yabasic will always do exactly the same.</p><p>The <tt>pause</tt>-command will simply wait for the specified number of seconds. This may be a fractional number, so you may well wait less than a second. However, if you try to pause for a smaller and smaller interval (e.g. 0.1 seconds, 0.01 seconds, 0.001 seconds and so on) you will find that at some point yabasic will not wait at all. The minimal interval that can be waited depends on the system (Unix, Windows) you are using.</p><p>The <tt>pause</tt>-command cannot be interrupted. However, sometimes you may want the wait to be interuptible by simply pressing a key on the keyboard. In such cases you should consider using the <tt><a href="#ref_inkey" title="inkey$">inkey$</a></tt>-function, with a number of seconds as an argument).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
deg=0
do
maxx=44+40*sin(deg)
for x=1 to maxx
print &quot;*&quot;;
next x
pause 0.1+(maxx*maxx/(4*84*84))
print
deg=deg+0.1
loop
</pre><p>This example draws a sine-curve; due to the <tt>pause</tt>-statement the speed of drawing varies in the same way as the speed of a ball might vary, if it would roll along this curve under the influence of gravity.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sleep" title="sleep">sleep</a></tt>, <tt><a href="#ref_wait" title="wait">wait</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_peek"></a>peek</h1><div class="refnamediv"><h2>Name</h2><p>peek &#8212; retrieve various internal informations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print peek(&quot;foo&quot;)
a=peek(#1)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>peek</tt>-function has many different and mostly unrelated uses. It is a kind of grabbag for retrieving all kinds of numerical information, internal to yabasic. The meaning of the numbers returned be the <tt>peek</tt>-function depends on the string or number passed as an argument.</p><p><tt>peek</tt> always returns a number, however the closely related <tt><a href="#ref_peek2" title="peek$">peek$</a></tt>-function exists, which may be used to retrieve string information from among the internals of yabasic. Finally note, that some of the values which are retrieved with <tt>peek</tt> may even be changed, using the <tt><a href="#ref_poke" title="poke">poke</a></tt>-function.</p><p>There are two variants of the <tt>peek</tt>-function: One expects an integer, positive number and is described within the first entry of the list below. The other variant expects one of a well defined set of strings as described in the second and all the following entries of the list below.</p><div class="variablelist"><dl><dt><span class="term"><tt>peek(a), peek(#a)</tt></span></dt><dd><p>Read a single character from the file <tt>a</tt> (which must be open of course).</p></dd><dt><span class="term"><tt>peek(&quot;winheight&quot;)</tt></span></dt><dd><p>Return the height of the graphic-window in pixels. If none is open, this <tt>peek</tt> will return the height of the last window opened or 100, if none has been opened yet.</p></dd><dt><span class="term"><tt>peek(&quot;winwidth&quot;)</tt></span></dt><dd><p>Return the width of the graphic-window in pixels. If none is open, this <tt>peek</tt> will return the width of the last window opened or 100, if none has been opened yet.</p></dd><dt><span class="term"><tt>peek(&quot;fontheight&quot;)</tt></span></dt><dd><p>Return the height of the font used within the graphic window. If none is open, this <tt>peek</tt> will return the height of the last font used or 10, if no window has been opened yet.</p></dd><dt><span class="term"><tt>peek(&quot;screenheight&quot;)</tt></span></dt><dd><p>Return the height in characters of the window, wherein yabasic runs. If you have not called <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> yet, this <tt>peek</tt>will return 0, regardless of the size of your terminal.</p></dd><dt><span class="term"><tt>peek(&quot;screenwidth&quot;)</tt></span></dt><dd><p>Return the width in characters of the window, wherein yabasic runs. If you have not called <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> yet, this <tt>peek</tt>will return 0, regardless of the size of your terminal.</p></dd><dt><span class="term"><tt>peek(&quot;argument&quot;)</tt></span></dt><dd><p>Return the number of arguments, that have been passed to yabasic at invocation time. E.g. if yabasic has been called like this: <tt>yabasic foo.yab bar baz</tt>, then <tt>peek(&quot;argument&quot;)</tt> will return 2. This is because <tt>foo.yab</tt> is treated as the name of the program to run, whereas <tt>bar</tt> and <tt>baz</tt> are considered arguments to the program, which are passed on the commandline. <span class="emphasis"><i>Note</i></span>, that for windows-users, who tend to click on the icon (as opposed to starting yabasic on the command line), this <tt>peek</tt>will mostly return 0.</p><p>The function <tt>peek(&quot;argument&quot;)</tt> can be written as <tt>peek(&quot;arguments&quot;)</tt> too.</p><p>You will want to check out the corresponding function <tt><a href="#ref_peek2" title="peek$">peek$(&quot;argument&quot;)</a></tt> to actually <span class="emphasis"><i>retrieve</i></span> the arguments. <span class="emphasis"><i>Note</i></span>, that each call to <tt>peek$(&quot;argument&quot;)</tt> reduces the number returned by <tt>peek(&quot;argument&quot;)</tt>.</p></dd><dt><span class="term"><tt>peek(&quot;isbound&quot;)</tt></span></dt><dd><p>Return <tt>true</tt>, if the executing yabasic-program is part of a standalone program; see the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><i>standalone</i></span>-program</a> for details.</p></dd><dt><span class="term"><tt>peek(&quot;version&quot;)</tt></span></dt><dd><p>Return the version number of yabasic (e.g. 2.72).</p></dd><dt><span class="term"><tt>peek(&quot;error&quot;)</tt></span></dt><dd><p>Return a number specifying the nature of the last error in an <tt>open</tt>- or <tt>seek</tt>-statement. Normally an error within an <tt>open</tt>-statement immediately terminates your program with an appropriate error-message, so there is no chance and no need to learn more about the nature of the error. However, if you use <tt>open</tt> as a condition (e.g. <tt>if (open(#1,&quot;foo&quot;)) &#8230;</tt>) the outcome (success or failure) of the <tt>open</tt>-operation will determine, if the condition evaluates to <tt>true</tt> or <tt>false</tt>. If now such an operation fails, your program will not be terminated and you might want to learn the reason for failure. This reason will be returned by <tt>peek(&quot;error&quot;)</tt> (as a number) or by <tt>peek$(&quot;error&quot;)</tt> (as a string)</p><p>The table below shows the various error codes; the value returned by <tt>peek$(&quot;error&quot;)</tt> explains the nature of the error. Note, that the codes 10,11 and 12 refer to the <tt>seek</tt>-command.</p><div class="table"><p><b>Table 6.1. Error codes</b></p><table summary="Error codes" border="1"><colgroup><col><col><col></colgroup><thead><tr><th><tt>peek(&quot;error&quot;)</tt></th><th><tt>peek$(&quot;error&quot;)</tt></th><th>Explanation</th></tr></thead><tbody><tr><td align="center">2</td><td><tt>Stream already in use</tt></td><td>Do not try to open one and the same filenumber twice; rather <tt><a href="#ref_close" title="close">close</a></tt> it first.</td></tr><tr><td align="center">3</td><td><tt>'x' is not a valid filemode</tt></td><td>The optional <span class="emphasis"><i>filemode</i></span> argument, which may be passed to the <tt><a href="#ref_open" title="open">open</a></tt>-function, has an invalid value</td></tr><tr><td align="center">4</td><td><tt>could not open 'foo'</tt></td><td>The <tt>open</tt>-call did not work, no further explanation is available.</td></tr><tr><td align="center">5</td><td><tt>reached maximum number of open files</tt></td><td>You have opened more files than your operating system permits.</td></tr><tr><td align="center">6</td><td><tt>cannot open printer: already printing graphics</tt></td><td>The commands <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt> and <tt><a href="#ref_open" title="open">open #1,printer</a></tt> both open a printer (refer to their description for the difference). However, only one can be active at a time; if you try to do both at the same time, you will receive this error.</td></tr><tr><td align="center">7</td><td><tt>could not open line printer</tt></td><td>Well, it simply did not work.</td></tr><tr><td align="center">9</td><td><tt>invalid stream number</tt></td><td>An attempt to use an invalid (e.g. negative) stream number; example: <tt>open(-1,&quot;foo&quot;)</tt></td></tr><tr><td align="center">10</td><td><tt>could not position stream x to byte y</tt></td><td><tt><a href="#ref_seek" title="seek()">seek</a></tt> did not work.</td></tr><tr><td align="center">11</td><td><tt>stream x not open</tt></td><td>You have tried to <tt><a href="#ref_seek" title="seek()">seek</a></tt> within a stream, that has not been opened yet.</td></tr><tr><td align="center">12</td><td><tt>seek mode 'x' is none of begin,end,here</tt></td><td>The argument, which has been passed to <tt><a href="#ref_seek" title="seek()">seek</a></tt> is invalid.</td></tr></tbody></table></div></dd></dl></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open &quot;foo&quot; for reading as #1
open &quot;bar&quot; for writing as #2
while(not eof(#1))
poke #2,chr$(peek(#1));
wend
</pre><p>This program will copy the file <tt>foo</tt> byte by byte to <tt>bar</tt>.</p><p>Note, that each <tt>peek</tt> does something entirely different, and only one has been demonstrated above. Therefore you need to make up examples yourself for all the other <tt>peek</tt>s.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_peek2" title="peek$">peek$</a></tt>, <tt><a href="#ref_poke" title="poke">poke</a></tt>, <tt><a href="#ref_open" title="open">open</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_peek2"></a>peek$</h1><div class="refnamediv"><h2>Name</h2><p>peek$ &#8212; retrieve various internal string-informations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print peek$(&quot;foo&quot;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>peek$</tt>-function has many different and unrelated uses. It is a kind of grabbag for retrieving all kinds of string information, internal to yabasic; the exact nature of the strings returned be the <tt>peek$</tt>-function depends on the string passed as an argument.</p><p><tt>peek$</tt> always returns a string, however the closely related <tt><a href="#ref_peek" title="peek">peek</a></tt>-function exists, which may be used to retrieve numerical information from among the internals of yabasic. Finally note, that some of the values which are retrieved with <tt>peek$</tt> may even be changed, using the <tt><a href="#ref_poke" title="poke">poke</a></tt>-function.</p><p>The following list shows all possible arguments to <tt>peek$</tt>:</p><div class="variablelist"><dl><dt><span class="term"><tt>peek$(&quot;infolevel&quot;)</tt></span></dt><dd><p>Returns either <tt>&quot;debug&quot;</tt>, <tt>&quot;note&quot;</tt>, <tt>&quot;warning&quot;</tt>, <tt>&quot;error&quot;</tt> or <tt>&quot;fatal&quot;</tt>, depending on the current infolevel. This value can be specified with an option (either under <a href="#windows_options">windows</a> or <a href="#unix_options">unix</a>) on the commandline or changed during the execution of the program with the corresponding <tt><a href="#ref_poke" title="poke">poke</a></tt>; however, normally only the author of yabasic (<span class="emphasis"><i>me</i></span> !) would want to change this from its default value <tt>&quot;warning&quot;</tt>.</p></dd><dt><span class="term"><tt>peek$(&quot;textalign&quot;)</tt></span></dt><dd><p>Returns one of nine possible strings, specifying the default alignment of text within the graphics-window. The alignment-string returned by this <tt>peek</tt> describes, how the <tt><a href="#ref_text" title="text">text</a></tt>-command aligns its string-argument with respect to the coordinates supplied. However, this value does <span class="emphasis"><i>not apply</i></span>, if the <tt>text</tt>-command explicitly specifies an alignment. Each of these strings is two characters long. The first character specifies the horizontal alignment and can be either <tt>l</tt>, <tt>r</tt> or <tt>c</tt>, which stand for <i>left</i>, <i>right</i> or <i>center</i>. The second character specifies the vertical alignment and can be one of <tt>t</tt>, <tt>b</tt> or <tt>c</tt>, which stand for <i>top</i>, <i>bottom</i> or <i>center</i> respectively.</p><p>You may change this value with the corresponding command <tt>poke &quot;textalign&quot;,&#8230;</tt>; the initial value is <tt>lb</tt>, which means the top of the left and the top edge if the text will be aligned with the coordinates, that are specified within the <tt>text</tt>-command.</p></dd><dt><span class="term"><tt>peek$(&quot;windoworigin&quot;)</tt></span></dt><dd><p>This <tt>peek</tt> returns a two character string, which specifies the position of the origin of the coordinate system of the window; this string might be changed with the corresponding command <tt>poke &quot;windoworigin&quot;,x,y</tt> or specified as the argument of the <tt><a href="#ref_origin" title="window origin">origin</a></tt> command; see there for a detailed description of the string, which might be returned by this <tt>peek</tt>.</p></dd><dt><span class="term"><tt>peek$(&quot;error&quot;)</tt></span></dt><dd><p>Return a string describing the nature of the last error in an <tt>open</tt>- or <tt>seek</tt>-statement. See the corresponding <tt><a href="#ref_peek" title="peek">peek(&quot;error&quot;)</a></tt> for a detailed description.</p></dd><dt><span class="term"><tt>peek$(&quot;library&quot;)</tt></span></dt><dd><p>Return the name of the library, this statement is contained in. See the <tt><a href="#ref_import" title="import">import</a></tt>-command for a detailed description or for more about libraries.</p></dd><dt><span class="term"><tt>peek$(&quot;os&quot;)</tt></span></dt><dd><p>This <tt>peek</tt> returns the name of the operating system, where your program executes. This can be either <tt>windows</tt> or <tt>unix</tt>.</p></dd><dt><span class="term"><tt>peek$(&quot;font&quot;)</tt></span></dt><dd><p>Return the name of the font, which is used for text within the graphic window; this value can be specified as the third argument to the <tt><a href="#ref_open_window" title="open window">open window</a></tt>-command.</p></dd><dt><span class="term"><tt>peek$(&quot;env&quot;,&quot;<i><tt>NAME</tt></i>&quot;)</tt></span></dt><dd><p>Return the environment variable specified by <i><tt>NAME</tt></i> (which may be any string expression). Which kind of environment variables are available on your system depends, as well as their meaning, on your system; however typing <b>env</b> on the commandline will produce a list (for Windows and Unix alike). Note, that <tt>peek$(&quot;env&quot;,...)</tt> can be written as <tt>peek$(&quot;environment&quot;,...)</tt> too.</p></dd><dt><span class="term"><tt>peek$(&quot;argument&quot;)</tt></span></dt><dd><p>Return one of the arguments, that have been passed to yabasic at invocation time (the next call will return the the second argument, and so on). E.g. if yabasic has been called like this: <tt>yabasic foo.yab bar baz</tt>, then the first call to <tt>peek$(&quot;argument&quot;)</tt> will return <tt>bar</tt>. This is because <tt>foo.yab</tt> is treated as the name of the program to run, whereas <tt>bar</tt> and <tt>baz</tt> are considered arguments to this program, which are passed on the commandline. The second call to <tt>peek$(&quot;argument&quot;)</tt> will return <tt>baz</tt>. <span class="emphasis"><i>Note</i></span>, that for windows-users, who tend to click on the icon (as opposed to starting yabasic on the command line), this <tt>peek</tt>will mostly return the empty string.</p><p>Note, that <tt>peek$(&quot;argument&quot;)</tt> can be written as <tt>peek$(&quot;arguments&quot;)</tt>.</p><p>Finally you will want to check out the corresponding function <tt><a href="#ref_peek" title="peek">peek(&quot;argument&quot;)</a></tt>.</p></dd></dl></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;You have supplied these arguments: &quot;
while(peek(&quot;argument&quot;))
print peek(&quot;argument&quot;),peek$(&quot;argument&quot;)
wend
</pre><p>If you save this program in a file <tt>foo.yab</tt> and execute it via <b><tt>yabasic t.yab a b c</tt></b> (for windows users: please use the commandline for this), your will get this output:</p><pre class="screen">
3a
2b
1c
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_peek" title="peek">peek</a></tt>, <tt><a href="#ref_poke" title="poke">poke</a></tt>, <tt><a href="#ref_open" title="open">open</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_pi"></a>pi</h1><div class="refnamediv"><h2>Name</h2><p>pi &#8212; a constant with the value <tt>3.14159</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print pi
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>pi</tt> is <tt>3.14159265359</tt> (well at least for yabasic); do not try to assign to pi (e.g. <tt>pi=22/7</tt>) this would not only be mathematically dubious, but would also result in a syntax error.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 180
print &quot;The sine of &quot;,a,&quot; degrees is &quot;,sin(a*pi/180)
next a
</pre><p>This program uses <tt>pi</tt> to transform an angle from degrees into radians.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_euler" title="euler">euler</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_poke"></a>poke</h1><div class="refnamediv"><h2>Name</h2><p>poke &#8212; change selected internals of yabasic</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
poke &quot;foo&quot;,&quot;bar&quot;
poke &quot;foo&quot;,baz
poke #a,&quot;bar&quot;
poke #a,baz
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>poke</tt>-command may be used to change details of yabasics behaviour. Like the related function <tt>peek</tt>, <tt>poke</tt> does many different things, depending on the arguments supplied.</p><p>Here are the different things you can do with <tt>poke</tt>:</p><div class="variablelist"><dl><dt><span class="term"><tt>poke &quot;textalign&quot;,&quot;cc&quot;</tt></span></dt><dd><p>This <tt>poke</tt> changes the <span class="emphasis"><i>default</i></span> alignment of text with respect to the coordinates supplied within the <tt>text</tt>-command. However, this value does <span class="emphasis"><i>not apply</i></span>, if the <tt>text</tt>-command explicitly specifies an alignment. The second argument (<tt>&quot;cc&quot;</tt> in the example) must always be two characters long; the first character can be one of <tt>l</tt> (<i>left</i>), <tt>r</tt> (<i>right</i>) or <tt>c</tt> (<i>center</i>); the second character can be either <tt>t</tt> (<i>top</i>), <tt>b</tt> (<i>bottom</i>) or <tt>c</tt> (<i>center</i>); see the corresponding <tt><a href="#ref_peek2" title="peek$">peek$(&quot;textalign&quot;)</a></tt> for a detailed description of this argument.</p></dd><dt><span class="term"><tt>poke &quot;windoworigin&quot;,&quot;lt&quot;</tt></span></dt><dd><p>This <tt>poke</tt> moves the origin of the coordinate system of the window to the specified position. The second argument (<tt>&quot;lt&quot;</tt> in the example) must always be two characters long; the first character can be one of <tt>l</tt> (<i>left</i>), <tt>r</tt> (<i>right</i>) or <tt>c</tt> (<i>center</i>); the second character can be either <tt>t</tt> (<i>top</i>), <tt>b</tt> (<i>bottom</i>) or <tt>c</tt> (<i>center</i>). Together those two characters specify the new position of the coordinate-origin. See the corresponding <tt><a href="#ref_peek2" title="peek$">peek$(&quot;windoworigin&quot;)</a></tt> for a more in depth description of this argument.</p></dd><dt><span class="term"><tt>poke &quot;infolevel&quot;,&quot;debug&quot;</tt></span></dt><dd><p>Change the amount of internal information, that yabasic outputs during execution.</p><p>The second argument can be either <tt>&quot;debug&quot;</tt>, <tt>&quot;note&quot;</tt>, <tt>&quot;warning&quot;</tt>, <tt>&quot;error&quot;</tt> or <tt>&quot;fatal&quot;</tt>. However, normally you will not want to change this from its default value <tt>&quot;warning&quot;</tt>.</p><p>See also the related <tt><a href="#ref_peek2" title="peek$">peek$(&quot;infolevel&quot;)</a></tt>.</p></dd><dt><span class="term"><tt>poke #1,a</tt></span></dt><dd><p>Write the given byte (<tt>a</tt> in the example above) to the specified stream (<tt>#a</tt> in the example).</p><p>See also the related function function <tt><a href="#ref_peek" title="peek">peek(#1)</a></tt>.</p></dd></dl></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Hello, now you will see, how much work&quot;
print &quot;a simple for-loop involves ...&quot;
input &quot;Please press return &quot; a$
poke &quot;infolevel&quot;,&quot;debug&quot;
for a=1 to 10:next a
</pre><p>This example only demonstrates one of the many <tt>poke</tt>s, which are described above: The program switches the infolevel to <tt>debug</tt>, which makes yabasic produce a lot of debug-messages during the subsequent <tt>for</tt>-loop.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_peek" title="peek">peek</a></tt>, <tt><a href="#ref_peek2" title="peek$">peek$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_print"></a>print</h1><div class="refnamediv"><h2>Name</h2><p>print &#8212; Write to terminal or file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print &quot;foo&quot;,a$,b
print &quot;foo&quot;,&quot;a$,b;
print #a &quot;foo&quot;,a$
print #a &quot;foo&quot;,a$;
print foo using &quot;##.###&quot;
print reverse &quot;foo&quot;
print at(10,10) a$,b
print @(10,10) a$,b
print color(&quot;red&quot;,&quot;blue&quot;) a$,b
print color(&quot;magenta&quot;) a$,b
print color(&quot;green&quot;,&quot;yellow&quot;) at(5,5) a$,b
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>print</tt>-statement outputs strings or characters, either to your terminal (also known as <i>console</i>) or to an open file.</p><p>To understand all those uses of the <tt>print</tt>-statement, let's go throught the various lines in the synopsis above:</p><div class="variablelist"><dl><dt><span class="term"><tt>print &quot;foo&quot;,a$,b</tt></span></dt><dd><p>Print the string <tt>foo</tt> as well as the contents of the variables <tt>a$</tt> and <tt>b</tt> onto the screen, silently adding a <span class="emphasis"><i>newline</i></span>.</p></dd><dt><span class="term"><tt>print &quot;foo&quot;,a$,b;</tt></span></dt><dd><p>(Note the trailing semicolon !) This statement does the same as the one above; only the implicit <span class="emphasis"><i>newline</i></span> is skipped, which means that the next <tt>print</tt>-statement will append seamlessly.</p></dd><dt><span class="term"><tt>print #a &quot;foo&quot;,a$</tt></span></dt><dd><p>This is the way to write to files. The file with the number <tt>a</tt> must be open already, an implicit <span class="emphasis"><i>newline</i></span> is added. Note the file-number <tt>#a</tt>, which starts with a hash ('<tt>#</tt>') amd is separated from the rest of the statement by a space only. The file-number (contained in the variable <tt>a</tt>) must have been returned by a previous <tt><a href="#ref_open" title="open">open</a></tt>-statement (e.g. <tt>a=open(&quot;bar&quot;)</tt>).</p></dd><dt><span class="term"><tt>print #a &quot;foo&quot;,a$;</tt></span></dt><dd><p>The same as above, but without the implicit <span class="emphasis"><i>newline</i></span>.</p></dd><dt><span class="term"><tt>print foo using &quot;##.###&quot;</tt></span></dt><dd><p>Print the number <tt>foo</tt> with as many digits before and after the decimal dot as given by the number of '<tt>#</tt>'-signs. See the entries for <tt><a href="#ref_using" title="using">using</a></tt> and <tt><a href="#ref_str" title="str$()">str$</a></tt> for a detailed description of this format.</p></dd><dt><span class="term"><tt>print reverse &quot;foo&quot;</tt></span></dt><dd><p>As all the <tt>print</tt>-variants to follow, this form of the <tt>print</tt>-statement can only be issued after <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> has been called. The strings and numbers after the <tt>reverse</tt>-clause are simply printed inverse (compared to the normal <tt>print</tt>-statement).</p></dd><dt><span class="term"><tt>print at(10,10) a$,b</tt></span></dt><dd><p>Print at the specified (x,y)-position. This is only allowed after <tt>clear screen</tt> has been called. You may want to query <tt><a href="#ref_peek2" title="peek$">peek$(&quot;screenwidth&quot;)</a></tt> or <tt><a href="#ref_peek2" title="peek$">peek$(&quot;screenheight&quot;)</a></tt> to learn the actual size of your screen. You may add a semicolon to suppress the implicit newline.</p></dd><dt><span class="term"><tt>print @(10,10) a$,b</tt></span></dt><dd><p>This is exactly the same as above, however, <tt>at</tt> may be written as <tt>@</tt>.</p></dd><dt><span class="term"><tt>print color(&quot;red&quot;,&quot;blue&quot;) at(5,5) a$,b</tt></span></dt><dd><p>Print with the specified fore- (<tt>&quot;red&quot;</tt>) and background (<tt>&quot;blue&quot;</tt>) color (or colour). The possible values are <tt>&quot;black&quot;</tt>, <tt>&quot;white&quot;</tt>, <tt>&quot;red&quot;</tt>, <tt>&quot;blue&quot;</tt>, <tt>&quot;green&quot;</tt>, <tt>&quot;yellow&quot;</tt>, <tt>&quot;cyan&quot;</tt> or <tt>&quot;magenta&quot;</tt>. Again, you need to call <tt>clear screen</tt> first and add a semicolon if you want to suppress the implicit newline.</p></dd><dt><span class="term"><tt>print color(&quot;magenta&quot;) a$,b</tt></span></dt><dd><p>You may specify the foreground color only.</p></dd><dt><span class="term"><tt>print color(&quot;green&quot;,&quot;yellow&quot;) a$,b</tt></span></dt><dd><p>A color and a position (in this sequence, not the other way around) may be specified at once.</p></dd></dl></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
columns=peek(&quot;screenwidth&quot;)
lines=peek(&quot;screenheight&quot;)
dim col$(7)
for a=0 to 7:read col$(a):next a
data &quot;black&quot;,&quot;white&quot;,&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;,&quot;cyan&quot;,&quot;magenta&quot;
for a=0 to 2*pi step 0.1
print colour(col$(mod(i,8))) at(columns*(0.8*sin(a)+0.9)/2,lines*(0.8*cos(a)+0.9)/2) &quot;*&quot;
i=i+1
next a
</pre><p>This example draws a cloured ellipse within the text window.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_at" title="at()">at</a></tt><tt>, <tt><a href="#ref_color" title="color">color</a></tt>, <a href="#ref_input" title="input">input</a></tt>, <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt>, <tt><a href="#ref_using" title="using">using</a></tt>, <tt><a href="#ref_semicolon" title=";">;</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_putbit"></a>putbit</h1><div class="refnamediv"><h2>Name</h2><p>putbit &#8212; draw a rectangle of pixels into the graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 200,200
&#8230;
a$=getbit(20,20,50,50)
&#8230;
putbit a$,30,30
putbit a$ to 30,30
putbit a$,30,30,&quot;or&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>putbit</tt>-command is the counterpart of the <tt><a href="#ref_getbit" title="getbit$()">getbit</a></tt>-function. <tt>putbit</tt> requires a string as returned by the <tt><a href="#ref_getbit" title="getbit$()">getbit</a></tt>-function. Such a string contains a rectangle from the graphic window; the <tt>putbit</tt>-function puts such a rectangular region back into the graphic-window.</p><p>Note, that the <tt>putbit</tt>-command currently accepts a third argument. However only the string value <tt>&quot;or&quot;</tt> is supported here. The effect is, that only those pixel, which are set in the string will be set in the graphic window. Those pixels, which are not set in the string, will not change in the window (as opposed to beeing cleared).</p><p>Note, that the format of the string returned by this function is due to change as soon as yabasic will learn, how to deal with colors.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
c$=&quot;41,41:0000000000000000000000000400000000cff1000000ffff100000ffff700008fffff30008ffffff0008ffffff3008fffffff000fffffff100fffffff700ffffffff10efffffff30cfffffff70cffffffff18ffffffff30ffffffff70effffffff0cffffffff1cffffffff30ffffffff70effffffff0cffffffff18ffffffff30ffffffff70cfffffff708ffffffff00ffffffff10cfffffff100fffffff100effffff3008ffffff3000efffff30008fffff30000cffff100000ffff1000000ff700000000000000000000000000000000000&quot;
open window 200,200
do
x=ran(200)
y=ran(200)
putbit c$,x,y,&quot;or&quot;
loop
</pre><p>This program uses a precanned string (containing the image of a circle) and draws it repeatedly into the graphic-window. The mode <tt>&quot;or&quot;</tt> ensures, that no pixels will be cleared.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_getbit" title="getbit$()">getbit$</a></tt>, <tt><a href="#ref_open_window" title="open window">open window</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_putscreen"></a>putscreen</h1><div class="refnamediv"><h2>Name</h2><p>putscreen &#8212; draw a rectangle of characters into the text terminal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
&#8230;
a$=getscreen$(5,5,10,10)
&#8230;
putscreen a$,7,7
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>putscreen</tt>-command is the counterpart of the <tt><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></tt>-function. <tt>putscreen</tt> requires a string as returned by the <tt><a href="#ref_getscreen" title="getscreen$()">getscreen</a></tt>-function. Such a string contains a rectangular detail from the terminal; the <tt>putscreen</tt>-function puts such a region back into the terminal-window.</p><p>Note, that <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt> must have been called before.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
for a=1 to 200
print color(&quot;red&quot;) &quot;Hallo !&quot;;
print color(&quot;blue&quot;) &quot;Welt !&quot;;
next a
r$=getscreen$(0,0,20,20)
for x=0 to 60
putscreen r$,x,0
sleep 0.1
next x
</pre><p>This example prints the string <tt>&quot;Hallo !Welt !&quot;</tt> all over the screen and then moves a rectangle from one side to the other.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></tt>, <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_r"></a>R</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_ran">ran()</a> - return a random number</dt><dt><a href="#ref_read">read</a> - read data from data-statements</dt><dt><a href="#ref_rectangle">rectangle</a> - draw a rectangle</dt><dt><a href="#ref_redim">redim</a> - create an array prior to its first use. A synonym for dim</dt><dt><a href="#ref_rem">rem</a> - start a comment</dt><dt><a href="#ref_repeat">repeat</a> - start a repeat-loop</dt><dt><a href="#ref_restore">restore</a> - reposition the data-pointer</dt><dt><a href="#ref_return">return</a> - return from a subroutine or a gosub</dt><dt><a href="#ref_reverse">reverse</a> - print reverse (background and foreground colors exchanged)</dt><dt><a href="#ref_right">right$()</a> - return (or change) the right end of a string</dt><dt><a href="#ref_rinstr">rinstr()</a> - find the rightmost occurence of one string within the other</dt><dt><a href="#ref_rtrim">rtrim$()</a> - trim spaces at the right end of a string</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_ran"></a>ran()</h1><div class="refnamediv"><h2>Name</h2><p>ran() &#8212; return a random number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print ran()
x=ran(y)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>ran</tt>-function returns a random number. If no argument is given, the number returned is in the range from 0 to 1; where only 0 is a possible value; 1 will never be returned. If an argument is supplied, the number returned will be in the range from 0 up to this argument, whereas this argument itself is not a possible return value.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
c=peek(&quot;screenwidth&quot;)-1
l=peek(&quot;screenheight&quot;)
dim col$(8)
for a=0 to 7:read col$(a):next a
data &quot;black&quot;,&quot;white&quot;,&quot;red&quot;,&quot;blue&quot;,&quot;green&quot;,&quot;yellow&quot;,&quot;cyan&quot;,&quot;magenta&quot;
do
x=ran(c)
y=l-ran(l*exp(-32*((x/c-1/2)**2)))
i=i+1
print color(col$(mod(i,8))) at(x,y) &quot;*&quot;;
loop
</pre><p>This example will print a cloured bell-curve.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_int" title="int()">int</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_read"></a>read</h1><div class="refnamediv"><h2>Name</h2><p>read &#8212; read data from <tt>data</tt>-statements</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
read a$,a
&#8230;
data &quot;Hello !&quot;,7
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>read</tt>-statement retrieves literal data, which is stored within <tt>data</tt>-statements elsewhere in your program.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
read num
dim col$(num)
for a=1 to num:read col$(a):next a
clear screen
print &quot;These are the colours known to yabasic:\n&quot;
for a=1 to num
print colour(col$(a)) col$(a)
next a
data 8,&quot;black&quot;,&quot;white&quot;,&quot;red&quot;,&quot;blue&quot;
data &quot;green&quot;,&quot;yellow&quot;,&quot;cyan&quot;,&quot;magenta&quot;
</pre><p>This program prints the names of the colors known to yabasic in those very colors.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_data" title="data">data</a>, <tt><a href="#ref_restore" title="restore">restore</a></tt></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_rectangle"></a>rectangle</h1><div class="refnamediv"><h2>Name</h2><p>rectangle &#8212; draw a rectangle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 100,100
rectangle 10,10 to 90,90
rectangle 20,20,80,80
rect 20,20,80,80
box 30,30,70,70
clear rectangle 30,30,70,70
fill rectangle 40,40,60,60
clear fill rectangle 60,60,40,40
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>rectangle</tt>-command (also known as <tt>box</tt> or <tt>rect</tt>, for short) draws a recatangle; it accepts four parameters: The x- and y-coordinates of two facing cornerpoints of the rectangle. With the optional clauses <tt>clear</tt> and <tt>fill</tt> (which may appear both and in any sequence) the rectangle can be cleared and filled respectively.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
c=1
do
for phi=0 to pi step 0.1
if (c) then
rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi)
else
clear rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi)
endif
sleep 0.1
next phi
c=not c
loop
</pre><p>This example draws a nice animated pattern; watch it for a couple of hours, to see how it develops.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_window" title="open window">open window</a></tt>, <tt><a href="#ref_open_printer" title="open printer">open printer</a></tt>, <tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_circle" title="circle">circle</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_redim"></a>redim</h1><div class="refnamediv"><h2>Name</h2><p>redim &#8212; create an array prior to its first use. A synonym for <tt>dim</tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
See the <tt><a href="#ref_dim" title="dim">dim</a></tt>-command.
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>redim</tt>-command does exactly the same as the <tt><a href="#ref_dim" title="dim">dim</a></tt>-command; it is just a <span class="emphasis"><i>synonym</i></span>. <tt>redim</tt> has been around in older versions of basic (not even yabasic) for many years; therefore it is supported in yabasic for compatibility reasons.</p><p>Please refer to the entry for the <tt><a href="#ref_dim" title="dim">dim</a></tt>-command for further information.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_rem"></a>rem</h1><div class="refnamediv"><h2>Name</h2><p>rem &#8212; start a comment</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
rem Hey, this is a comment
# this is a comment too
// even this
print &quot;Not a comment&quot; # This is an error !!
print &quot;Not a comment&quot;:// But this is again a valid comment
print &quot;Not a comment&quot; // even this.
print &quot;Not a comment&quot; rem and this !
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>rem</tt> introduces a comment (like <tt>#</tt> or <tt>//</tt>), that extends up to the end of the line.</p><p>Those comments do not even need a colon ('<tt>:</tt>' infront of them); they (<tt>rem</tt>, <tt>#</tt> and <tt>//</tt>) all behave alike except for <tt>#</tt>, which may only appear at the very beginning of a line; therefore the fourth example in the synopsis above (<tt>print &quot;Not a comment&quot; # This is an error !!</tt>) is indeed an error.</p><p>Note, that <tt>rem</tt> is an abbreviation for <span class="emphasis"><i>remark</i></span>. <tt>remark</tt> however is <span class="emphasis"><i>not</i></span> a valid command in yabasic.</p><p>Finally note, that a comment intoduced with '<tt>#</tt>' may have a special meaning under unix; see the entry for <a href="#ref_hash" title="#">#</a> for details.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
#
rem comments on data structures
# are more useful than
// comments on algorithms.
rem
</pre><p>This program does nothing, but in a splendid and well commented way.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_hash" title="#">#</a></tt>, <tt><a href="#ref_double_slash" title="//">//</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_repeat"></a>repeat</h1><div class="refnamediv"><h2>Name</h2><p>repeat &#8212; start a <tt>repeat</tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
repeat
&#8230;
until (&#8230;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>repeat</tt>-loop executes all the statements up to the final <tt>until</tt>-keyword over and over. The loop is executed as long as the condition, which is specified with the <tt>until</tt>-clause, becomes true. By construction, the statements within the loop are executed at least once.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
x=0
clear screen
print &quot;This program will print the numbers from 1 to 10&quot;
repeat
x=x+1
print x
print &quot;Press any key for the next number, or 'q' to quit&quot;
if (inkey$=&quot;q&quot;) break
until(x=10)
</pre><p>This program is pretty much useless, but self-explanatory.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_until" title="until">until</a></tt>, <tt><a href="#ref_break" title="break">break</a></tt>, <tt><a href="#ref_while" title="while">while</a></tt>, <tt><a href="#ref_do" title="do">do</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_restore"></a>restore</h1><div class="refnamediv"><h2>Name</h2><p>restore &#8212; reposition the <tt>data</tt>-pointer</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
read a,b,c,d,e,f
restore
read g,h,i
restore foo
data 1,2,3
label foo
data 4,5,6
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>restore</tt>-command may be used to <span class="emphasis"><i>reset</i></span> the reading of <tt>data</tt>-statements, so that the next <tt>read</tt>-statement will read data from the first <tt>data</tt>-statement.</p><p>You may specify a <a href="#ref_label" title="label">label</a> with the <tt>restore</tt>-command; in that case, the next <tt>read</tt>-statement will read data starting at the given label. If the label is omitted, reading data will begin with the first <tt>data</tt>-statement within your program.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Which language (german/english) ? &quot; l$
if (instr(&quot;german&quot;,l$)&gt;0) then
restore german
else
restore english
endif
for a=1 to 3
read x,x$
print x,&quot;=&quot;,x$
next a
label english
data 1,&quot;one&quot;,2,&quot;two&quot;,3,&quot;three&quot;
label german
data 1,&quot;eins&quot;,2,&quot;zwei&quot;,3,&quot;drei&quot;
</pre><p>This program asks to select one of those languages known to me (i.e. english or german) and then prints the numbers 1,2 and 3 and their textual equivalents in the chosen language.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_read" title="read">read</a></tt>, <tt><a href="#ref_data" title="data">data</a></tt>, <tt><a href="#ref_label" title="label">label</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_return"></a>return</h1><div class="refnamediv"><h2>Name</h2><p>return &#8212; return from a subroutine or a gosub</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
gosub foo
&#8230;
label foo
&#8230;
return
sub bar(baz)
&#8230;
return quertz
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>return</tt>-statement serves two different (albeit somewhat related) purposes. The probably more important use of <tt>return</tt> is to return control from within a subroutine to the place in your program, where the subroutine has been called. If the subroutine is declared to return a value, the <tt>return</tt>-statement might be accompanied by a string or number, which constitutes the <span class="emphasis"><i>return value</i></span> of the subroutine.</p><p>However, even if the subroutine should return a value, the <tt>return</tt>-statement need not carry a value; in that case the subroutine will return 0 or the empty string (depending on the type of the subroutine). Moreover, feel free to place multiple <tt>return</tt>-statements within your subroutine; it's a nice way of controlling the flow of execution.</p><p>The second (but historcially first) use of <tt>return</tt> is to return to the position, where a prior <tt><a href="#ref_gosub" title="gosub">gosub</a></tt> has left off. In that case <tt>return</tt> may <span class="emphasis"><i>not</i></span> carry a value.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
read a$
if (a$=&quot;&quot;) then
print
end
endif
print mark$(a$),&quot; &quot;;
loop
data &quot;The&quot;,&quot;quick&quot;,&quot;brown&quot;,&quot;fox&quot;,&quot;jumped&quot;
data &quot;over&quot;,&quot;the&quot;,&quot;lazy&quot;,&quot;dog&quot;,&quot;&quot;
sub mark$(a$)
if (instr(lower$(a$),&quot;q&quot;)) return upper$(a$)
return a$
end sub
</pre><p>This example features a subroutine <tt>mark$</tt>, that returns its argument in upper case, if it contains the letter &quot;q&quot;, or unchanged otherwise. In the test-text the word <tt>quick</tt> will end up beeing marked as <tt>QUICK</tt>.</p><p>The example above demonstrates <tt>return</tt> within subroutines; please see <a href="#ref_gosub" title="gosub"><tt>gosub</tt></a> for an example of how to use <tt>return</tt> in this context.</p></div></div><div class="refsect1"><h2>See also</h2><p><a href="#ref_sub" title="sub"><tt>sub</tt></a>, <a href="#ref_gosub" title="gosub"><tt>gosub</tt></a></p></div></div><div class="refentry"><h1 class="title"><a name="ref_reverse"></a>reverse</h1><div class="refnamediv"><h2>Name</h2><p>reverse &#8212; print reverse (background and foreground colors exchanged)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
&#8230;
print reverse &quot;foo&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>reverse</tt> may be used to <tt>print</tt> text in reverse. <tt>reverse</tt> is not a seperate command, but part of the <tt>print</tt>-command; it may be included just after the <tt>print</tt> and can only be issued once that <tt>clear screen</tt> has been issued.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
print &quot;1 &quot;;
c=3
do
prim=true
for a=2 to sqrt(c)
if (frac(c/a)=0) then
prim=false
break
endif
next a
if (prim) then
print
print reverse c;
else
print c;
endif
print &quot; &quot;;
c=c+1
loop
</pre><p>This program prints numbers from 1 on and marks each prime number in reverse.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_at" title="at()">at</a></tt><tt>, <tt><a href="#ref_color" title="color">color</a></tt>, <a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_right"></a>right$()</h1><div class="refnamediv"><h2>Name</h2><p>right$() &#8212; return (<span class="emphasis"><i>or change</i></span>) the right end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print right$(a$,2)
right$(b$,2)=&quot;baz&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>right$</tt>-function requires two arguments (a string and a number) and returns the part from the right end of the string, whose length is specified by its second argument. So, <tt>right$</tt> simply returns the requested number of chars from the right end of the given string.</p><p>Note, that the <tt>right$</tt>-function can be assigned to, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <tt>right$</tt>-function. Note, that that way the <span class="emphasis"><i>length</i></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Please enter a length either in inch or centimeter&quot;
print &quot;please add 'in' or 'cm' to mark the unit.&quot;
input &quot;Length: &quot; a$
if (right$(a$,2)=&quot;in&quot;) then
length=val(a$)*2.56
elsif (right$(a$,2)=&quot;cm&quot;) then
length=val(a$)
else
error &quot;Invalid input: &quot;+a$
endif
</pre><p>This program allows the user to enter a length qulified with a unit (either inch or centimeter).</p><p>This second example demonstrates the capability to <span class="emphasis"><i>assign</i></span> to the <tt>right$</tt>-function.</p><pre class="programlisting">
a$=&quot;Heiho World !&quot;
print a$
right$(a$,7)=&quot;dwarfs.&quot;
print a$
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_right" title="right$()">right$</a></tt> and <tt><a href="#ref_mid" title="mid$()">mid$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_rinstr"></a>rinstr()</h1><div class="refnamediv"><h2>Name</h2><p>rinstr() &#8212; find the rightmost occurence of one string within the other</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
pos=rinstr(&quot;Thequickbrownfox&quot;,&quot;equi&quot;)
pos=rinstr(a$,b$,x)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>rinstr</tt>-function accepts two string-arguments and tries to find the second within the first. However, unlike the <tt><a href="#ref_instr" title="instr()">instr</a></tt>, the <tt>rinstr</tt>-function finds the <span class="emphasis"><i>rightmost</i></span> (or last) occurence of the string; whereas the <tt>instr</tt>-function finds the <span class="emphasis"><i>leftmost</i></span> (or first) occurence. In any case however, the position is counted from the left.</p><p>If you supply a third, numeric argument to the <tt>rinstr</tt>-function, it will be used as a starting point for the search. Therefore <tt>rinstr(&quot;abcdeabcdeabcde&quot;,&quot;e&quot;,8)</tt> will return 5, because the search for an &quot;<tt>e</tt>&quot; starts at position 8 and finds the first one at position 5.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print rinstr(&quot;foofoofoobar&quot;,&quot;foo&quot;)
</pre><p>This simple example will print <tt>7</tt>, because it finds the <span class="emphasis"><i>rightmost</i></span> among the three occurences of <tt>foo</tt> within the string. Note, that</p><div class="informalexample"><pre class="programlisting">
print instr(&quot;foofoofoobar&quot;,&quot;foo&quot;)
</pre></div><p>would have printed <tt>1</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_instr" title="instr()">instr</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_rtrim"></a>rtrim$()</h1><div class="refnamediv"><h2>Name</h2><p>rtrim$() &#8212; trim spaces at the right end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=rtrim$(b$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>rtrim$</tt>-function removes all wthitespace from the right end of a string and returns the result.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open 1,&quot;foo&quot;
dim lines$(100)
l=1
while(not eof(1))
input #1 a$
a$=rtrim$(a$)
if (right$(line$,1)=&quot;\\&quot;) then
line$=line$+&quot; &quot;+a$
else
lines$(l)=line$
l=l+1
line$=a$
endif
end while
print &quot;Read &quot;,l,&quot; lines&quot;
</pre><p>This example reads the file <tt>foo</tt> allowing for <span class="emphasis"><i>continuation lines</i></span>, which are marked by a <tt>\</tt>, which appears as the last character on a line. For convenience whitespace at the right end of a line is trimmed with <tt>rtrim</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_ltrim" title="ltrim$()">ltrim$</a></tt>, <tt><a href="#ref_trim" title="trim$()">trim$</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_s"></a>S</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_screen">screen</a> - as clear screen clears the text window</dt><dt><a href="#ref_seek">seek()</a> - change the position within an open file</dt><dt><a href="#ref_sig">sig()</a> - return the sign of its argument</dt><dt><a href="#ref_sin">sin()</a> - return the sine of its single argument</dt><dt><a href="#ref_sleep">sleep</a> - pause, sleep, wait for the specified number of seconds</dt><dt><a href="#ref_split">split()</a> - split a string into many strings</dt><dt><a href="#ref_sqr">sqr()</a> - compute the square of its argument</dt><dt><a href="#ref_sqrt">sqrt()</a> - compute the square root of its argument</dt><dt><a href="#ref_static">static</a> - preserves the value of a variable between calls to a subroutine</dt><dt><a href="#ref_step">step</a> - specifies the increment step in a for-loop</dt><dt><a href="#ref_str">str$()</a> - convert a number into a string</dt><dt><a href="#ref_sub">sub</a> - declare a user defined subroutine</dt><dt><a href="#ref_switch">switch</a> - select one of many alternatives depending on a value</dt><dt><a href="#ref_system">system$()</a> - hand a statement over to your operating system and return its output</dt><dt><a href="#ref_system2">system()</a> - hand a statement over to your operating system and return its exitcode</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_screen"></a>screen</h1><div class="refnamediv"><h2>Name</h2><p>screen &#8212; as <tt>clear screen</tt> clears the text window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
</pre></div><div class="refsect1"><h2>Description</h2><p>The keyword <tt>screen</tt> appears only within the sequence <tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt>; please see there for a description.</p></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_clear_screen" title="clear screen">clear screen</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_seek"></a>seek()</h1><div class="refnamediv"><h2>Name</h2><p>seek() &#8212; change the position within an open file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open 1,&quot;foo&quot;
seek #1,q
seek #1,x,&quot;begin&quot;
seek #1,y,&quot;end&quot;
seek #1,z,&quot;here&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>seek</tt>-command changes the position, where the next <tt>input</tt> (or <tt>peek</tt>) statement will read from an open file. Usually files are read from the beginning to the end sequentially; however sometimes you may want to depart from this simple scheme. This can be done with the <tt>seek</tt>-command, allowing you to change the position, where the next piece of data will be read from the file.</p><p><tt>seek</tt> accepts two or three arguments: The first one is the number of an already open file. The second one is the position where the next read from the file will start. The third argument is optional and specifies the the point from where the position (the second argument) will count. It can be one of:</p><div class="variablelist"><dl><dt><span class="term"><tt>begin</tt></span></dt><dd><p>Count from the beginning of the file.</p></dd><dt><span class="term"><tt>end</tt></span></dt><dd><p>Count from the end of the file.</p></dd><dt><span class="term"><tt>here</tt></span></dt><dd><p>Count from the current position within the file.</p></dd></dl></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,&quot;count.dat&quot;,&quot;w&quot;
for a=1 to 10
print #1,&quot;00000000&quot;;
if (a&lt;10) print #1,&quot;;&quot;;
next a
dim count(10)
do
x=int(ran(10))
i=i+1
if (mod(i,1000)=0) print &quot;.&quot;;
count(x)=count(x)+1
curr$=right$(&quot;00000000&quot;+str$(count(x)),8)
seek #1,9*x,&quot;begin&quot;
print #1,curr$;
loop
</pre><p>This example increments randomly one of ten counters (in the array <tt>count()</tt>); however, the result is always kept and updated within the file <tt>count.dat</tt>, so even in case of an unexpected interrupt, the result will not be lost.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_tell" title="tell">tell</a></tt>, <tt><a href="#ref_open" title="open">open</a></tt>, <tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sig"></a>sig()</h1><div class="refnamediv"><h2>Name</h2><p>sig() &#8212; return the sign of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=sig(b)
</pre></div><div class="refsect1"><h2>Description</h2><p>Return <tt>+1</tt>, <tt>-1</tt> or <tt>0</tt>, if the single argument is positive, negative or zero.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
dim c$(3):c$(1)=&quot;red&quot;:c$(2)=&quot;white&quot;:c$(3)=&quot;green&quot;
do
num=ran(100)-50
print color(c$(2+sig(num))) num
loop
</pre><p>This program prints an infinite sequence of random number; positive numbers are printed in green, negative numbers are printed red (an exact zero would be printed white). (With a little extra work, this program could be easily extended into a brogerage system)</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_abs" title="abs()">abs</a></tt>, <tt><a href="#ref_int" title="int()">int</a></tt>, <tt><a href="#ref_frac" title="frac()">frac</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sin"></a>sin()</h1><div class="refnamediv"><h2>Name</h2><p>sin() &#8212; return the sine of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
y=sin(angle)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>sin</tt>-function expects an angle (in radian, <span class="emphasis"><i>not</i></span> degree) and returns its sine.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
new curve
for phi=0 to 2*pi step 0.1
line to 100+90*sin(phi),100+90*cos(phi)
next phi
close curve
</pre><p>This program draws a circle (ignoring the existence of the <tt><a href="#ref_circle" title="circle">circle</a></tt>-command).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_asin" title="asin()">asin</a></tt>, <tt><a href="#ref_cos" title="cos()">cos</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sleep"></a>sleep</h1><div class="refnamediv"><h2>Name</h2><p>sleep &#8212; pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sleep 4
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>sleep</tt>-command has many different names: You may write <tt>pause</tt>, <tt>sleep</tt> or <tt>wait</tt> interchangable; whatever you write, yabasic will always do exactly the same.</p><p>Therefore you should refer to the entry for the <tt><a href="#ref_pause" title="pause">pause</a></tt>-function for further information.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_split"></a>split()</h1><div class="refnamediv"><h2>Name</h2><p>split() &#8212; split a string into many strings</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim w$(10)
&#8230;
num=split(a$,w$())
num=split(a$,w$(),s$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>split</tt>-function requires a string (containing the text to be split), a <a href="#ref_array_references" title="References on arrays">reference</a> to a string-array (which will receive the resulting strings, i.e. the <span class="emphasis"><i>tokens</i></span>) and an optional string (with a set of characters, at which to split, i.e. the <span class="emphasis"><i>delimiters</i></span>).</p><p>The <tt>split</tt>-function regards its first argument (a string) as a list of <span class="emphasis"><i>tokens</i></span> separated by <span class="emphasis"><i>delimiters</i></span> and it will store the list of tokens within the array-reference you have supplied. Note, that the array, which is passed as a reference (<tt>w$()</tt> in the synopsis), will be resized accordingly, so that you don't have to figure out the number of tokens in advance. The element at position zero (i.e. <tt>w$(0)</tt>) will not be used.</p><p>normally (i.e. if you omit the third, which is the delimiter-argument) the function will regard <span class="emphasis"><i>space</i></span> or <span class="emphasis"><i>tab</i></span> as delimiters for tokens; however by supplying a third argument, you may split at <span class="emphasis"><i>any single</i></span> of the characters within this string. E.g. if you supply <tt>&quot;:;&quot;</tt> as the third argument, then colon (<tt>:</tt>) or semicolon (<tt>;</tt>) will delimit tokens.</p><p>Note, that a sequence of separator-characters will produce a sequence of empty tokens; that way, the number of tokens returned will always be one plus the number of separator characters contained within the string. Refer to the closely related <tt><a href="#ref_token" title="token()">token</a></tt>-function, if you do not like this behaviour. In some way, the <tt>split</tt>-function focuses on the separators (other than the <tt>token</tt>-function, which focuses on the <span class="emphasis"><i>tokens</i></span>), hence its name.</p><p>The second argument is a <a href="#ref_array_references" title="References on arrays">reference</a> on a string-array, where the tokens will be stored; this array will be expanded (or shrinked) to have room for all tokens, if necessary.</p><p>The first argument finally contains the text, that will be split into tokens. The <tt>split</tt>-function returns the number of tokens that have been found.</p><p>Please see the examples below for some hints on the exact behaviour of the <tt>split</tt>-function and how it differs from the <tt>token</tt>-function:</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;This program will help you to understand, how the&quot;
print &quot;split()-function exactly works and how it behaves&quot;
print &quot;in certain special cases.&quot;
print
print &quot;Please enter a line containing tokens separated&quot;
print &quot;by either '=' or '-'&quot;
dim t$(10)
do
print
input &quot;Please enter a line: &quot; l$
num=split(l$,t$(),&quot;=-&quot;)
print num,&quot; Tokens: &quot;;
for a=1 to num
if (t$(a)=&quot;&quot;) then
print &quot;(EMPTY)&quot;;
else
print t$(a);
endif
if (a&lt;num) print &quot;,&quot;;
next a
print
loop
</pre><p>This program prints the following output:</p><p>
<pre class="screen">
Please enter a line: a
1 Tokens: a
Please enter a line:
0 Tokens:
Please enter a line: ab
1 Tokens: ab
Please enter a line: a=b
2 Tokens: a,b
Please enter a line: a-
2 Tokens: a,(EMPTY)
Please enter a line: a-=
3 Tokens: a,(EMPTY),(EMPTY)
Please enter a line: =a-
3 Tokens: (EMPTY),a,(EMPTY)
Please enter a line: a=-b
3 Tokens: a,(EMPTY),b
Please enter a line: a--b-
4 Tokens: a,(EMPTY),b,(EMPTY)
Please enter a line: -a==b-c==
7 Tokens: (EMPTY),a,(EMPTY),b,c,(EMPTY),(EMPTY)
</pre>
</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_token" title="token()">token</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sqr"></a>sqr()</h1><div class="refnamediv"><h2>Name</h2><p>sqr() &#8212; compute the square of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=sqr(b)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>sqr</tt>-function computes the square of its numerical argument (i.e. it multiplies its argument with itself).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
print a,sqr(a),a**2
next a
</pre><p>As you may see from the output, <tt>sqr</tt> can be written as <tt>**2</tt> (or <tt>^2</tt>) too.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sqrt" title="sqrt()">sqrt</a></tt>, <tt><a href="#ref_pow" title="** or ^">**</a></tt>, <tt><a href="#ref_pow" title="** or ^">^</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sqrt"></a>sqrt()</h1><div class="refnamediv"><h2>Name</h2><p>sqrt() &#8212; compute the square root of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">to be written</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>sqrt</tt>-function computes the square root of its numerical argument.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 5
print a,sqrt(a),a**(1/2)
next a
</pre><p>As you may see from the output, <tt>sqrt</tt> can be written as <tt>**(1/2)</tt> (or <tt>^(1/2)</tt>) too.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sqr" title="sqr()">sqr</a></tt>, <tt><a href="#ref_pow" title="** or ^">**</a></tt>, <tt><a href="#ref_pow" title="** or ^">^</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_static"></a>static</h1><div class="refnamediv"><h2>Name</h2><p>static &#8212; preserves the value of a variable between calls to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo()
static a
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>static</tt> keyword can be used within subroutines to mark variables as <span class="emphasis"><i>static</i></span>. This has two effects: First, the variable is <span class="emphasis"><i>local</i></span> to the subroutine, i.e. its value is not know outside the subroutine (this is the effect of the <tt><a href="#ref_local" title="local">local</a></tt> keyword). Second, the <tt>static</tt>-keyword arranges things, so that the variable keeps its value between invocations of the subroutine (this is different from the <tt>local</tt>-keyword).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
foo()
foo()
foo()
sub foo()
static a
local b
a=a+1
b=b+1
print a,b
end sub
</pre><p>This program shows the difference between <tt>static</tt> and <tt>local</tt> variables within a subroutine; it produces this output:</p><p>
<pre class="screen">1 1
2 1
3 1
</pre>
</p><p>The output shows, that the <tt>static</tt> variable <tt>a</tt> keeps its value between subroutine calls, whereas <tt>b</tt> is initialized with the value 0 at every call to the subroutine <tt>foo</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sub" title="sub">sub</a></tt>, <tt><a href="#ref_local" title="local">local</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_step"></a>step</h1><div class="refnamediv"><h2>Name</h2><p>step &#8212; specifies the increment step in a for-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 10 step 3
&#8230;
next a
</pre></div><div class="refsect1"><h2>Description</h2><p>Specify, by which amount the loop-variable of a <tt><a href="#ref_for" title="for">for</a></tt>-loop will be incremented at each step.</p><p>The <tt>step</tt> (as well as the lower and upper bound) are computed anew in each step; this is not common, but possible, as the example below demonstrates.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for x=1 to 1000 step y
y=x+y
print x,&quot; &quot;,y,&quot; &quot;;
next x
print
</pre><p>This program computes the fibonacci numbers between 1 and 1000.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_for" title="for">for</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_str"></a>str$()</h1><div class="refnamediv"><h2>Name</h2><p>str$() &#8212; convert a number into a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=str$(a)
b$=str$(x,&quot;##.###&quot;)
b$=str$(x,&quot;###,###.##&quot;)
b$=str$(x,&quot;###,###.##&quot;,&quot;_.&quot;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>str$</tt>-function accepts a numeric argument and returns it as a string. This conversion between number and string can be controlled with the optional third argument (the <span class="emphasis"><i>format</i></span> argument). See the following table of examples to learn about valid values of this argument. Note, that those examples fall in one of two categories: <span class="emphasis"><i>C-style</i></span> and <span class="emphasis"><i>basic-style</i></span>; the first 4 examples in the table below are C-style, the rest of the examples are basic-style. For more information on the C-style formats, you may refer to your favorite documentation on the C programming language. The basic-style formats are much simpler, they just depict the desired output, marking digits with '<tt>#</tt>'; groups of (usually three) digits may be separated with colons ('<tt>,</tt>'), the decimal dot must be marked by a literal dot ('<tt>.</tt>'). Moreover these characters (colons and dot) may be replaced by other characters to satisfy the needs of non-english (e.g. german) languages; see the examples below.</p><p>Note, that for clarity, each space in the result has been replaced by the letter 'x', because it would be hard to figure out, how many spaces are produced <span class="emphasis"><i>exactly</i></span> otherwise.</p><div class="table"><p><b>Table 6.2. Examples for the format argument</b></p><table summary="Examples for the format argument" border="1"><colgroup><col><col></colgroup><thead><tr><th><tt>Example string</tt></th><th><tt>Result for converting 1000*<tt>pi</tt></tt></th><th><tt>Description</tt></th></tr></thead><tbody><tr><td><tt>%2.5f</tt></td><td><tt>3141.59265</tt></td><td>The '<tt>2</tt>' determines the minimum length of the output; but if needed (as in the example) the output can be longer. The '<tt>5</tt>' is the number of digits after the decimal point.</td></tr><tr><td><tt>%12.5f</tt></td><td><tt>xx3141.59265</tt></td><td>Two spaces (which appear as '<tt>x</tt>') are added to pad the output to the requested length of 12 characters.</td></tr><tr><td><tt>%012.5g</tt></td><td><tt>0000003141.6</tt></td><td>The '<tt>g</tt>' requests, that the precision ('<tt>5</tt>') specifies the <span class="emphasis"><i>overall</i></span> number of digits (before and after the decimal point).</td></tr><tr><td><tt>%-12.5f</tt></td><td><tt>3141.59265xx</tt></td><td>The '<tt>-</tt>' requests the output to be left-centered (therefor the filling space appears at thi right).</td></tr><tr><td><tt>#####.##</tt></td><td><tt>x3141.59</tt></td><td>Each '<tt>#</tt>' specifies a digit (either before or after the dot), the '<tt>.</tt>' specifies the position of the dot. As 1000*<tt>pi</tt> does not have enough digits, the 5 requested digits before the dot are filled up with a space (which shows up as an '<tt>x</tt>').</td></tr><tr><td><tt>##,###.##</tt></td><td><tt>x3,141.59</tt></td><td>Nearly the same as above, but the colon from the format shows up within the result.</td></tr><tr><td><tt>##,###.##</tt> and an <span class="emphasis"><i>addtional</i></span> argument of <tt>&quot;.,&quot;</tt></td><td><tt>x3.141,59</tt></td><td>Similar to the example above, but colon and dot are replaced with dot and colon respectivly.</td></tr><tr><td><tt>##,###.##</tt> and an <span class="emphasis"><i>addtional</i></span> argument of <tt>&quot;_,&quot;</tt></td><td><tt>x3_141,59</tt></td><td>Similar to the example above, but colon and dot are replaced with underscore and colon respectivly.</td></tr><tr><td><tt>#####</tt></td><td><tt>x3142</tt></td><td>The format string does not contain a dot, and therefore the result does not have any fractional digits.</td></tr><tr><td><tt>##.###</tt></td><td><tt>##.###</tt></td><td>As 1000*<tt>pi</tt> has 4 digits infront of the decimal dot and the format only specifies 2, yabasic does not know what to do; therefore it chooses just to reproduce the format string.</td></tr></tbody></table></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
input &quot;Please enter a format string: &quot; f$
a$=str$(1000*pi,f$)
for a=1 to len(a$)
if (mid$(a$,a,1)=&quot; &quot;) mid$(a$,a,1)=&quot;x&quot;
next a
print a$
loop
</pre><p>This is the program, that has been used to get the results shown in the table above.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_using" title="using">using</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_sub"></a>sub</h1><div class="refnamediv"><h2>Name</h2><p>sub &#8212; declare a user defined subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo(2,&quot;hello&quot;)
&#8230;
sub foo(bar,baz$)
&#8230;
return qux
&#8230;
end sub
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>sub</tt>-keyword starts the definition of a <span class="emphasis"><i>user defined subroutine</i></span>. With user defined subroutines you are able to somewhat extend yabasic with your own commands or functions. A subroutine accepts arguments (numbers or strings) and returns a number or a string (however, you are not required to assign the value returned to a variable).</p><p>The name of the subroutine follows after the keyword <tt>sub</tt>. If the name (in the synopsis: <tt>foo</tt>) ends on a '<tt>$</tt>', the subroutine should return a string (with the <tt><a href="#ref_return" title="return">return</a></tt>-statement), otherwise a number.</p><p>After the name of the subroutine yabasic requires a pair of braces; within those braces you may specify a list of parameters, for which values can (but need not) be included when calling the subroutine. If you omit one of those parameters when calling such a subroutine, it assumes the value zero (for numeric parameters) or the empty string (for string-parameters). However with <tt><a href="#ref_peek" title="peek">peek(&quot;argument&quot;)</a></tt> you may find out, how many arguments have really been passed while calling the subroutine.</p><p>Parameters of a subroutine are always local variables (see the keyword <tt><a href="#ref_local" title="local">local</a></tt> for more explanation).</p><p>From within the subroutine you may return any time with the keyword <tt><a href="#ref_return" title="return">return</a></tt>; along with the <tt>return</tt>-keyword you may specify the return value. Note that more than one <tt>return</tt> is allowed within a single subroutine.</p><p>Finally, the keyword <tt>end sub</tt> ends the subroutine definition. Note, that the definition of a subroutine <span class="emphasis"><i>need not</i></span> appear within the program <span class="emphasis"><i>before</i></span> the first call to this sub.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>As <span class="emphasis"><i>braces</i></span> have two uses in yabasic (i.e. for supplying arguments to a subroutine as well as to list the indices of an array). yabasic can not tell apart an array from a subroutine with the same name. Therefore you <span class="emphasis"><i>cannot</i></span> define a subroutine with the same name as an array !</p></div></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
p=2
do
if (is_prime(p)) print p
p=p+1
loop
sub is_prime(a)
local b
for b=2 to sqrt(a)
if (frac(a/b)=0) return false
next b
return true
end sub
</pre><p>This example is not the recommended way to compute prime numbers. However it gives a nice demonstration of using a subroutine.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_local" title="local">local</a></tt>, <tt><a href="#ref_static" title="static">static</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_switch"></a>switch</h1><div class="refnamediv"><h2>Name</h2><p>switch &#8212; select one of many alternatives depending on a value</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a
case 1
case 2
&#8230;
end switch
&#8230;
switch a$
case &quot;a&quot;
case &quot;b&quot;
end switch
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>switch</tt>-statment selects one of many codepaths depending on a numerical or string expression. I.e. it takes an expression (either numeric or string) and compares it with a series of values, each wrapped within a <tt><a href="#ref_case" title="case">case</a></tt>-clause. If the expression equals the value given in a <tt>case</tt>-clause, the subsequent statements are executed.</p><p>The <tt><a href="#ref_default" title="default">default</a></tt>-clause allows to specify commands, which should be executed, if none of <tt>case</tt>-clauses matches.</p><p>Note, that many <tt>case</tt>-clauses might be clustered (e.g. <tt>case &quot;a&quot;:case &quot;b&quot;:case &quot;c&quot;</tt>). Or put another way: You need a <tt>break</tt>-statement at the end of a <tt>case</tt>-branch, if you do not want to run into the next <tt>case</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a single digit: &quot; n
switch n
case 0:print &quot;zero&quot;:break
case 1:print &quot;one&quot;:break
case 2:print &quot;two&quot;:break
case 3:print &quot;three&quot;:break
case 4:print &quot;four&quot;:break
case 5:case 6: case 7:case 8:case 9
print &quot;Much !&quot;:break
default:print &quot;Hey ! That was more than a single digit !&quot;
end switch
</pre><p>This example translates a single digit into a string; note, how the cases 5 to 7 are clustered.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_switch" title="switch">switch</a></tt>, <tt><a href="#ref_case" title="case">case</a></tt>, <tt><a href="#ref_break" title="break">break</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_system"></a>system$()</h1><div class="refnamediv"><h2>Name</h2><p>system$() &#8212; hand a statement over to your operating system and return its output</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print system$(&quot;dir&quot;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>system$</tt>-command accepts a single string argument, specifying a command, that can be found and executed by your operating system. It returns the output of this command as one big string.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter the name of a directory: &quot; d$
print
print &quot;This is the contents of the '&quot;+d$+&quot;':&quot;
print system$(&quot;dir &quot;+d$)
</pre><p>This example lists the contents of a directory, employing the dir-command (which is about the only program, that is known under Unix as well as Windows).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_system" title="system$()">system</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_system2"></a>system()</h1><div class="refnamediv"><h2>Name</h2><p>system() &#8212; hand a statement over to your operating system and return its exitcode</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
ret=system(&quot;foo&quot;)
system(&quot;bar&quot;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>system</tt>-command accepts a single string argument, which specifies a command to be executed. The function will return the exitcode of the command; its output (if any) will be lost.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Please enter the name of the file, that should be deleted.&quot;
input f$
if (system(&quot;rm &quot;+f$+&quot; &gt;/dev/null 2&gt;&amp;1&quot;)) then
print &quot;Error !&quot;
else
print &quot;okay.&quot;
endif
</pre><p>This program is Unix-specific: It uses the Unix-command <tt>rm</tt> to remove a file.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_system2" title="system()">system$</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_t"></a>T</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_tan">tan()</a> - return the tangens of its argument</dt><dt><a href="#ref_tell">tell</a> - get the current position within an open file</dt><dt><a href="#ref_text">text</a> - write text into your graphic-window</dt><dt><a href="#ref_then">then</a> - tell the long from the short form of the if-statement</dt><dt><a href="#ref_time">time$</a> - return a string containing the current time</dt><dt><a href="#ref_to">to</a> - this keyword appears as part of other statements</dt><dt><a href="#ref_token">token()</a> - split a string into multiple strings</dt><dt><a href="#ref_trim">trim$()</a> - remove leading and trailing spaces from its argument</dt><dt><a href="#ref_true">true</a> - a constant with the value of 1</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_tan"></a>tan()</h1><div class="refnamediv"><h2>Name</h2><p>tan() &#8212; return the tangens of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo=tan(bar)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>tan</tt>-function computes the tangens of its arguments (which should be specified in radian).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 45
print tan(a*pi/180)
next a
</pre><p>This example simply prints the tangens of all angles between 0 and 45 degree.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_atan" title="atan()">atan</a></tt>, <tt><a href="#ref_sin" title="sin()">sin</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_tell"></a>tell</h1><div class="refnamediv"><h2>Name</h2><p>tell &#8212; get the current position within an open file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open #1,&quot;foo&quot;
&#8230;
position=tell(#1)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>tell</tt>-function requires the number of an open file as an argument. It returns the position (counted in bytes, starting from the beginning of the file) where the next read will start.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,&quot;foo&quot;,&quot;w&quot;
print #1 &quot;Hello World !&quot;
close #1
open #1,&quot;foo&quot;
seek #1,0,&quot;end&quot;
print tell(#1)
close 1
</pre><p>This example (mis)uses <tt>tell</tt> to get the size of the file. The <tt>seek</tt> positions the file pointer at the end of the file, therefor the call to <tt>tell</tt> returns the total length of the file.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_tell" title="tell">tell</a></tt>, <tt><a href="#ref_open" title="open">open</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_text"></a>text</h1><div class="refnamediv"><h2>Name</h2><p>text &#8212; write text into your graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
text x,y,&quot;foo&quot;
text x,y,&quot;foo&quot;,&quot;l&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>text</tt>-function displays a text-string (the third argument) at the given position (the first two arguments) within an already <tt><a href="#ref_open_window" title="open window">open</a></tt>ed <tt><a href="#ref_open_window" title="open window">window</a></tt>. There is no way to specify a font for the text, that will be written (this font can only be specified once, as an argument to the <tt><a href="#ref_open_window" title="open window">open window</a></tt>-statement).</p><p>The fourth, optional argument can be used to specify the alignment of the text with respect to the specified position. This argument is always two characters long: The first character specifies the horizontal alignment and can be either <tt>l</tt>, <tt>r</tt> or <tt>c</tt>, which stand for <i>left</i>, <i>right</i> or <i>center</i>. The second character specifies the vertical alignment and can be one of <tt>t</tt>, <tt>b</tt> or <tt>c</tt>, which stand for <i>top</i>, <i>bottom</i> or <i>center</i> respectively. If you omit this alignment argument, the default <tt>&quot;lb&quot;</tt> applies; however this default may be changed with <tt><a href="#ref_poke" title="poke">poke &quot;textalign&quot;,&quot;xx&quot;</a></tt></p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 500,200
clear screen
data &quot;lt&quot;,&quot;lc&quot;,&quot;lb&quot;,&quot;ct&quot;,&quot;cc&quot;,&quot;cb&quot;,&quot;rt&quot;,&quot;rc&quot;,&quot;rb&quot;
for a=1 to 9
read align$
print &quot;Alignment: &quot;,align$
line 50*a-15,100,50*a+15,100
line 50*a,85,50*a,115
text 50*a,100,&quot;Test&quot;,align$
inkey$
next a
</pre><p>This program draws nine crosses and writes the same text at each; however it goes through all possible nine alignment strings, showing their effect.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_window" title="open window">open window</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt>, <tt><a href="#ref_poke" title="poke">poke</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_then"></a>then</h1><div class="refnamediv"><h2>Name</h2><p>then &#8212; tell the long from the short form of the <tt>if</tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a&lt;b) then
&#8230;
endif
</pre></div><div class="refsect1"><h2>Description</h2><p>The keyword <tt>then</tt> is part of the <tt><a href="#ref_if" title="if">if</a></tt>-statement; please see there for further explanations. However, not every <tt>if</tt>-statement requires the keyword <tt>then</tt>: If the keyword <tt>then</tt> is present, the <tt>if</tt>-clause may extend over more than one line, and the keyword <tt>endif</tt> is required to end it. If the keyword <tt>then</tt> is <span class="emphasis"><i>not</i></span> present, the <tt>if</tt>-statement extends up to the end of the line, and any <tt>endif</tt> would be an error.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (1&lt;2) then
print &quot;Hello &quot;;
endif
if (2&lt;3) print &quot;world&quot;
if (2&lt;1)
print &quot;!&quot;
</pre><p>This example prints <tt>Hello world</tt>. Note, that no exclamation mark (<tt>!</tt>) is printed, which might come as a surprise and may be changed in future versions of yabasic.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_if" title="if">if</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_time"></a>time$</h1><div class="refnamediv"><h2>Name</h2><p>time$ &#8212; return a string containing the current time</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print time$
print time$()
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>time$</tt> function returns the current time in four fields separated by hyphens '<tt>-</tt>'. The fields are:</p><p>
<div class="itemizedlist"><ul><li><p>The current hour in the range from 0 to 23, padded with zeroes (e.g. <tt>00</tt> or <tt>04</tt>) to a length of two characters.</p></li><li><p>The number of minutes, padded with zeroes.</p></li><li><p>The number of seconds, padded with zeroes.</p></li><li><p>The number of seconds, that have elapsed since the program has been started. This value encreases as long as your program runs and is therefore unbound and not padded with zeroes.</p></li></ul></div>
</p><p>At the time of writing this documentation, <tt>time$</tt> returns <tt>22-58-53-0</tt>. Note, that the first three of the four fields returned by <tt>time$</tt> have a fixed width; therefore it is easy to extract some fields with the usual string-functions <tt><a href="#ref_mid" title="mid$()">mid$</a></tt> (and others).</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Hello it is &quot;,time$
print &quot;An empty for-loop with ten million iterations takes &quot;;
s=val(mid$(time$,10))
for a=1 to 10000000:next a
e=val(mid$(time$,10))
print e-s,&quot; seconds&quot;
</pre><p>This program benchmarks the <tt>for</tt>-loop and uses the fourth field of the string returned by <tt>time$</tt>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_date" title="date$">date</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_to"></a>to</h1><div class="refnamediv"><h2>Name</h2><p>to &#8212; this keyword appears as part of other statements</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 100 step 2
&#8230;
next a
line x,y to a,b
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>to</tt>-keyword serves two purposes (which are not related at all):</p><div class="itemizedlist"><ul><li><p>within <tt><a href="#ref_for" title="for">for</a></tt>-statements, to specify the upper bound of the loop.</p></li><li><p>Within any graphical command (e.g. <tt>line</tt>), that requires two points (i.e. four numbers) as arguments, a comma '<tt>,</tt>' might be replaced with the keyword <tt>to</tt>. I.e. instead of <tt>100,100,200,200</tt> you may write <tt>100,100 to 200,200</tt> in such commands.</p></li></ul></div></div><div class="refsect1"><h2>Example</h2><p>Pleas see the command listed under &quot;See also&quot; for examples.</p></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_for" title="for">for</a></tt>, <tt><a href="#ref_line" title="line">line</a></tt>, <tt><a href="#ref_rectangle" title="rectangle">rectangle</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_token"></a>token()</h1><div class="refnamediv"><h2>Name</h2><p>token() &#8212; split a string into multiple strings</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim w$(10)
&#8230;
num=token(a$,w$())
num=token(a$,w$(),s$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>token</tt>-function accepts a string (containing the text to be split), a <a href="#ref_array_references" title="References on arrays">reference</a> to a string-array (which will receive the resulting strings, i.e. the <span class="emphasis"><i>tokens</i></span>) and an optional string (with a set of characters, at which to split, i.e. the <span class="emphasis"><i>delimiters</i></span>).</p><p>The <tt>token</tt>-function regards its first argument as a list of <span class="emphasis"><i>tokens</i></span> separated by <span class="emphasis"><i>delimiters</i></span> and it will store the list of tokens within the array-reference that has been supplied. Note, that the array, which is passed as a reference (<tt>w$()</tt> in the synopsis), will be resized accordingly, so that you don't have to figure out the number of tokens in advance. The element at position zero (i.e. <tt>w$(0)</tt>) will not be used.</p><p>Normally (i.e. if you omit the third, the delimiter-argument) the function will regard <span class="emphasis"><i>space</i></span> or <span class="emphasis"><i>tab</i></span> as delimiters for tokens; however by supplying a third argument, you may split at <span class="emphasis"><i>any single</i></span> of the characters within this string. E.g. if you supply <tt>&quot;:;&quot;</tt> as the third argument, then colon (<tt>:</tt>) or semicolon (<tt>;</tt>) will delimit tokens.</p><p>Note, that <tt>token</tt> will never produce empty tokens, even if two or more separators follow in sequence. Refer to the closely related <tt><a href="#ref_token" title="token()">split</a></tt>-function, if you do not like this behaviour. In some way, the <tt>token</tt>-function focuses on the tokens and not on the separators (other than the <tt>split</tt>-function, which focuses on the separators).</p><p>The second argument is a <a href="#ref_array_references" title="References on arrays">reference</a> on a string-array, where the tokens will be stored; this array will be expanded (or shrinked) as necessary to have room for all tokens.</p><p>The first argument finally contains the text, that will be split into tokens. The <tt>token</tt>-function returns the number of tokens, that have been found.</p><p>Please see the examples below for some hints on the exact behaviour of the <tt>token</tt>-function and how it differs from the <tt>split</tt>-function:</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;This program will help you to understand, how the&quot;
print &quot;token()-function exactly works and how it behaves&quot;
print &quot;in certain special cases.&quot;
print
print &quot;Please enter a line containing tokens separated&quot;
print &quot;by either '=' or '-'&quot;
dim t$(10)
do
print
input &quot;Please enter a line: &quot; l$
num=token(l$,t$(),&quot;=-&quot;)
print num,&quot; Tokens: &quot;;
for a=1 to num
if (t$(a)=&quot;&quot;) then
print &quot;(EMPTY)&quot;;
else
print t$(a);
endif
if (a&lt;num) print &quot;,&quot;;
next a
print
loop
</pre>
This program prints the following output:
<p>
<pre class="screen">
Please enter a line: a
1 Tokens: a
Please enter a line:
0 Tokens:
Please enter a line: ab
1 Tokens: ab
Please enter a line: a=b
2 Tokens: a,b
Please enter a line: a-
1 Tokens: a
Please enter a line: a-=
1 Tokens: a
Please enter a line: =a-
1 Tokens: a
Please enter a line: a=-b
2 Tokens: a,b
Please enter a line: a--b-
2 Tokens: a,b
Please enter a line: -a==b-c==
3 Tokens: a,b,c
</pre>
</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_split" title="split()">split</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_trim"></a>trim$()</h1><div class="refnamediv"><h2>Name</h2><p>trim$() &#8212; remove leading and trailing spaces from its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=trim$(b$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>trim$</tt>-function removes all whitespaces from the left and from the right end of a string and returns the result. Calling <tt>trim$</tt> is equivalent to calling <tt>rtrim$(ltrim$())</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
input &quot;Continue ? Please answer yes or no: &quot; a$
a$=lower$(trim$(a$))
if (len(a$)&gt;0 and a$=left$(&quot;no&quot;,len(a$)) exit
loop
</pre><p>This example asks for an answer (<tt>yes</tt> or <tt>no</tt>) and removes spaces with <tt>trim$</tt> to make the comparison with the string <tt>&quot;no&quot;</tt> more bulletproof.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_ltrim" title="ltrim$()">ltrim$</a></tt>, <tt><a href="#ref_rtrim" title="rtrim$()">rtrim$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_true"></a>true</h1><div class="refnamediv"><h2>Name</h2><p>true &#8212; a constant with the value of 1</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
okay=true
</pre></div><div class="refsect1"><h2>Description</h2><p>The constant <tt>true</tt> can be assigned to variables which will later appear in conditions (e.g. an <tt>if</tt>-statement.</p><p><tt>true</tt> may also be written as <tt>TRUE</tt> or even <tt>TrUe</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a string of all upper letters: &quot; a$
if (is_upper(a$)) print &quot;Okay&quot;
sub is_upper(a$)
if (a$=upper$(a$)) return true
return false
end sub
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_false" title="false">false</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_u"></a>U</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_until">until</a> - end a repeat-loop</dt><dt><a href="#ref_upper">upper$()</a> - convert a string to upper case</dt><dt><a href="#ref_using">using</a> - Specify the format for printing a number</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_until"></a>until</h1><div class="refnamediv"><h2>Name</h2><p>until &#8212; end a <tt>repeat</tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
repeat
&#8230;
until (&#8230;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>until</tt>-keyword ends a loop, which has been introduced by the <tt><a href="#ref_repeat" title="repeat">repeat</a></tt>-keyword. <tt>until</tt> requires a condition in braces (or an expression, see <a href="#ref_conditions_and_expressions" title="Conditions and expressions">here</a> for details) as an argument; the loop will continue <span class="emphasis"><i>until</i></span> this condition evaluates to true.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
c=1
s=1
repeat
l=c
s=-(s+sig(s))
c=c+1/s
print c
until(abs(l-c)&lt;0.000001)
</pre><p>This program calculates the sequence 1/1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+ &#8230; ; please let me know, if you know against which value this converges.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_repeat" title="repeat">repeat</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_upper"></a>upper$()</h1><div class="refnamediv"><h2>Name</h2><p>upper$() &#8212; convert a string to upper case</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
u$=upper$(a$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>upper$</tt>-function accepts a single string argument and converts it to all upper case.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input &quot;Please enter a sentence without the letter 'e': &quot; l$
p=instr(upper$(l$),&quot;E&quot;)
if (p) then
l$=lower$(l$)
mid$(l$,p,1)=&quot;E&quot;
print &quot;Hey, you are wrong, see here!&quot;
print l$
else
print &quot;Thanks.&quot;
endif
</pre><p>This program asks for a sentence and marks the first (if any) occurence of the letter 'e' by coverting it to upper case (in contrast to the rest of the sentence, which is converted to lower case).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_lower" title="lower$()">lower$</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_using"></a>using</h1><div class="refnamediv"><h2>Name</h2><p>using &#8212; Specify the format for printing a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print a using &quot;##.###&quot;
print a using(&quot;##.###&quot;,&quot;,.&quot;)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>using</tt>-keyword may appear as part of the <tt>print</tt>-statement and specifies the format (e.g. the number of digits before and after the decimal dot), which should be used to print the number.</p><p>The possible values for the format argument (<tt>&quot;##.###&quot;</tt> in the synopsis above) are described within the entry for the <tt><a href="#ref_str" title="str$()">str$</a></tt>-function; especially the second line in the synopsis (<tt>print a using(&quot;##.###&quot;,&quot;,.&quot;)</tt>) will become clear after referring to <tt>str$</tt>. In fact the <tt>using</tt> clause is closely related to the <tt>str$</tt>-function; the former can always be rewritten using the latter; i.e. <tt>print foo using bar$</tt> is always equivalent to <tt>print str$(foo,bar$)</tt>. Therefore you should check out <tt><a href="#ref_str" title="str$()">str$</a></tt> to learn more.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
print sqrt(ran(10000*a)) using &quot;#########.#####&quot;
next a
</pre><p>This example prints a column of square roots of random number, nicely aligned at the decimal dot.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_str" title="str$()">str$</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_v"></a>V</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_val">val()</a> - converts a string to a number</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_val"></a>val()</h1><div class="refnamediv"><h2>Name</h2><p>val() &#8212; converts a string to a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=val(x$)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>val</tt>-function checks, if the start of its string argument forms a floating point number and then returns this number. The string therefore has to start with digits (only whitespace infront is allowed), otherwise the <tt>val</tt>-function returns zero.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a length, either in inches (in) or centimeters (cm) &quot; l$
if (right$(l$,2)=&quot;in&quot;) then
l=val(l$)*2.51
else
l=val(l$)
print &quot;You have entered &quot;,l,&quot;cm.&quot;
</pre><p>This example queries for a length and checks, if it has been specified in inches or centimeters. The length is then converted to centimeters.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_str" title="str$()">str$</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_w"></a>W</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_wait">wait</a> - pause, sleep, wait for the specified number of seconds</dt><dt><a href="#ref_wend">wend</a> - end a while-loop</dt><dt><a href="#ref_while">while</a> - start a while-loop</dt><dt><a href="#ref_origin">window origin</a> - move the origin of a window</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_wait"></a>wait</h1><div class="refnamediv"><h2>Name</h2><p>wait &#8212; pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
wait 4
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>wait</tt>-command has many different names: You may write <tt>pause</tt>, <tt>sleep</tt> or <tt>wait</tt> interchangeable; whatever you write, yabasic will always do exactly the same.</p><p>Therefore you should refer to the entry for the <tt><a href="#ref_pause" title="pause">pause</a></tt>-function for further information.</p></div></div><div class="refentry"><h1 class="title"><a name="ref_wend"></a>wend</h1><div class="refnamediv"><h2>Name</h2><p>wend &#8212; end a <tt><a href="#ref_while" title="while">while</a></tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
while(a&lt;b)
&#8230;
wend
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>wend</tt>-keyword marks the end of a <tt><a href="#ref_while" title="while">while</a></tt>-loop. Please see the <tt><a href="#ref_while" title="while">while</a></tt>-keyword for more details.</p><p><tt>wend</tt> can be written as <tt>end while</tt> or even <tt>end-while</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input &quot;Please enter a sentence: &quot; a$
p=instr(a$,&quot;e&quot;)
while(p)
mid$(a$,p,1)=&quot;E&quot;
p=instr(a$,&quot;e&quot;)
wend
print a$
</pre><p>This example reads a sentence and converts every occurence of the letter <tt>e</tt> into uppercase (<tt>E</tt>).</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_while" title="while">while</a></tt> (which is just the following entry).</p></div></div><div class="refentry"><h1 class="title"><a name="ref_while"></a>while</h1><div class="refnamediv"><h2>Name</h2><p>while &#8212; start a <tt>while</tt>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
while(&#8230;)
&#8230;
wend
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>while</tt>-keyword starts a <tt>while</tt>-loop, i.e. a loop that is excuted as long as the condition (which is specified in braces after the keyword <tt>while</tt>) evaluates to <tt>true</tt>.</p><p>Note, that the body of such a <tt>while</tt>-loop will not be executed at all, if the condition following the <tt>while</tt>-keyword is not true initially.</p><p>If you want to leave the loop prematurely, you may use the <tt><a href="#ref_break" title="break">break</a></tt>-statement.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,&quot;foo&quot;
while(!eof(1))
line input #1 a$
print a$
wend
</pre><p>This program reads the file <tt>foo</tt> and prints it line by line.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_until" title="until">until</a></tt>, <tt><a href="#ref_break" title="break">break</a></tt>, <tt><a href="#ref_wend" title="wend">wend</a></tt>, <tt><a href="#ref_do" title="do">do</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_origin"></a>window origin</h1><div class="refnamediv"><h2>Name</h2><p>origin &#8212; move the origin of a window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 200,200
origin &quot;cc&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>origin</tt>-command applies to graphic windows and moves the origin of the coordinate system to one of nine point within the window. The normal position of the origin is in the upper left corner of the window; however in some cases this is inconvenient and moving the origin may save you from substracting a constant offset from all of your coordinates.</p><p>However, you may not move the origin to an arbitrary position; in horizontal possition there are only three positions: left, center and right, which are decoded by the letters <tt>l</tt>, <tt>c</tt> and <tt>r</tt>. In vertical position the allowed positions are top, center and bottom; encoded by the letters <tt>t</tt>, <tt>c</tt> and <tt>b</tt>. Taking the letters together, you arrive at a string, which might be passed as an argument to the command; e.g. <tt>&quot;cc&quot;</tt> or <tt>&quot;rt&quot;</tt>.</p></div><div class="refsect1"><h2>Example</h2>100,100
<div class="informalexample"><pre class="programlisting">
open window 200,200
window origin &quot;cc&quot;
circle 0,0,60
</pre><p>This example draws a circle, centered at the center of the window.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_open_window" title="open window">open window</a></tt></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_x"></a>X</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_xor">xor()</a> - compute the exclusive or</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_xor"></a>xor()</h1><div class="refnamediv"><h2>Name</h2><p>xor() &#8212; compute the exclusive or</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=xor(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>The <tt>xor</tt> computes the bitwise <span class="emphasis"><i>exclusive or</i></span> of its two numeric arguments. To understand the result, both arguments should be viewed as binary numbers (i.e. a series of 0 and 1); a bit of the result will then be 1, if exactly one argument has a 1 and the other has a 0 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <tt>and</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print xor(7,4)
</pre><p>This will print <tt>3</tt>. This result is obvious, if you note, that the binary representation of 7 and 4 are 111 and 100 respectively; this will yield 011 in binary representaion or 2 as decimal.</p><p>The <tt>eor</tt>-function is the same as the <tt>xor</tt> function; both are synonymous; however they have each their own description, so you may check out the entry of <tt><a href="#ref_eor" title="eor()">eor</a></tt> for a slightly different view.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_arithmetic_and" title="and()">and</a></tt>, <a href="#ref_arithmetic_or" title="or()"><tt>or</tt></a>, <a href="#ref_eor" title="eor()"><tt>eor</tt></a>, <a href="#ref_not" title="not"><tt>not</tt></a></p></div></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_special_characters"></a>Special characters</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_hash">#</a> - either a comment or a marker for a file-number</dt><dt><a href="#ref_double_slash">//</a> - starts a comment</dt><dt><a href="#ref_at_sign">@</a> - synonymous to at</dt><dt><a href="#ref_colon">:</a> - separate commands from each other</dt><dt><a href="#ref_semicolon">;</a> - suppress the implicit newline after a print-statement</dt><dt><a href="#ref_pow">** or ^</a> - raise its first argument to the power of its second</dt></dl></div><div class="refentry"><h1 class="title"><a name="ref_hash"></a>#</h1><div class="refnamediv"><h2>Name</h2><p># &#8212; either a comment or a marker for a file-number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
# This is a comment, but the line below not !
open #1,&quot;foo&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The hash ('<tt>#</tt>') has two totally unrelated uses:</p><div class="itemizedlist"><ul><li><p>A hash might appear in commands related with file-io. yabasic uses simple numbers to refer to open files (within <tt><a href="#ref_input" title="input">input</a></tt>, <tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt> or <tt><a href="#ref_eof" title="eof">eof</a></tt>). In those commands the hash may precede the number, which species the file. Please see those commands for further information and examples; the rest of <span class="emphasis"><i>this</i></span> entry is about the second use (as a comment).</p></li><li><p>As the <span class="emphasis"><i>very first</i></span> character within a line, a hash introduces comments (similar to <tt>rem</tt>).</p></li></ul></div><p> '<tt>#</tt>' as a comment is common in most scripting languages and has a special use under Unix: If the <span class="emphasis"><i>very first line</i></span> of any Unix-program begins with the character sequence '<tt>#!</tt>' (&quot;she-bang&quot;, no spaces allowed), the rest of the line is taken as the program that should be used to execute the script. I.e. if your yabasic-program starts with '<tt>#!/usr/local/bin/yabasic</tt>', the program <tt>/usr/local/bin/yabasic</tt> will be invoked to execute the rest of the program. As a remark for windows-users: This mechanism ensures, that yabasic will be invoked to execute your program; the ending of the file (e.g. <tt>.yab</tt>) will be ignored by Unix.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
# This line is a valid comment
print &quot;Hello &quot; : # But this is a syntax error, because
print &quot;World!&quot; : # the hash is not the first character !
</pre><p>Note, that this example will produce a syntax error and is <span class="emphasis"><i>not</i></span> a valid program !</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_input" title="input">input</a></tt>, <tt><a href="#ref_print" title="print">print</a></tt>, <tt><a href="#ref_peek" title="peek">peek</a></tt> or <tt><a href="#ref_eof" title="eof">eof</a></tt>, <tt><a href="#ref_double_slash" title="//">//</a></tt>, <tt><a href="#ref_rem" title="rem">rem</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_double_slash"></a>//</h1><div class="refnamediv"><h2>Name</h2><p>// &#8212; starts a comment</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
// This is a comment !
</pre></div><div class="refsect1"><h2>Description</h2><p>The double-slash ('<tt>//</tt>') is (besides <tt>REM</tt> and '<tt>#</tt>') the third way to start a comment. '<tt>//</tt>' is the latest and greatest in the field of commenting and allows yabasic to catch up with such cool languages like C++ and Java.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
// Another comment.
print &quot;Hello world !&quot; // Another comment
</pre><p>Unlike the example given for '<tt><a href="#ref_hash" title="#">#</a></tt>' this example is syntactically correct and will not produce an error.</p></div></div><div class="refsect1"><h2>See also</h2><p> <tt><a href="#ref_hash" title="#">#</a></tt>, <tt><a href="#ref_rem" title="rem">rem</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_at_sign"></a>@</h1><div class="refnamediv"><h2>Name</h2><p>@ &#8212; synonymous to <tt><a href="#ref_at" title="at()">at</a></tt></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
&#8230;
print @(a,b)
</pre></div><div class="refsect1"><h2>Description</h2><p>As '<tt>@</tt>' is simply a synonym for <tt>at</tt>, please see <tt><a href="#ref_at" title="at()">at</a></tt> for further information.</p></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_at" title="at()">at</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_colon"></a>:</h1><div class="refnamediv"><h2>Name</h2><p>: &#8212; separate commands from each other</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print &quot;Hello &quot;:print &quot;World&quot;
</pre></div><div class="refsect1"><h2>Description</h2><p>The <span class="emphasis"><i>colon</i></span> ('<tt>:</tt>') separates multiple commands on a single line.</p><p>The <span class="emphasis"><i>colon</i></span> and the <span class="emphasis"><i>newline</i></span>-character have mostly the same effect, only that the latter, well, starts a new line too. The only other difference is their effect within the (so-called) <span class="emphasis"><i>short</i></span> <tt>if</tt>, which is an <tt>if</tt>-statement without the keyword <tt>then</tt>. Please see the entry for <tt><a href="#ref_if" title="if">if</a></tt> for more details.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (a&lt;10) print &quot;Hello &quot;:print &quot;World !&quot;
</pre><p>This example demonstrates the difference between colon and newline as described above.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_if" title="if">if</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_semicolon"></a>;</h1><div class="refnamediv"><h2>Name</h2><p>; &#8212; suppress the implicit newline after a <tt><a href="#ref_print" title="print">print</a></tt>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print &quot;foo&quot;,bar;
</pre></div><div class="refsect1"><h2>Description</h2><p>The semicolon ('<tt>;</tt>') may only appear at the last position within a <tt><a href="#ref_print" title="print">print</a></tt>-statement. It supresses the implicit newline, which yabasic normally adds after each <tt>print</tt>-statement.</p><p>Put another way: Normally the output of each <tt>print</tt>-statement appears on a line by itself. If you rather want the output of many <tt>print</tt>-statements to appear on a single line, you should end the <tt>print</tt>-statement with a semicolon.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print &quot;Hello &quot;;:print &quot;World !&quot;
</pre><p>This example prints <tt>Hello World !</tt> <span class="emphasis"><i>in a single line</i></span>.</p></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_print" title="print">print</a></tt></p></div></div><div class="refentry"><h1 class="title"><a name="ref_pow"></a>** or ^</h1><div class="refnamediv"><h2>Name</h2><p>** or ^ &#8212; raise its first argument to the power of its second</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print 2**b
print 3^4
</pre></div><div class="refsect1"><h2>Description</h2><p><tt>**</tt> (or <tt>^</tt>, which is an exact synonym), is the arithmetic operator of exponentiation; it requires one number to its left and a second one to its right; <tt>**</tt> then raises the first argument to the power of the second and returns the result. The result will only be computed if it yields a <span class="emphasis"><i>real</i></span> number (as opposed to a <span class="emphasis"><i>complex</i></span> number); this means, that the power can <span class="emphasis"><i>not</i></span> be computed, if the first argument is negative and the second one is fractional. On the other hand, the second argument can be fractional, if the first one ist positive; this means, that <tt>**</tt> may be used to compute arbitrary roots: e.g. <tt>x**0.5</tt> computes the square root of <tt>x</tt>.</p></div><div class="refsect1"><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print 2**0.5
</pre></div></div><div class="refsect1"><h2>See also</h2><p><tt><a href="#ref_sqrt" title="sqrt()">sqrt</a></tt></p></div></div></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_ref_concepts"></a>Chapter 7. A grab-bag of some general concepts and terms</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#ref_logical_shortcuts">Logical shortcuts</a></dt><dt><a href="#ref_conditions_and_expressions">Conditions and expressions</a></dt><dt><a href="#ref_array_references">References on arrays</a></dt><dt><a href="#ref_windows_filenames">Specifying Filenames under Windows</a></dt><dt><a href="#ref_escape_sequences">Escape-sequences</a></dt><dt><a href="#ref_standalone">Creating a <span class="emphasis"><i>standalone</i></span> program from your yabasic-program</a></dt></dl></div><p>This chapter presents some general concepts and terms, which deserve a description on their own, but are not associated with a single command or function in yabasic. Most of these topics do not lend themselves to be read alone, rather they might be read (or skimmed) as background material if an entry from the <a href="#chapter_ref_words" title="Chapter 6. All commands and functions of yabasic grouped alphabetically">alphabetical list of commands</a> refers to them.</p><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_logical_shortcuts"></a>Logical shortcuts</h2></div></div><p><span class="emphasis"><i>Logical shortcuts</i></span> are no special language construct and there is no keyword for them; they are just a way to evaluate <span class="emphasis"><i>logical expressions</i></span>. Logical expressions (i.e. a series of conditions or comparisons joined by <a href="#ref_arithmetic_and" title="and()"><tt>and</tt></a> or <a href="#ref_arithmetic_or" title="or()"><tt>or</tt></a>) are only evaluated until the final result of the expression can be determined. An example:</p><div class="informalexample"><pre class="programlisting">
if (a&lt;&gt;0 and b/a&gt;2) print &quot;b is at least twice as big as a&quot;
</pre></div><p>
The logical expression <tt>a&lt;&gt;0 and b/a&gt;2</tt> consists of two comparisons, both of which must be true, if the <tt>print</tt> statement should be executed. Now, if the first comparison (<tt>a&lt;&gt;0</tt>) is <tt>false</tt>, the whole logical expression can never be <tt>true</tt> and the second comparison (<tt>b/a&gt;2</tt>) need not be evaluated.
</p><p>This is exactly, how yabasic behaves: The evaluation of a composed logical expressions is terminated immediately, as soon as the final result can be deduced from the already evaluated parts.</p><p>In practice, this has the following consequences:</p><div class="itemizedlist"><ul><li><p>If two or more comparisons are joined with <tt>and</tt> and one comparison results in <tt>false</tt>, the logical expression is evaluated no further and the overall result is <tt>false</tt>.</p></li><li><p>If two or more comparisons are joined with <tt>or</tt> and one comparison results in <tt>true</tt>, the logical expression is evaluated no further and the result is <tt>true</tt>.</p></li></ul></div><p>&#8220;Nice, but whats this good for ?&#8221;, I hear you say. Well, just have another look at the example, especially the second comparison (<tt>b/a&gt;2</tt>); deviding <tt>b</tt> by <tt>a</tt> is potentially hazardous: If <tt>a</tt> equals zero, the expression will cause an error and your program will terminate. To avoid this, the first part of the comparison (<tt>a&lt;&gt;0</tt>) checks, if the second one can be evaluated without risk. This pre-checking is the most common usage and primary motivation for <span class="emphasis"><i>logical shortcuts</i></span> (and the reason why most programming languages implement them).</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_conditions_and_expressions"></a>Conditions and expressions</h2></div></div><p>Well, bottomline there is no difference or distinction between <span class="emphasis"><i>conditions</i></span> and <span class="emphasis"><i>expressions</i></span>, at least as yabasic is concerned. So you may assign the result of comparisons to variables or use an arithmetic expression or a simple variable within a condition (e.g. within an <tt>if</tt>-statement). So the constructs shown in the example below are all totally valid:</p><div class="informalexample"><pre class="programlisting">
input &quot;Please enter a number between 1 and 10: &quot; a
rem Assigning the result of a comparison to a variable
okay=a&gt;=1 and a&lt;=10
rem Use a variable within an if-statement
if (not okay) error &quot;Wrong, wrong !&quot;
</pre></div><p>So conditions and expressions are really the same thing (at least as long as yabasic is concerned). Therefore the terms <i>conditions</i> and <i>expression</i> can really be used interchangeably, at least in theory. In reality the term <i>condition</i> is used in connection with <tt>if</tt> or <tt>while</tt> whereas the term <i>expression</i> tends to be used more often within arithmetic context.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_array_references"></a>References on arrays</h2></div></div><p><span class="emphasis"><i>References on arrays</i></span> are the only way to refer to an array <span class="emphasis"><i>as a whole</i></span> and to pass it to subroutines or functions like <a href="#ref_arraydim" title="arraydim()"><tt>arraydim</tt></a> or <a href="#ref_arraysize" title="arraysize()"><tt>arraysize</tt></a>. Whereas (for example) <tt>a(2)</tt> designates the second element of the array <tt>a</tt>, <tt>a()</tt> (with empty braces) refers to the array <tt>a</tt> itself. <tt>a()</tt> is called an <span class="emphasis"><i>array reference</i></span>.</p><p>If you pass an array reference to one of your own subroutines, you need to be aware, that the subroutine will be able to modify the array you have passed in. So passing an array reference does not create a copy of the array; this has some interesting consequences:</p><div class="itemizedlist"><ul><li><p><span class="emphasis"><i>Speed and space:</i></span> Creating a copy of an array would be a time- and resourceconsuming operation; passing just a reference is cheap and fast.</p></li><li><p>Returning many values: A subroutine, that wants to give back more than one value, may require an array reference among its arguments and then store its many return values within this array. This is the only way to return more than one value from a subroutine.</p></li></ul></div></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_windows_filenames"></a>Specifying Filenames under Windows</h2></div></div><p>As you probably know, windows uses the character '<tt>\</tt>' to separate the directories within a pathname; an example would be <tt>C:\yabasic\yabasic.exe</tt> (the usual location of the yabasic executable). However, the very same character '<tt>\</tt>' is used to contstruct <a href="#ref_escape_sequences" title="Escape-sequences">escape sequences</a>, not only in yabasic but in most other programming languages.</p><p>Therefore the string <tt>&quot;C:\t.dat&quot;</tt> does <span class="emphasis"><i>not</i></span> specify the file <tt>t.dat</tt> within the directory <tt>C:</tt>; this is because the sequence '<tt>\t</tt>' is translated into the tab-character. To specify this filename, you need to use the string <tt>&quot;C:\\t.dat&quot;</tt> (note the double slash '<tt>\\</tt>').</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_escape_sequences"></a>Escape-sequences</h2></div></div><p><span class="emphasis"><i>Escape-sequences</i></span> are the preferred way of specifying 'special' characters. They ar intoduced by the '\'-character and followed by one of a few regular letters, e.g. '\n' or '\r' (see the table below).</p><p>Escape-sequences may occur within any string at any position; they are replaced at <span class="emphasis"><i>parsetime</i></span> (opposed to <span class="emphasis"><i>runtime</i></span>), i.e. as soon as yabasic discovers the string, with their corresponding <span class="emphasis"><i>special</i></span> character. As a consequence of this <tt>len(&quot;\a&quot;)</tt> returns 1, because yabasic replaces <tt>&quot;\a&quot;</tt> with the matching special character just before the program executes.</p><div class="table"><p><b>Table 7.1. Escape sequences</b></p><table summary="Escape sequences" border="1"><colgroup><col><col></colgroup><thead><tr><th>Escape Seqence</th><th>Matching special character</th></tr></thead><tbody><tr><td><tt>\n</tt></td><td><span class="emphasis"><i>newline</i></span></td></tr><tr><td><tt>\t</tt></td><td><span class="emphasis"><i>tabulator</i></span></td></tr><tr><td><tt>\v</tt></td><td><span class="emphasis"><i>vertical tabulator</i></span></td></tr><tr><td><tt>\b</tt></td><td><span class="emphasis"><i>backspace</i></span></td></tr><tr><td><tt>\r</tt></td><td><span class="emphasis"><i>carriage return</i></span></td></tr><tr><td><tt>\f</tt></td><td><span class="emphasis"><i>formfeed</i></span></td></tr><tr><td><tt>\a</tt></td><td><span class="emphasis"><i>alert</i></span> (i.e. a beeping sound)</td></tr><tr><td><tt>\\</tt></td><td><span class="emphasis"><i>backslash</i></span></td></tr><tr><td><tt>\'</tt></td><td><span class="emphasis"><i>single quote</i></span></td></tr><tr><td><tt>\&quot;</tt></td><td><span class="emphasis"><i>double quote</i></span></td></tr><tr><td><tt>\x</tt><span class="emphasis"><i>HEX</i></span></td><td><tt>chr$(</tt><span class="emphasis"><i>HEX</i></span><tt>)</tt> (see below)</td></tr></tbody></table></div><p>Note, that an escape sequences of the form \xHEX allows to encode arbitrary
characters as long as you know their position (as a hex-number) within the
ascii-charset:
For example \x012 is transformed into the character <tt>chr$(18)</tt> (or <tt>chr$(dec(&quot;12&quot;,16))</tt>. Note that \x requires a
hexa-decimal number (and the hexa-decimal string &quot;12&quot; corresponds to the decimal number 18).</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="ref_standalone"></a>Creating a <span class="emphasis"><i>standalone</i></span> program from your yabasic-program</h2></div></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The <tt>bind</tt>-feature, which is described below, is at an experimental stage right now. It works (at least for me !) under Windows and Linux, but I cannot even promise it for other variants of Unix. However, if it does not work for your Unix, I will at least try to make it work, if you give me sufficient information of your system.</p></div><p>Sometimes you may want to give one of your yabasic-programs to other people. However, what if those other people do not have yabasic installed ? In that case you may create a <span class="emphasis"><i>standalone</i></span>-program from your yabasic-program, i.e. an executable, that may be executed on its own, standalone, even (and especially !) on computers, that do not have yabasic installed. Having created a standalone program, you may pass it around like any other program (e.g. one written in C) and you can be sure that your program will execute right away.</p><p>Such a standalone-program is simply created by copying the full yabasic-interpreter and your yabasic-program (plus all the libraries it does <tt>import</tt>) together into a single, new program, whose name might be chosen at will (under windows of course it should have the ending <tt>.exe</tt>). If you decide to create a standalone-program, there are three bits in yabasic, that you may use:</p><div class="itemizedlist"><ul><li><p>The <tt><a href="#ref_bind" title="bind()">bind</a></tt>-command, which does the actual job of creating the standalone program from the yabasic-interpreter and your program.</p></li><li><p>The command-line Option <tt>-bind</tt> (available under <a href="#windows_options">windows</a> and <a href="#unix_options">Unix</a>), which does the same from the command-line.</p></li><li><p>The special <tt><a href="#ref_peek" title="peek">peek(&quot;isbound&quot;)</a></tt>, which may be used to check, if the yabasic-program containing this <tt>peek</tt> is bound to the interpreter as part of a standalone program.</p></li></ul></div><p>With these bits you know enough to create a standalone-program. Actually there are two ways to do this: on the commandline and from within your program.</p><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="id2826651"></a>Creating a standalone-program from the commandline</h4></div></div><p>Let's say you have the following <span class="emphasis"><i>very</i></span> simple program within the file <tt>foo.yab</tt>:</p><div class="informalexample"><pre class="programlisting">
print &quot;Hello World !&quot;
</pre></div><p>Normally you would start this yabasic-program by typing <b><tt>yabasic foo.yab</tt></b> and as a result the string <tt>Hello World !</tt> would appear on your screen. However, to create a <span class="emphasis"><i>standalone</i></span>-program from <tt>foo.yab</tt> you would type:</p><div class="informalexample"><p><b><tt>yabasic -bind foo.exe foo.yab</tt></b></p></div><p>This command does <span class="emphasis"><i>not</i></span> execute your program <tt>foo.yab</tt> but rather create a <span class="emphasis"><i>standalone</i></span>-program <tt>foo.exe</tt>. Note: under Unix you would probably name the standalone program <tt>foo</tt> or such, omitting the windows-specific ending <tt>.exe</tt>. </p><p>Yabasic will confirm by printing something like: <tt>---Info: Successfully bound 'yabasic' and 'foo.yab' into 'foo.exe'</tt>.</p><p>After that you will find a program <tt>foo.exe</tt> (which must be made <span class="emphasis"><i>executable</i></span> with the <b>chmod</b>-command under Unix first). Now, executing this program <tt>foo.exe</tt> (or <tt>foo</tt> under Unix) will produce the output <tt>Hello World !</tt>.</p><p>This newly created program <tt>foo.exe</tt> might be passed around to anyone, even if he does not have yabasic installed.</p></div><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="id2826863"></a>Creating a standalone-program from within your program</h4></div></div><p>It is possible to write a yabasic-program, that binds itself to the yabasic-interpreter. Here is an example:</p><div class="informalexample"><pre class="programlisting">
if (!peek(&quot;isbound&quot;)) then
bind &quot;foo&quot;
print &quot;Successfully created the standalone executable 'foo' !&quot;
exit
endif
print &quot;Hello World !&quot;
</pre></div><p>If you run this program (which may be saved in the file <tt>foo.yab</tt>) via <b><tt>yabasic foo.yab</tt></b>, the <tt><a href="#ref_peek" title="peek">peek(&quot;isbound&quot;)</a></tt> in the first line will check, if the program is already part of a standalone-program. If <span class="emphasis"><i>not</i></span> (i.e. if the yabasic-interpreter and the yabasic-program are seperate files) the <tt><a href="#ref_bind" title="bind()">bind</a></tt>-command will create a standalone program <tt>foo</tt> containing both. As a result you would see the output <tt>Successfully created the standalone executable 'foo' !</tt>. Note: Under Windows you would probably choose the filename <tt>foo.exe</tt>.</p><p>Now, if you run this standalone executable <tt>foo</tt> (or <tt>foo.exe</tt>), the very same yabasic-program that is shown above will be executed again. However, this time the <tt><a href="#ref_peek" title="peek">peek(&quot;isbound&quot;)</a></tt> will return <tt>TRUE</tt> and therefore the condition of the <tt>if</tt>-statement is <span class="emphasis"><i>false</i></span> and the three lines after <tt>then</tt> are <span class="emphasis"><i>not</i></span> executed. Rather the last <tt>print</tt>-statement will run, and you will see the output <tt>Hello World !</tt>.</p><p>That way a yabasic-program may turn itself into a standalone-program.</p></div><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="id2827084"></a>Downsides of creating a standalone program</h4></div></div><p>Now, before you go out and turn all your yabasic-programs into standalone programs, please take a second to consider the downsides of doing so:</p><div class="itemizedlist"><ul><li><p>The new standalone program will be at least as big as the interpreter itself, so you need to pass a few hundred kilobytes around, just to save people from having to install yabasic themselves.</p></li><li><p>There is no easy way to extract your yabasic-program from within the standalone program: If you ever want to change it, you need to have it around seperately.</p></li><li><p>If a new version of yabasic becomes available, again you need to recreate all of your standalone programs to take advantage of bugfixes and improvements.</p></li></ul></div><p>So, beeing able to create a standalone program is certainly a good thin, but certainly <span class="emphasis"><i>not</i></span> a silver bullet.</p></div><div class="sect3"><div class="titlepage"><div><h4 class="title"><a name="id2827174"></a>See also</h4></div></div><p>The <a href="#ref_bind" title="bind()"><tt>bind</tt></a>-command, the <a href="#ref_peek" title="peek"><tt>peek</tt></a>-function and the commandline options for <a href="#unix_options">Unix</a> and <a href="#windows_options">Windows</a>.</p></div></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_examples"></a>Chapter 8. A few example programs</h2></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2827243">A very simple program</a></dt><dt><a href="#id2827270">A part of the demo of yabasic</a></dt></dl></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2827243"></a>A very simple program</h2></div></div><p>The program below is a very simple program:</p><pre class="programlisting">
repeat
input &quot;Please enter the first number, to add &quot; a
input &quot;Please enter the second number, to add &quot; b
print a+b
until(a=0 and b=0)
</pre><p>This program requests two numbers, which it than adds. The process is repeated until you enter zero (or nothing) twice.</p></div><div class="sect1"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2827270"></a>A part of the demo of yabasic</h2></div></div><p>The listing below is an abbreviated and slightly refreshed version of the <span class="emphasis"><i>demo</i></span> of yabasic. However this demo has been written <span class="emphasis"><i>before</i></span> some of the more advanced features of yabasic have been implemented. For example <span class="emphasis"><i>subroutines</i></span> have only been retrofitted on the original version of this demo. So please do not take this as a particular good example of yabasic-code. On the other hand: This is no beauty contest. However you could make it one, if you send me some better code (which should do nice and simple things with less than 200 lines).</p><pre class="programlisting">
//
// This program demoes yabasic
//
// Check, if screen is large enough
clear screen
sw=peek(&quot;screenwidth&quot;):sh=peek(&quot;screenheight&quot;)
if (sw&lt;78 or sh&lt;24) then
print
print &quot; Sorry, but your screen is to small to run this demo !&quot;
print
end
endif
sw=78:sh=24
// Initialize everything
restore mmdata
read mmnum:dim mmtext$(mmnum)
for a=1 to mmnum:read mmtext$(a):next a
// Main loop selection of demo
ysel=1
label mainloop
clear screen
print colour(&quot;cyan&quot;,&quot;magenta&quot;) at(7,2) &quot;################################&quot;
print colour(&quot;cyan&quot;,&quot;magenta&quot;) at(7,3) &quot;################################&quot;
print colour(&quot;cyan&quot;,&quot;magenta&quot;) at(7,4) &quot;################################&quot;
print colour(&quot;yellow&quot;,&quot;blue&quot;) at(8,3) &quot; This is the demo for yabasic &quot;
yoff=7
for a=1 to mmnum
if (a=mmnum) then ydisp=1:else ydisp=0:fi
if (a=ysel) then
print colour(&quot;blue&quot;,&quot;green&quot;) at(5,yoff+ydisp+a) mmtext$(a);
else
print at(5,yoff+ydisp+a) mmtext$(a);
endif
next a
print at(3,sh-3) &quot;Move selection with CURSOR KEYS (or u and d),&quot;
print at(3,sh-2) &quot;Press RETURN or SPACE to choose, ESC to quit.&quot;
do // loop for keys pressed
rev=1
do // loop for blinking
k$=inkey$(0.4)
if (k$=&quot;&quot;) then
if (ysel=mmnum) then
if (rev=1) then
print colour(&quot;blue&quot;,&quot;green&quot;) at(5,yoff+mmnum+1) mmtext$(mmnum);
rev=0
else
print colour(&quot;yellow&quot;,&quot;red&quot;) at(5,yoff+mmnum+1) mmtext$(mmnum);
rev=1
endif
endif
else // key has been pressed, leave loop
break
endif
loop // loop for blinking
yalt=ysel
if (k$=&quot;up&quot; or k$=&quot;u&quot;) then
if (ysel=1) then ysel=mmnum else ysel=ysel-1 fi
redraw():heal():continue
fi
if (k$=&quot;down&quot; or k$=&quot;d&quot;) then
if (ysel=mmnum) then ysel=1 else ysel=ysel+1 fi
redraw():heal():continue
fi
if (k$=&quot; &quot; or k$=&quot;enter&quot; or k$=&quot;right&quot;) then
on ysel gosub overview,bitmap,endit,notyet
goto mainloop
fi
if (k$=&quot;esc&quot;) then
endit()
fi
beep
print at(3,sh-5) &quot;Invalid key: &quot;,k$,&quot; &quot;
loop // loop for keys pressed
// redraw line
sub redraw()
if (yalt=mmnum) then ydisp=1:else ydisp=0:fi
print at(5,yoff+yalt+ydisp) mmtext$(yalt);
if (ysel=mmnum) then ydisp=1:else ydisp=0:fi
print colour(&quot;blue&quot;,&quot;green&quot;) at(5,yoff+ysel+ydisp) mmtext$(ysel);
return
end sub
// erase a line
sub heal()
print at(3,sh-5) &quot; &quot;
return
end sub
// Go here to exit
label endit
print at(3,sh-8) &quot;Hope you liked it ...\n &quot;;
exit
return
// Present a short overview
label overview
clear screen
print &quot;\n Yabasic is a quite traditional basic: It comes with&quot;
print &quot; print, input, for-next-loops, goto, gosub, while and&quot;
print &quot; repeat and even user defined procedures and libraries.&quot;
print &quot;\n Yabasic has the usual functions, from sin(), int() to mid$();&quot;
print &quot; more advanced functions are date$ (is &quot;,date$,&quot;),&quot;
print &quot; or token$(), system$(), ran() and glob$().&quot;
print &quot;\n Yabasic makes it easy to open a window, draw lines&quot;
print &quot; and print the resulting picture.&quot;
print &quot;\n Yabasic programs are interpreted and run under Unix&quot;
print &quot; and Windows. Yabasic is small (around 200k) and&quot;
print &quot; free, i.e. subject to the GNU copyleft.&quot;
print &quot;\n Finally, this demo itself is written in yabasic and&quot;
print &quot; gives an idea of what can be done with the language.&quot;
print &quot;\n\n\n While you read this, I am calculating prime numbers,&quot;
print &quot; Press any key to return to main menu ...&quot;
can=1
print at(6,19) &quot;This is a prime number: &quot;
label nextcan
can=can+2
for i=2 to sqrt(can):if (frac(can/i)=0) then goto notprime:fi:next i
print at(32,19) can;
label notprime
if (lower$(inkey$(0))&lt;&gt;&quot;&quot;) then return:fi
goto nextcan
// Show some animated bitmaps
label bitmap
clear screen
print at(5,5) &quot;Yabasic offers limited support for bitmapped graphics.&quot;
print at(5,6) &quot;You can retrieve and alter rectangular regions of&quot;
print at(5,7) &quot;the graphics window with a single command.&quot;
print reverse at(5,12) &quot; Press any key to return to main menu ... &quot;
n=20
open window 400,400
if (picsinitialized=0) then
picsinitialized=1
dim pics(n,4)
dim pics$(5)
restore pics
for a=1 to 5:read pics$(a):next a
endif
tick=1
for a=1 to n:pics(a,4)=0:next a
cx=ran(370):cy=ran(370):vx=10-ran(20):vy=10-ran(20)
label picloop
for a=1 to n
if (pics(a,4)&lt;=tick) then
if (pics(a,4)=tick) then
bitblit pics$(pics(a,3)) to pics(a,1),pics(a,2),&quot;xor&quot;
endif
x=cx+50-ran(100):y=cy+50-ran(100)
if (ran(10)&gt;3) then
pics(a,1)=x:pics(a,2)=y:pics(a,3)=ran(5)+1
pics(a,4)=tick+4+int(ran(4))
bitblit pics$(pics(a,3)) to pics(a,1),pics(a,2),&quot;xor&quot;
endif
endif
next a
tick=tick+1
cx=cx+vx:cy=cy+vy
if (cx&lt;-30 or cx&gt;400) then cx=cx-vx:vx=-vx fi
if (cy&lt;-30 or cy&gt;400) then cy=cy-vy:vy=-vy fi
if (inkey$(0.1)=&quot;&quot;) then goto picloop fi
close window
return
// data for bitmaps
label pics
data &quot;24,24:00000000000000000000000008f1000eff000fff308f9f30cf0c70e30870e30070e00070e07070e07870e0fc70e1ff30e1ff3ec1cf1ec3000fc700cf8f3cf78ffff30efff000ff00&quot;
data &quot;24,24:00c10000e10000f10000f10008f30008f30008f700fff700ffff30ffffffefffffefffff0ffff70eff700eff000cff100eff300fff70cfff70ef7ef1ef1cf3e700e3e100c3000000&quot;
data &quot;24,24:0000000000700e00700e00700e00700e10700e38700c38700c7c30087c3000fe1000ff1000ef0000e70000c70000c30000c30000e10000f10000f0000c70000c70000c3000000000&quot;
data &quot;24,24:000000000000008700008f30008f7000cf7000c37000e97000f97000f83008f8300878300cf8300ef8300efb300eef700fcf700f0f708700f0c700f1c300e1c100e1000000000000&quot;
data &quot;24,24:0000000000000cf1000cff000cff300cbf300c3c700838700c30700cff700cff700cff700c9f700c1c700e10700e10700f38708fff708fff7083ff10000000000000000000000000&quot;
// Go here for a feature not yet implemented
label notyet
clear screen
print &quot;\n\n Sorry this section is not yet implemented !&quot;
print &quot; Press any key to return to main menu ...&quot;
inkey$
return
// Data section ...
label mmdata
// Data for main menu: Number and text of entries in main menu
data 3
data &quot; Yabasic in a nutshell &quot;
data &quot; Animated Bitmaps &quot;
data &quot; Exit this demo &quot;
</pre></div></div><div class="chapter"><div class="titlepage"><div><h2 class="title"><a name="chapter_copyright"></a>Chapter 9. The Copyright of yabasic</h2></div></div><p>yabasic may be copied only under the terms of the <span class="emphasis"><i><a href="http://www.yabasic.de/artistic.htm" target="_top">Artistic License</a></i></span> or the <span class="emphasis"><i><a href="http://www.yabasic.de/gpl.htm" target="_top">GNU General Public License</a></i></span> (GPL), both of which are distributed with yabasic.</p><p>[Can't you make up your mind ?!], I hear you say. Umm, well <span class="emphasis"><i>yes</i></span>. In fact I do not want to read or try to understand them both, so I have put the burden on <span class="emphasis"><i>you</i></span> (grin). However, I think that the Artistic License is more liberal and gives you more rights and you should choose it; on the other hand the GPL is more widely known and a lot of software is distributed under its terms.</p><p>Here is a list of things that are possible under the terms of the Artistic License:</p><div class="itemizedlist"><ul><li><p>Put yabasic on your own homepage or CD and even charge for the service of distributing yabasic.</p></li><li><p>Write your own yabasic-programs, pack your program and yabasic into a package and sell the whole thing.</p></li><li><p>Modify yabasic and add or remove features, sell the modified version.</p></li></ul></div></div></div></body></html>