<!DOCTYPE book SYSTEM "docbook/docbookx.dtd">
<book>
  <bookinfo>
    <title>Yabasic</title>
  </bookinfo>
  <chapter id="chapter_intoduction">
  <title>Introduction</title>
    <sect1>
      <title>About this document</title>
      <para>
      This document describes <application>yabasic</application>.
      You will find information about the <application>yabasic</application>
      interpreter (the program <command>yabasic</command> under Unix or
      <command>yabasic.exe</command> under Windows)
      as well as the language itself.<para>
    </para>
      This document applies to version 2.740 of <application>yabasic</application></para>
    <para>
      However, this document does not contain the latest news about <application>yabasic</application> or a FAQ.
      As such information tends to change rapidly, it is presented online only
      at <ulink url="http://www.yabasic.de">www.yabasic.de</ulink>.</para>
    <para>
      Although <acronym>basic</acronym> 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.</para>
    <para>
    </para>
  </sect1>


  <sect1>
    <title>About <application>yabasic</application></title>
    <para><application>yabasic</application> is a traditional basic interpreter. It understands most of the typical basic-constructs, like <function>goto</function>, <function>gosub</function>, line numbers, <function>read</function>, <function>data</function> or string-variables with a trailing '<literal>$</literal>'. But on the other hand, <application>yabasic</application> implements some more advanced programming-constructs like subroutines or libraries (but <emphasis>not</emphasis> objects). <application>yabasic</application> works much the same under Unix and Windows.</para>
    <para><application>yabasic</application> 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:</para>
    <programlisting>
open window 100,100
open printer
circle 50,50,40
text 10,50,"Press any key to get a printout"
clear screen
inkey$
close printer
close window
</programlisting>
    <para>This example has fewer lines, than it would have in many other programming languages. In the end however <application>yabasic</application> 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.</para>
      </sect1>
  </chapter>


  <chapter id="chapter_program_windows">
    <title>The <application>yabasic</application>-program under Windows</title>
    <sect1>
      <title id="windows_starting">Starting <application>yabasic</application></title>
      <para>Once, <application>yabasic</application> has been set up correctly, there are three ways to start it:</para>
      <orderedlist>
<listitem>
   <para><emphasis>Rightclick on your desktop:</emphasis> The desktop menu appears with a submenu named <emphasis>new</emphasis>. From this submenu choose <application>yabasic</application>. This will create a new icon on your desktop. If you rightclick on this icon, its <link linkend="windows_context_menu">context menu</link> will appear; choose <guilabel>Execute</guilabel> to execute the program.</para>
</listitem>


<listitem>
   <para>As a variant of the way described above, you may simply <emphasis>create a file with the ending <filename>.yab</filename></emphasis> (e.g. with your favorite editor). Everything else then works as described above.</para>
</listitem>


<listitem>
   <para><emphasis>From the start-menu:</emphasis> Choose <application>yabasic</application> 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 <literal>return</literal> twice, and <application>yabasic</application> will parse and execute your program.</para>
   <note>
     <para>This is <emphasis>not</emphasis> the preferred way of starting <application>yabasic</application> ! Simply because the program, that you have typed, <emphasis>can not be saved</emphasis> and will be lost inevitably ! There is no such thing as a <function>save</function>-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs.</para>
   </note>
</listitem>
      </orderedlist>
    </sect1>
    <sect1>
      <title id="windows_options">Options</title>
      <para>Under Windows <application>yabasic</application> 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.</para>
      <para>All the options below may be abbreviated, as long as the abbreviation does not become ambigous. For example, you may write <literal>-e</literal> instead of <literal>-execute</literal>.</para>
      <variablelist>
<varlistentry>
   <term><literal>-help</literal> or <literal>-?</literal></term>
   <listitem>
     <para>Prints a short help message, which itself describes two further help-options.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-version</literal></term>
   <listitem>
     <para>Prints the version of <application>yabasic</application>.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-geometry +<replaceable>X-POSITION</replaceable>+<replaceable>Y-POSITION</replaceable></literal></term>
   <listitem>
     <para>Sets the position of the graphic window, that is opened by <function>open window</function> (the <emphasis>size</emphasis> of this window, of course, is specified within the <function>open window</function>-command). An example would be <literal>-geometry +20+10</literal>, 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 <application>yabasic</application> has been started.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-font <replaceable>NAME-OF-FONT</replaceable></literal></term>
   <listitem>
     <para>Name of the font, which will be used for graphic-text; can be any of <literal>decorative, dontcare, modern, roman, script, swiss</literal>. You may append a fontsize (measured in pixels) to any of those fontnames; for example <literal>-font swiss30</literal> chooses a swiss-type font with a size of 30 pixels.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-bind <replaceable>NAME-OF-STANDALONE-PROGRAM</replaceable></literal></term>
   <listitem>
     <para>Create a standalone program (whose name is specified by <replaceable>NAME-OF-STANDALONE-PROGRAM</replaceable>) from the <application>yabasic</application>-program, that is specified on the commandline. See the section about <link linkend="ref_standalone">creating a <emphasis>standalone</emphasis>-program</link> for details.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-execute <replaceable>A-PROGRAM-AS-A-SINGLE-STRING</replaceable></literal></term>
   <listitem>
     <para>With this option you may specify some <application>yabasic</application>-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, <application>yabasic</application> 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 <literal>yabasic -e 'for a=1 to 10:print a*a:next a'</literal> will give you the answer immediately.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-infolevel <replaceable>INFOLEVEL</replaceable></literal></term>
   <listitem>
     <para>Change the <emphasis>infolevel</emphasis> of yabasic, where <replaceable>INFOLEVEL</replaceable> can be one of <literal>debug</literal>, <literal>note</literal>, <literal>warning</literal>, <literal>error</literal> and <literal>fatal</literal> (the default is <literal>warning</literal>). This option changes the amount of debugging-information <application>yabasic</application> produces. However, normally only the author of <application>yabasic</application> (<emphasis>me</emphasis> !) would want to change this.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-doc <replaceable>NAME-OF-A-PROGRAM</replaceable></literal></term>
   <listitem>
     <para>Print the <emphasis>embedded documentation</emphasis> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <function><link linkend="ref_doc">doc</link></function>. This documentation can also be seen by choosing the corresponding entry from the context-menu of any <application>yabasic</application>-program.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-librarypath <replaceable>DIRECTORY-WITH-LIBRARIES</replaceable></literal></term>
   <listitem>
     <para>Change the directory, wherein libraries will be searched and imported (with the <function><link linkend="ref_import">import</link></function>-command). See also <function><link linkend="ref_import">this entry</link></function> for more information about the way, libraries are searched.</para>
   </listitem>
</varlistentry>
      </variablelist>
    </sect1>
    <sect1>
      <title id="windows_context_menu">The context Menu</title>
      <para>Like every other icon under Windows, the icon of every <application>yabasic</application>-program has a <emphasis>context menu</emphasis> offering the most frequent operations, that may be applied to a <application>yabasic</application>-program.</para>


   <variablelist>
     <varlistentry>
   <term><guilabel>Execute</guilabel></term>
       <listitem>
  <para>This will invoke <application>yabasic</application> to execute your program. The same happens, if you <emphasis>doubleclick</emphasis> on the icon.</para>
       </listitem>
     </varlistentry>
     <varlistentry>
   <term><guilabel>Edit</guilabel></term>
       <listitem>
  <para><application>notepad</application> will be invoked, allowing you to edit your program.</para>
       </listitem>
     </varlistentry>
     <varlistentry>
   <term><guilabel>View docu</guilabel></term>
       <listitem>
  <para>This will present the embedded documentation of your program. Embedded documentation is created with the special comment <function><link linkend="ref_doc">doc</link></function>.</para>
       </listitem>
     </varlistentry>
   </variablelist>
    </sect1>
  </chapter>




  <chapter id="chapter_program_unix">
    <title>The <application>yabasic</application>-program under Unix</title>
    <sect1>
      <title id="unix_starting">Starting <application>yabasic</application></title>
      <para>If your system administrator (vulgo <emphasis>root</emphasis>) has installed <application>yabasic</application> correctly, there are three ways to start it:</para>


      <orderedlist>


<listitem>
   <para>You may use your favorite editor (<application>emacs</application>, <application>vi</application> ?) to put your program into a file (e.g. <filename>foo</filename>). Make sure that the very first line starts with the characters '<literal>#!</literal>'  followed by the full pathname of <application>yabasic</application> (e.g. '<literal>#!/usr/local/bin/yabasic</literal>'). This <emphasis>she-bang</emphasis>-line ensures, that your Unix will invoke <application>yabasic</application> to execute your program (see also the entry for the <link linkend="ref_hash">hash</link>-character). Moreover, you will need to change the permissions of your <application>yabasic</application>-program <filename>foo</filename>, e.g. <literal>chmod u+x foo</literal>. After that you may invoke <application>yabasic</application> to invoke your program by simply typing <literal>foo</literal> (without even mentioning <application>yabasic</application>). However, if your <envar>PATH</envar>-variable does not contain a single dot ('<literal>.</literal>') you will have to type the full pathname of your program: e.g. <filename>/home/ihm/foo</filename> (or at least <filename>./foo</filename>).</para>
</listitem>


<listitem>
   <para>Save your program into a file (e.g. <filename>foo</filename>) and type <literal>yabasic foo</literal>. This assumes, that the directory, where <application>yabasic</application> resides, is contained within your <envar>PATH</envar>-variable.</para>
</listitem>


<listitem>
   <para>Finally your may simply type <userinput>yabasic</userinput> (maybe it will be necessary to include its full pathname). This will make <application>yabasic</application> come up and you will be asked to type in your program. Once you are finished, you need to type <literal>return</literal> twice, and <application>yabasic</application> will parse and execute your program.</para>
   <note>
     <para>This is <emphasis>not</emphasis> the preferred way of starting <application>yabasic</application> ! Simply because the program, that you have typed, <emphasis>can not be saved</emphasis> and will be lost inevitably ! There is no such thing as a <function>save</function>-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 <application>yabasic</application> as some sort of fancy desktop calculator.</para>
   </note>
</listitem>
      </orderedlist>
    </sect1>


    <sect1>
      <title id="unix_options">Options</title>
      <para><application>yabasic</application> 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 <literal>-e</literal> instead of <literal>-execute</literal>.</para>
      <variablelist>
<varlistentry>
   <term><literal>-help</literal> or <literal>-?</literal></term>
   <listitem>
     <para>Prints a short help message, which itself describes two further help-options.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-version</literal></term>
   <listitem>
     <para>Prints the version of <application>yabasic</application>.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-fg <replaceable>FOREGROUND-COLOR</replaceable></literal> or <literal>-foreground <replaceable>FOREGROUND-COLOR</replaceable></literal></term>
   <listitem>
     <para>Define the foreground color for the graphics-window (that will be opened with <function><link linkend="ref_open_window">open window</link></function>). The usual X11 colornames, like <emphasis>red</emphasis>, <emphasis>green</emphasis>, … are accepted. This value cannot be changed, once <application>yabasic</application> has been started.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-bg <replaceable>BACKGROUND-COLOR</replaceable></literal> or <literal>-background <replaceable>BACKGROUND-COLOR</replaceable></literal></term>
   <listitem>
     <para>Define the background color for the graphics-window. The usual X11 colornames are accepted. This value cannot be changed, once <application>yabasic</application> has been started.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-geometry +<replaceable>X-POSITION</replaceable>+<replaceable>Y-POSITION</replaceable></literal></term>
   <listitem>
     <para>Sets the position of the graphic window, that is opened by <function>open window</function> (the <emphasis>size</emphasis> of this window, of course, is specified with the <function>open window</function>-command). An example would be <literal>+20+10</literal>, 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 <application>yabasic</application> has been started.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-display <replaceable>BACKGROUND-COLOR</replaceable></literal></term>
   <listitem>
     <para>Specify the <emphasis>display</emphasis>, where the graphics window of yabasic should appear. Normally, however this value will be already present within the environment variable <envar>DISPLAY</envar>.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-font <replaceable>NAME-OF-FONT</replaceable></literal></term>
   <listitem>
     <para>Name of the font, which will be used for text within the graphics window.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-execute <replaceable>A-PROGRAM-AS-A-SINGLE-STRING</replaceable></literal></term>
   <listitem>
     <para>With this option you may specify some <application>yabasic</application>-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, <application>yabasic</application> will not read any code from a file. E.g. <programlisting>yabasic -e 'for a=1 to 10:print a*a:next a'</programlisting> prints the square numbers from 1 to 10.
</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-bind <replaceable>NAME-OF-STANDALONE-PROGRAM</replaceable></literal></term>
   <listitem>
     <para>Create a standalone program (whose name is specified by <replaceable>NAME-OF-STANDALONE-PROGRAM</replaceable>) from the <application>yabasic</application>-program, that is specified on the commandline. See the section about <link linkend="ref_standalone">creating a <emphasis>standalone</emphasis>-program</link> for details.</para>
   </listitem>
</varlistentry>



<varlistentry>
   <term><literal>-infolevel <replaceable>INFOLEVEL</replaceable></literal></term>
   <listitem>
     <para>Change the <emphasis>infolevel</emphasis> of yabasic where <replaceable>INFOLEVEL</replaceable> can be one of <literal>debug</literal>, <literal>note</literal>, <literal>warning</literal>, <literal>error</literal> and <literal>fatal</literal> (the default is <literal>warning</literal>). This option changes the amount of debugging-information <application>yabasic</application> produces. However, normally only the author of <application>yabasic</application> (<emphasis>me</emphasis> !) would want to change this.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-doc <replaceable>NAME-OF-A-PROGRAM</replaceable></literal></term>
   <listitem>
     <para>Print the <emphasis>embedded documentation</emphasis> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <function><link linkend="ref_doc">doc</link></function>.</para>
   </listitem>
</varlistentry>


<varlistentry>
   <term><literal>-librarypath <replaceable>DIRECTORY-WITH-LIBRARIES</replaceable></literal></term>
   <listitem>
     <para>Change the directory from which libraries will be imported (with the <function><link linkend="ref_import">import</link></function>-command). See also this entry for more information about the way, libraries will be searched.</para>
   </listitem>
</varlistentry>
      </variablelist>
    </sect1>


    <sect1>
      <title id="unix_setting_defaults">Setting defaults</title>
      <para>If you want to set some options <emphasis>once for all</emphasis>, you may put them into your X-Windows resource file. This is usually the file <filename>.Xresources</filename> or some such within your home directory (type <userinput>man X</userinput> for details).</para>
      <para>Here is a sample section, which may appear within this file:</para>
      <programlisting>
yabasic*foreground: blue
yabasic*background: gold
yabasic*geometry: +10+10
yabasic*font: 9x15
</programlisting>
      <para>This will set the foreground color of the graphic-window to <emphasis>blue</emphasis> and the background color to <emphasis>gold</emphasis>. The window will appear at position <emphasis>10,10</emphasis> and the text font will be <emphasis>9x15</emphasis>.</para>
</sect1>
  </chapter>



  <chapter id="chapter_topics">
    <title>Some features of <application>yabasic</application>, grouped by topic</title>
    <para>This chapter has sections for some of the major features of <application>yabasic</application> 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 <emphasis>see also</emphasis>-section.</para>
    <sect1>
      <title><function>print</function>, <function>input</function> and others</title>
      <para>The <function><link linkend="ref_print">print</link></function>-command is used to put text on the text screen. Here, the term <wordasword>text screen</wordasword> stands for your terminal (under Unix) or the console window (under Windows).</para>
      <para>At the bottom line, <function>print</function> simply outputs its argument to the text window. However, once you have called <function><link linkend="ref_clear_screen">clear screen</link></function> you may use advanced features like printing colors or copying areas of text with <function><link linkend="ref_getscreen">getscreen$</link></function> or <function><link linkend="ref_putscreen">putscreen</link></function>.</para>
      <para>You may ask the user for input with the <function><link linkend="ref_input">input</link></function>-command; use <function><link linkend="ref_inkey">inkey$</link></function> to get each key as soon as it is pressed.</para>
    </sect1>


    <sect1>
      <title>Control statements: loops, <function>if</function> and <function>switch</function></title>
      <para>Of course, <application>yabasic</application> has the <function><link linkend="ref_goto">goto</link></function>- and <function><link linkend="ref_gosub">gosub</link></function>-statements; you may go to a <function><link linkend="ref_label">label</link></function> or a <emphasis>line number</emphasis> (which is just a special kind of label). <function><link linkend="ref_goto">goto</link></function>, despite its bad reputation (<citation><function>goto</function> considered harmful</citation>), has still its good uses; however in many cases you are probably better off with loops like <function><link linkend="ref_repeat">repeat</link></function>-<function><link linkend="ref_until">until</link></function>, <function><link linkend="ref_while">while</link></function>-<function><link linkend="ref_wend">wend</link></function> or <function><link linkend="ref_do">do</link></function>-<function><link linkend="ref_loop">loop</link></function>; you may leave any of these loops with the <function><link linkend="ref_break">break</link></function>-statement or start the next iteration immediately with <function><link linkend="ref_continue">continue</link></function>.</para>
      <para>Decisions can be made with the <function><link linkend="ref_if">if</link></function>-statement, which comes either in a <emphasis>short</emphasis> and a <emphasis>long</emphasis> form. The short form has no <function><link linkend="ref_then">then</link></function>-keyword and extends up to the end of the line. The long form extends up to the final <function><link linkend="ref_endif">endif</link></function> and may use some of the keywords <function><link linkend="ref_then">then</link></function> (which introduces the long form), <function><link linkend="ref_else">else</link></function> or <function><link linkend="ref_elsif">elsif</link></function>.</para>
<para>If you want to test the result of an expression against many different values, you should probably use the <function><link linkend="ref_switch">switch</link></function>-statement.</para>
    </sect1>



    <sect1>
      <title>Drawing and painting</title>
      <para>You need to call <function><link linkend="ref_open_window">open window</link></function> before you may draw anything with either <function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_circle">circle</link></function> or <function><link linkend="ref_rectangle">rectangle</link></function>; all of these statements may be decorated with <function><link linkend="ref_clear">clear</link></function> or <function><link linkend="ref_fill">fill</link></function>. Note however, that all graphics in <application>yabasic</application> is <emphasis>monochrome</emphasis> ("black on white"). Moreover, there can only be a single window open at any given moment in time.</para>
      <para>Evyerything you have drawn can be send to your printer too, if you use the <function><link linkend="ref_open_printer">open printer</link></function> command.</para>
      <para>To allow for some (very) limited version of animated graphics, <application>yabasic</application> offers the commands <function><link linkend="ref_getbit">getbit$</link></function> and <function><link linkend="ref_putbit">putbit</link></function>, which retrieve rectangular regions from the graphics-window into a string or vice versa.</para>
      <para>If you want to sense mouse-clicks, you may use the <function><link linkend="ref_inkey">inkey$</link></function>-function.</para>
    </sect1>


    <sect1>
      <title>Reading from and writing to files</title>
      <para>Before you may read or write a file, you need to <function><link linkend="ref_open">open</link></function> it; once you are done, you should <function><link linkend="ref_close">close</link></function> 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 ('<literal>#</literal>') followd by the number of the file after the keyword <function><link linkend="ref_input">input</link></function> (for reading from) or <function><link linkend="ref_print">print</link></function> (for writing to a file) respectively.</para>
      <para>If you need more control, you may consider reading and writing one byte at a time, using the multi-purpose commands <function><link linkend="ref_peek">peek</link></function> and <function><link linkend="ref_poke">poke</link></function>.</para>
    </sect1>


    <sect1>
      <title>Subroutines and Libraries</title>
      <para>The best way to break any <application>yabasic</application>-program into smaller, more manageable chunks are <emphasis>subroutines</emphasis> and <emphasis>libraries</emphasis>. They are <application>yabasic</application>'s most advanced means of structuring a program.</para>
      <para>Subroutines are created with the command <function><link linkend="ref_sub">sub</link></function>. they accept parameters and may return a value. Subroutines can be called much like any builtin function of <application>yabasic</application>; therefore they allow to <emphasis>extend</emphasis> the language itself.</para>
      <para>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 <emphasis>library</emphasis>. Such a library is contained within a separate file and may be included in any of your programs, using the keyword <function><link linkend="ref_import">import</link></function>.</para>
    </sect1>


    <sect1>
      <title>String processing</title>
      <para><application>yabasic</application> has the usual functions to extract parts from a string: <function><link linkend="ref_left">left$</link></function>, <function><link linkend="ref_mid">mid$</link></function> and <function><link linkend="ref_right">right$</link></function>. Note, that all of them can be assigned to, i.e. they may <emphasis>change</emphasis> part of a string.</para>
      <para>If you want to split a string into tokens you should use the functions <function><link linkend="ref_token">token</link></function> or <function><link linkend="ref_split">split</link></function>.</para>
      <para>There is quite a bunch of other string-processing functions like <function><link linkend="ref_upper">upper$</link></function> (converting to upper case), <function><link linkend="ref_instr">instr</link></function> (finding one string within the other), <function><link linkend="ref_chr">chr$</link></function> (converting an ascii-code into a character), <function><link linkend="ref_glob">glob</link></function> (testing a string against a pattern) and more. Just follow the links.</para>
    </sect1>


    <sect1>
      <title>Arithmetic</title>
      <para><application>Yabasic</application> handles numbers and arithmetic: You may calculate trigonometric functions like <function><link linkend="ref_sin">sin</link></function> or <function><link linkend="ref_atan">atan</link></function>, or logarithms (with <function><link linkend="ref_log">log</link></function>). Bitwise operations, like <function><link linkend="ref_arithmetic_and">and</link></function> or <function><link linkend="ref_arithmetic_or">or</link></function> are available as well <function><link linkend="ref_min">min</link></function> or <function><link linkend="ref_max">max</link></function> (calculate the minimum or maximum of its argument) or <function><link linkend="ref_mod">mod</link></function> or <function><link linkend="ref_int">int</link></function> (reminder of a division or integer part or a number).</para>
      </sect1>


    <sect1>
      <title>Data and such</title>
      <para>You may store data within your program within <function><link linkend="ref_data">data</link></function>-statements; during execution you will probably want to <function><link linkend="ref_read">read</link></function> it into <emphasis>arrays</emphasis>, which must have been <function><link linkend="ref_dim">dim</link></function>ed before.</para>
    </sect1>


    <sect1>
      <title>Other interesting commands.</title>
      <itemizedlist>
<listitem>
      <para><application>Yabasic</application> programs may start other programs with the commands <function><link linkend="ref_system">system</link></function> and <function><link linkend="ref_system2">system$</link></function>.</para>
</listitem>
<listitem>
      <para><function><link linkend="ref_peek">peek</link></function> and <function><link linkend="ref_poke">poke</link></function> allow to get and set internal information; either for the operating system (i.e. Unix or Windows) or <application>yabasic</application> itself.</para>
</listitem>
<listitem>
      <para>The current time or date can be retrieved with (guess what !) <function><link linkend="ref_time">time$</link></function> and <function><link linkend="ref_date">date$</link></function>.</para>
</listitem>
      </itemizedlist>
    </sect1>
  </chapter>




  <chapter id="chapter_ref_words">
    <title>All commands and functions of <application>yabasic</application></title>


    <sect1 renderas="sect2" id="ref_note_on_placeholders">
      <title>A note on the <emphasis>synopsis</emphasis>-sections of reference-entries.</title>
      <para>Each reference-entries to follow contains a <emphasis>synopsis</emphasis> section, which specifies two things:</para>
      <itemizedlist>
<listitem>
   <para>The type and number of arguments each function or command accepts.</para>
</listitem>
<listitem>
   <para>The type of value (if any) returned by the function.</para>
</listitem>
      </itemizedlist>
      <para>If possible, the name of the variables is choosen to give a hint on their meaning, e.g. a variable might be named <systemitem>colour$</systemitem>, if it should contain a colour.</para>
      <para>An example:</para>
      <synopsis>
xpos=mousex()
xpos=mousex(mouseclick$)
</synopsis>
      <para>This is the synopsis for the <function>mousex</function>-function, which returns the horizontal screen-position of your mouse-cursor.</para>
      <para>The synopsis contains two lines, showing, that <function>mousex</function> might be called with or without an argument and returns a number (see the reference entry for <link linkend="ref_mousex">mousex</link> for a description).</para>
      <para>The synopsis above contains two variables, whose names give a hint on their meaning:</para>
      <itemizedlist>
<listitem>
   <para>The name <varname>mouseclick$</varname> is chosen, because the <function>mousex</function>-function accepts a string representing a mouse click as returned by <function>inkey$</function>.</para>
</listitem>
<listitem>
   <para>The name <varname>xpos</varname> is chosen, because <function>mousex</function> returns a horizontal or <emphasis>x</emphasis>-position.</para>
</listitem>
      </itemizedlist>
      <para>If there is no obvious name for the values accepted or returned by a function or command, a name like <varname>a$</varname>, <varname>x</varname> or <varname>foo</varname> is chosen.</para>
    </sect1>


    <sect1 renderas="sect2" id="ref_a">
      <title>A</title>


      <refentry id="ref_abs">
<refmeta>
   <refentrytitle>abs()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>abs()</refname>
   <refpurpose>returns the absolute value of its numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>y=abs(x)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>If the argument of the <function>abs</function>-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).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print abs(-2),abs(2)
          </programlisting>
     <para>This example will print <computeroutput>2 2</computeroutput></para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_sig"><function>sig</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_acos">
<refmeta>
   <refentrytitle>acos()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>acos()</refname>
   <refpurpose>returns the arcus cosine of its numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>x=acos(angle)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>acos</function> is the arcus cosine-function, i.e. the inverse of the <link linkend="ref_cos"><function>cos</function></link>-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 <function>acos</function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print acos(0.5),acos(cos(pi))
          </programlisting>
     <para>This example will print <computeroutput>1.0472 3.14159</computeroutput> which are &pgr;/3 and &pgr; respectively.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_cos"><function>cos</function></link>, <link linkend="ref_asin"><function>asin</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_logical_and">
<refmeta>
   <refentrytitle>and</refentrytitle>
</refmeta>
<refnamediv>
   <refname>and</refname>
   <refpurpose>logical and, used in conditions</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (a and b) …
while (a and b) …
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Used in conditions (e.g within <function><link linkend="ref_if">if</link></function>, <function><link linkend="ref_while">while</link></function> or <function><link linkend="ref_until">until</link></function>) to join two expressions. Returns <constant>true</constant>, if and only if its left and right argument are both <constant>true</constant> and <constant>false</constant> otherwise.</para>
   <para>Note, that <link linkend="ref_logical_shortcuts"><emphasis>logical shortcuts</emphasis></link>may take place.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number" a
if (a>=1 and a<=9) print "your input is between 1 and 9"
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_logical_or"><function>or</function></link>,<link linkend="ref_not"><function>not</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_arithmetic_and">
<refmeta>
   <refentrytitle>and()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>and()</refname>
   <refpurpose>the bitwise arithmetic <function>and</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=and(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Used to compute the bitwise <function>and</function> 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.</para>
   <para>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 <function>and</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print and(6,3)
          </programlisting>
     <para>This will print <computeroutput>2</computeroutput>. 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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arithmetic_or"><function>or</function></link>, <link linkend="ref_eor"><function>eor</function></link> and <link linkend="ref_not"><function>not</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_arraydim">
<refmeta>
   <refentrytitle>arraydim()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>arraydim()</refname>
   <refpurpose>returns the dimension of the array, which is passed as an <link linkend="ref_array_references">array reference</link></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>a=arraydim(b())</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>If you apply the <literal>arraydim()</literal>-function on a one-dimensional array (i.e. a vector) it will return <computeroutput>1</computeroutput>, on a two-dimensional array (i.e. a matrix) it will return 2, and so on.</para>
<para>This is mostly used within subroutines, which expect an array among their parameters. Such subroutines tend to use the <function>arraydim</function>-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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
dim a(10,10),b(10)
print arraydim(a()),arraydim(b())
          </programlisting>
     <para>This will print <computeroutput>2 1</computeroutput>, which are the dimension of the arrays <literal>a()</literal> and <literal>b()</literal>. You may check out the function <link linkend="ref_arraysize"><function>arraysize</function></link> for a full-fledged example.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arraysize"><function>arraysize</function></link> and <link linkend="ref_dim"><function>dim</function></link>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_arraysize">
<refmeta>
   <refentrytitle>arraysize()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>arraysize()</refname>
   <refpurpose>returns the size of a dimension of an array</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>x=arraysize(a(),b)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>arraysize</function>-function computes the size of a specified dimension of a specified array. Here, <emphasis>size</emphasis> stands for the maximum number, that may be used as an index for this array. The first argument to this function must be an <link linkend="ref_array_references">reference to an array</link>, the second one specifies, which of the multiple dimensions of the array should be taken to calculate the size.</para>
   <para>An Example involving subroutines: Let's say, an array has been declared as <literal>dim a(10,20)</literal> (that is a two-dimensional array or a matrix). If this array is passed as an <link linkend="ref_array_references">array reference</link> to a subroutine, this sub will not know, what sort of array has been passed. With the <function>arraydim</function>-function the sub will be able to find the dimension of the array, with the <function>arraysize</function>-function it will be able to find out the size of this array in its two dimensions, which will be 10 and 20 respectively.</para>
   <para>Our sample array is two dimensional; if you envision it as a matrix this matrix has 10 lines and 20 columns (see the <function>dim</function>-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 <literal>arraysize(a(),1)</literal> and <literal>arraysize(a(),2)</literal> respectively. Refer to the example below for a typical usage.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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 "Result:"
for x=1 to 20
   for y=10 to 1 step -1
      print c(y,x)," ";
   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())<>2 or arraydim(m2())<>2 or arraydim(r())<>2) then
      error "Need two dimensional arrays as input"
   endif


   y=arraysize(m1(),1):x=arraysize(m1(),2)
   if (arraysize(m2(),1)<>y or arraysize(m2(),2)<>x) then
      error "The two matrices cannot be added elementwise"
   endif


   if (arraysize(r(),1)<>y or arraysize(r(),2)<>x) then
      error "The result cannot be stored in the third argument"
   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


          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arraydim"><function>arraydim</function></link> and <link linkend="ref_dim"><function>dim</function></link>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_asc">
<refmeta>
   <refentrytitle>asc()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>asc()</refname>
   <refpurpose>accepts a string and returns the position of its first character within the <acronym>ascii</acronym> charset</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>a=asc(char$)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>asc</function>-function accepts a string, takes its first character and looks it up within the <acronym>ascii</acronym>-charset; this position will be returned. The <function>asc</function>-function is the opposite of the <function><link linkend="ref_chr">chr$</link></function>-function. There are valid uses for <function>asc</function>, however, comparing strings (i.e. to bring them into alphabetical sequence) is <emphasis>not</emphasis> among them; in such many cases you might consider to compare strings directly with <literal><</literal>, <literal>=</literal> and <literal>></literal> (rather than converting a string to a number and comparing this number).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a letter between 'a' and 'y': " a$
if (a$<"a" or a$>"y") print a$," is not in the proper range":end
print "The letter after ",a$," is ",chr$(asc(a$)+1)
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_chr"><function>chr$</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_asin">
<refmeta>
   <refentrytitle>asin()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>asin()</refname>
   <refpurpose>returns the arcus sine of its numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>angle=asin(x)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>acos</function> is the arcus sine-function, i.e. the inverse of the <link linkend="ref_sin"><function>sin</function></link>-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 <function>asin</function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print asin(0.5),asin(sin(pi))
          </programlisting>
     <para>This will print <computeroutput>0.523599 -2.06823e-13</computeroutput> which is &pgr; and almost 0 respectively.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_sin"><function>sin</function></link>, <link linkend="ref_acos"><function>acos</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_at">
<refmeta>
   <refentrytitle>at()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>at()</refname>
   <refpurpose>can be used in the <function>print</function>-command to place the output at a specified position</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen

print at(a,b)
print @(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>at</function>-clause takes two numeric arguments (e.g. <literal>at(2,3)</literal>) and can be inserted after the <literal>print</literal>-keyword. <literal>at()</literal> can be used only if <link linkend="ref_clear_screen"><function>clear screen</function></link> has been executed at least once within the program (otherwise you will get an error).</para>
   <para>The two numeric arguments of the <function>at</function>-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, <application>yabasic</application> 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 <function>at</function>-clause may vary. To get the size of your terminal you may use the <link linkend="ref_peek"><function>peek</function></link>-function: <literal>peek("screenwidth")</literal> returns the width of your terminal and <literal>peek("screenheight")</literal> its height.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
maxx=peek("screenwidth")-1:maxy=peek("screenheight")-1
for x=0 to maxx
  print at(x,maxy*(0.5+sin(2*pi*x/maxx)/2)) "*"
next x
          </programlisting>
     <para>This example plots a full period of the sine-function across the screen.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_print"><function>print</function></link>, <link linkend="ref_clear_screen"><function>clear screen</function></link>, <link linkend="ref_color"><function>color</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_atan">
<refmeta>
   <refentrytitle>atan()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>atan()</refname>
   <refpurpose>returns the arcus tangens of its numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
angle=atan(a,b)
angle=atan(a)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>atan</function> is the arcus-tangens-function, i.e. the inverse of the <link linkend="ref_tan"><function>tan</function></link>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the <function>tan</function>-function will produce the argument passed to the <function>atan</function>-function.</para>
   <para>The <function>atan</function>-function has a second form, which accepts two arguments: <function>atan(a,b)</function> which is (mostly) equivilantly to <function>atan(a/b)</function> <emphasis>except</emphasis> for the fact, that the two-argument-form returns an angle in the range -&pgr; to &pgr;, whereas the one-argument-form returns an angle in the range -&pgr;/2 to &pgr;/2. To understand this you have to be good at math.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print atan(1),atan(tan(pi)),atan(-0,-1),atan(-0,1)
          </programlisting>
   <para>This will print <computeroutput>0.463648 2.06823e-13 -3.14159 3.14159</computeroutput> which is &pgr;/4, almost 0, -&pgr; and &pgr; respectively.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_tan">tan</link></function>, <function><link linkend="ref_sin">sin</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_b">
      <title>B</title>


      <refentry id="ref_beep">
<refmeta>
   <refentrytitle>beep</refentrytitle>
</refmeta>
<refnamediv>
   <refname>beep</refname>
   <refpurpose>ring the bell within your computer; a synonym for <function>bell</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>beep</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>bell</function>-command rings the bell within your computer once. This command is <emphasis>not</emphasis> a sound-interface, so you can neither vary the length or the height of the sound (technically, it just prints <literal>\a</literal>). <function>bell</function> is exactly the same as <function><link linkend="ref_beep">beep</link></function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
beep:print "This is a problem ..."
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_beep">beep</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_bell">
<refmeta>
   <refentrytitle>bell</refentrytitle>
</refmeta>
<refnamediv>
   <refname>bell</refname>
   <refpurpose>ring the bell within your computer (just as <function>beep</function>)</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>bell</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>beep</function>-command rings the bell within your computer once. <function>beep</function> is a synonym for <function><link linkend="ref_bell">bell</link></function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "This is a problem ...":beep
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_bell">bell</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_bin">
<refmeta>
   <refentrytitle>bin$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>bin$()</refname>
   <refpurpose>converts a number into a sequence of binary digits</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>hexadecimal$=bin$(decimal)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>bin$</function>-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 <function>bin$</function>, the resulting string will be preceeded by a '-'.</para>
   <para>If you want to convert the other way around (i.e. from binary to decimal) you may use the <function><link linkend="ref_dec">dec</link></function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 100
  print bin$(a)
next a
          </programlisting>
     <para>This example prints the binary representation of all digits between 1 and 100.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_hex">hex$</link></function>, <function><link linkend="ref_dec">dec</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_bind">
<refmeta>
   <refentrytitle>bind()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>bind()</refname>
   <refpurpose>Binds a <application>yabasic</application>-program and the <application>yabasic</application>-interpreter together into a <emphasis>standalone</emphasis> program.</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>bind("foo.exe")</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>bind</function>-command combines your own <application>yabasic</application>-program 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 <application>yabasic</application> installed.</para>
   <para>Please see the section about <link linkend="ref_standalone">creating a <emphasis>standalone</emphasis>-program</link> for details.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
if (!peek("isbound")) then
  bind "foo"
  print "Successfully created the standalone executable 'foo' !"
  exit
endif


print "Hello World !"
          </programlisting>
     <para>This example creates a standalone program <filename>foo</filename> from itself.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para>The section about <link linkend="ref_standalone">creating a <emphasis>standalone</emphasis>-program</link>, the <link linkend="ref_peek"><function>peek</function></link>-function and the commandline options for <link linkend="unix_options">Unix</link> and <link linkend="windows_options">Windows</link>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_box">
<refmeta>
   <refentrytitle>box</refentrytitle>
</refmeta>
<refnamediv>
   <refname>box</refname>
   <refpurpose>draw a rectancle. A synonym for <function>rectangle</function></refpurpose>
</refnamediv>

<refsynopsisdiv>
   <synopsis>
See the <function><link linkend="ref_rectangle">rectangle</link></function>-command.
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>box</function>-command does exactly the same as the <function><link linkend="ref_rectangle">rectangle</link></function>-command; it is just a <emphasis>synonym</emphasis>. Therefore you should refer to the entry for the <function><link linkend="ref_rectangle">rectangle</link></function>-command for further information.</para>
</refsect1>
      </refentry>


      <refentry id="ref_break">
<refmeta>
   <refentrytitle>break</refentrytitle>
</refmeta>
<refnamediv>
   <refname>break</refname>
   <refpurpose>breaks out of a switch statement or a loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>break</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>break</function> transfers control immediately outside the enclosing loop or switch statement. This is the preferred way of leaving a such a statement (rather than <function>goto</function>, which is still possible in most cases).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10
  break
  print "Hi"
next a


while(1)
  break
  print "Hi"
wend


repeat
  break
  print "Hi"
until(0)


switch 1
case 1:break
case 2:case 3:print "Hi"
end switch
          </programlisting>
     <para>This example prints nothing at all, because each of the loops (and the <function>switch</function>-statement) does an immediate <function>break</function> (before it could print any "Hi").</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_for">for</link></function>, <function><link linkend="ref_while">while</link></function>, <function><link linkend="ref_repeat">repeat</link></function> and <function><link linkend="ref_switch">switch</link></function>.</para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_c">
      <title>C</title>


      <refentry id="ref_case">
<refmeta>
   <refentrytitle>case</refentrytitle>
</refmeta>
<refnamediv>
   <refname>case</refname>
   <refpurpose>mark the different cases within a <function><link linkend="ref_switch">switch</link></function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
switch a
  case 1
  case 2
  …
end switch




switch a$
  case "a"
  case "b"
  …
end switch
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Please see the <function><link linkend="ref_switch">switch</link></function>-statement.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input a
switch(a)
  case 1:print "one":break
  case 2:print "two":break
  default:print "more"
end switch
          </programlisting>
     <para>Depending on your input (a number is expected) this code will print <computeroutput>one</computeroutput> or <computeroutput>two</computeroutput> or otherwise <computeroutput>more</computeroutput>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_switch">switch</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_chr">
<refmeta>
   <refentrytitle>chr$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>chr$()</refname>
   <refpurpose>accepts a number and returns the character at this position within the <acronym>ascii</acronym> charset</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>character$=chr$(ascii)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>chr$</function>-function is the opposite of the <function><link linkend="ref_asc">asc</link></function>-function. It looks up and returns the character at the given position within the <acronym>ascii</acronym>-charset. It's typical use is to construct <emphasis>nonprintable</emphasis> characters which do not occur on your keyboard.</para>
   <para>Nevertheless you won't use <function>chr$</function> as often as you might think, because the most important nonprintable characters can be constructed using <emphasis><link linkend="ref_escape_sequences">escape-sequences</link></emphasis> using the \-character (e.g. you might use \n instead of <function>chr$(10)</function> wherever you want to use the newline-character).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "a",chr$(10),"b"
          </programlisting>
     <para>This will print the letters 'a' and 'b' in different lines because of the intervening newline-character, which is returned by <function>chr$(10)</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_asc">asc</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_circle">
<refmeta>
   <refentrytitle>circle</refentrytitle>
</refmeta>
<refnamediv>
   <refname>circle</refname>
   <refpurpose>draws a circle in the graphic-window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
circle x,y,r
clear circle x,y,r
fill circle x,y,r
clear fill circle x,y,r
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>circle</function>-command accepts three parameters: The x- and y-coordinates of the center and the radius of the circle.</para>
   <para>Some more observations related with the <function>circle</function>-command:</para>
   <itemizedlist>
     <listitem>
       <para>The graphic-window must have been opened already.</para>
     </listitem>
     <listitem>
       <para>The circle may well extend over the boundaries of the window.</para>
     </listitem>
     <listitem>
       <para>If you have issued <function><link linkend="ref_open_printer">open printer</link></function> before, the circle will finally appear in the printed hardcopy of the window.</para>
     </listitem>
     <listitem>
       <para><function>fill circle</function> will draw a filled (with black ink) circle.</para>
     </listitem>
     <listitem>
       <para><function>clear circle</function> will erase (or clear) the outline of the circle.</para>
     </listitem>
     <listitem>
       <para><function>clear fill circle</function> or <function>fill clear circle</function> will erase the full area of the circle.</para>
     </listitem>
   </itemizedlist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>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 (<function>fill circle x,y,10</function>), then most of this circle is erased again (<function>clear fill circle x,y,8</function>). 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).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_window">open window</link></function>, <function><link linkend="ref_open_printer">open printer</link></function>, <function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_rectangle">rectangle</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_clear">
<refmeta>
   <refentrytitle>clear</refentrytitle>
</refmeta>
<refnamediv>
   <refname>clear</refname>
   <refpurpose>Erase <function>circle</function>s or <function>rectangle</function>s</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear rectangle 10,10,90,90
clear fill circle 50,50,20
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>May be used within the <function><link linkend="ref_circle">circle</link></function> or <function><link linkend="ref_rectangle">rectangle</link></function> command and causes these shapes to be erased (i.e. be drawn in the colour of the background).</para>
   <para><function>fill</function> can be used in conjunction with and whereever the <function><link linkend="ref_fill">fill</link></function>-clause may appear. Used alone, <function>clear</function> will erase the outline (not the interior) of the shape (circle or rectangle); together with <function>fill</function> the whole shape (including its interior) is erased.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
          </programlisting>
     <para>This opens a window and draws a pacman-like figure.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_clear">clear</link></function>, <function><link linkend="ref_circle">circle</link></function>, <function><link linkend="ref_rectangle">rectangle</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_clear_screen">
<refmeta>
   <refentrytitle>clear screen</refentrytitle>
</refmeta>
<refnamediv>
   <refname>clear screen</refname>
   <refpurpose>erases the text window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>clear screen</function> erases the text window (the window where the output of <function>print</function> appears).</para>
   <para>It must be issued at least once, before some advanced screen-commands (e.g. <function>print at</function> or <function>inkey$</function>) may be called; this requirement is due to some limititations of the <systemitem>curses</systemitem>-library, which is used by <application>yabasic</application> under <acronym>Unix</acronym> for some commands.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
print "Please press a key : ";
a$=inkey$
print a$
          </programlisting>
     <para>The <function>clear screen</function> command is essential here; if it would be omitted, <application>yabasic</application> would issue an error ("<computeroutput>need to call 'clear screen' first</computeroutput>") while trying to execute the <function>inkey$</function>-function.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_inkey">inkey$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_clear_window">
<refmeta>
   <refentrytitle>clear window</refentrytitle>
</refmeta>
<refnamediv>
   <refname>clear window</refname>
   <refpurpose>clear the graphic window and begin a new page, if prining is under way</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>clear window</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>clear window</function> clears the graphic window. If you have started prining the graphic via <function><link linkend="ref_open_printer">open printer</link></function>, the <function>clear window</function>-command starts a new page as well.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
open printer "t.ps"


for a=1 to 10
if (a>1) clear window
text 100,100,"Hallo "+str$(a)
next a


close printer
close window
          </programlisting>
     <para>This example prints 10 pages, with the text "Hello 1", "Hello 2", … and so on. The <function>clear screen</function>-command clears the graphics window and starts a new page.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_window">open window</link></function>, <function><link linkend="ref_open_printer">open printer</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_close">
<refmeta>
   <refentrytitle>close</refentrytitle>
</refmeta>
<refnamediv>
   <refname>close</refname>
   <refpurpose>close a file, which has been opened before</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
close filenum
close # filenum
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>close</function>-command closes an open file. You should issue this command as soon as you are done with reading from or writing to a file.</para>
   <para></para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open "my.data" for reading as 1
input #1 a
print a
close 1
          </programlisting>
     <para>This program opens the file <systemitem>"my.data"</systemitem>, reads a number from it, prints this number and closes the file again.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open">open</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_close_curve">
<refmeta>
   <refentrytitle>close curve</refentrytitle>
</refmeta>
<refnamediv>
   <refname>close curve</refname>
   <refpurpose>close a curve, that has been drawn by the <function>line</function>-command</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
new curve
line to x1,y1

close curve
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>close curve</function>-command closes a sequence of lines, that has been drawn by repeated <function>line to</function>-commands.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
new curve
line to 100,50
line to 150,150
line to 50,150
close curve
          </programlisting>
     <para>This example draws a triangle: The three <function>line to</function>-commands draw two lines; the final line is however not drawn explicitly, but drawn by the <function>close curve</function>-command.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_new_curve">new curve</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_close_printer">
<refmeta>
   <refentrytitle>close printer</refentrytitle>
</refmeta>
<refnamediv>
   <refname>close printer</refname>
   <refpurpose>stops printing of graphics</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>close printer</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>close printer</function>-command ends the printing graphics. Between <function><link linkend="ref_open_printer">open printer</link></function> and <function>close printer</function> everything you draw (e.g. circles, lines …) is sent to your printer. <function>close printer</function> puts an end to printing and will make your printer eject the page.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
open printer
circle 100,100,50
close printer
close window
          </programlisting>
     <para>As soon as <function>close printer</function> is executed, your printer will eject a page with a circle on it.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_printer">open printer</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_close_window">
<refmeta>
   <refentrytitle>close window</refentrytitle>
</refmeta>
<refnamediv>
   <refname>close window</refname>
   <refpurpose>close the graphics-window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>close window</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>close window</function>-command closes the graphics-window, i.e. it makes it disappear from your screen. It includes an implicit <function>close printer</function>, if a printer has been opened previously.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
circle 100,100,50
close window
          </programlisting>
     <para>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..</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_printer">open window</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_color">
<refmeta>
   <refentrytitle>color</refentrytitle>
</refmeta>
<refnamediv>
   <refname>color</refname>
   <refpurpose>print with color</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print color(fore$) text$
print color(fore$,back$) text$
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Not a seperate command, but part of the <function>print</function>-command; may be included just after <function>print</function> and can only be issued after <function>clear screen</function> has been executed.</para>
   <para><function>color()</function> takes one or two string-arguments, specifying the color of the text and (optionally) the background.</para>
   <para>The one or two strings passed to <function>color()</function> can be one of these: <systemitem>"black"</systemitem>, <systemitem>"white"</systemitem>, <systemitem>"red"</systemitem>, <systemitem>"blue"</systemitem>, <systemitem>"green"</systemitem>, <systemitem>"yellow"</systemitem>, <systemitem>"cyan"</systemitem> and <systemitem>"magenta"</systemitem> (which can be abbreviated as <systemitem>"bla"</systemitem>, <systemitem>"whi"</systemitem>, <systemitem>"red"</systemitem>, <systemitem>"blu"</systemitem>, <systemitem>"gre"</systemitem>, <systemitem>"yel"</systemitem>, <systemitem>"cya"</systemitem> and <systemitem>"mag"</systemitem> respectively).</para>
   <para><function>color()</function> can only be used, if <function><link linkend="ref_clear_screen">clear scren</link></function> has been issued at least once.</para>
   <para>Note, that <function>color()</function> can be written as <function>colour()</function> too.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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))) " Hallo ";
  pause 0.01
loop
data "black","white","red","blue"
data "green","yellow","cyan","magenta"
          </programlisting>
     <para>This prints the word <systemitem>" Hallo "</systemitem> in all colors accross your screen.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_clear_screen">clear screen</link></function>, <function><link linkend="ref_at">at</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_colour">
<refmeta>
   <refentrytitle>colour</refentrytitle>
</refmeta>
<refnamediv>
   <refname>colour</refname>
   <refpurpose>see <function><link linkend="ref_color">color</link></function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print colour(fore$) text$
print colour(fore$,back$) text$
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_color">color</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_compile">
<refmeta>
   <refentrytitle>compile</refentrytitle>
</refmeta>
<refnamediv>
   <refname>compile</refname>
   <refpurpose>compile a string with <acronym>yabasic</acronym>-code <emphasis>on the fly</emphasis></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>compile(code$)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>This is an advanced command (closely related with the <function><link linkend="ref_execute">execute</link></function>-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.</para>
   <para>Note, that there is no way to <emphasis>remove</emphasis> the compiled code.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
compile("sub mysub(a):print a:end sub")
mysub(2)
          </programlisting>
     <para>This example creates a function named <function>mysub</function>, which simply prints its single argument.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_execute">execute</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_continue">
<refmeta>
   <refentrytitle>continue</refentrytitle>
</refmeta>
<refnamediv>
   <refname>continue</refname>
   <refpurpose>start the next iteration of a <function>for</function>-, <function>do</function>-, <function>repeat</function>- or <function>while</function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>continue</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>You may use <function>continue</function> 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: <function>for</function>- and <function>while</function>-loops will evaluate their respective conditions, <function>do</function>- and <function>repeat</function>-loops will not.</para>
   <remark>Remark: Another way to change the flow of execution within a loop, is the <function>break</function>-command.</remark>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 100
  if mod(a,2)=0 continue
  print a
next a
          </programlisting>
     <para>This example will print all odd numbers between 1 and 100.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_for">for</link></function>, <function><link linkend="ref_do">do</link></function>, <function><link linkend="ref_repeat">repeat</link></function>, <function><link linkend="ref_while">while</link></function>, <function><link linkend="ref_break">break</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_cos">
<refmeta>
   <refentrytitle>cos()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>cos()</refname>
   <refpurpose>return the cosine of its single argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=cos(angle)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>cos</function>-function expects an angle (in radian) and returns its cosine.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print cos(pi)
          </programlisting>
     <para>This example will print <computeroutput>-1</computeroutput>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_acos">acos</link></function>, <function><link linkend="ref_sin">sin</link></function></para>
</refsect1>
      </refentry>
    </sect1>


    <sect1 renderas="sect2" id="ref_d">
      <title>D</title>


      <refentry id="ref_data">
<refmeta>
   <refentrytitle>data</refentrytitle>
</refmeta>
<refnamediv>
   <refname>data</refname>
   <refpurpose>introduces a list of data-items</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
data 9,"world"

read b,a$
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>data</function>-keyword introduces a list of comma-seperated list of strings or numbers, which may be retrieved with the <function><link linkend="ref_read">read</link></function>-command.</para>
   <para>The <function>data</function>-command itself does nothing; it just stores data. A single <function>data</function>-command may precede an arbitrarily long list of values, in which strings or numbers may be mixed at will.</para>
   <para><application>yabasic</application> internally uses a <systemitem>data-pointer</systemitem> to keep track of the current location within the <function>data</function>-list; this pointer may be reset with the <function><link linkend="ref_restore">restore</link></function>-command.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  restore
  for a=1 to 4
    read num$,num
    print num$,"=",num
  next a
loop
data "eleven",11,"twelve",12,"thirteen",13,"fourteen",14
          </programlisting>
     <para>This example just prints a series of lines <computeroutput>eleven=11</computeroutput> up to <computeroutput>fourteen=14</computeroutput> and so on without end.</para>
     <para>The <function>restore</function>-command ensures that the list of <function>data</function>-items is read from the start with every iteration.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_read">read</link></function>, <function><link linkend="ref_restore">restore</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_date">
<refmeta>
   <refentrytitle>date$</refentrytitle>
</refmeta>
<refnamediv>
   <refname>date$</refname>
   <refpurpose>returns a string with various components of the current date</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>a$=date$</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>date$</function>-function (which <emphasis>must</emphasis> be called without parantheses; i.e. <function>date$()</function> would be an error) returns a string containing various components of a date; an example would be <computeroutput>4-05-27-2004-Thu-May</computeroutput>. This string consists of various fields seperated by hyphens ("<computeroutput>-</computeroutput>"):</para>
      <itemizedlist>
<listitem>
       <para>The day within the week as a number in the range 0 (=sunday) to 6 (=saturday) (in the example above: <computeroutput>4</computeroutput>, i.e. thursday).</para>
</listitem>
<listitem>
       <para>The month as a number in the range 1 (=january) to 12 (=december) (in the example: <computeroutput>5</computeroutput> which stands for may).</para>
</listitem>
<listitem>
       <para>The day within the month as a number in the range 1 to 31 (in the example: <computeroutput>27</computeroutput>).</para>
</listitem>
<listitem>
       <para>The full, 4-digit  year (in the example: <computeroutput>2004</computeroutput>, which reminds me that I should adjust the clock within my computer …).</para>
</listitem>
<listitem>
       <para>The abbreviated name of the day within the week (<computeroutput>Mon</computeroutput> to <computeroutput>Sun</computeroutput>).</para>
</listitem>
<listitem>
       <para>The abbreviated name of the month (<computeroutput>Jan</computeroutput> to <computeroutput>Dec</computeroutput>).</para>
</listitem>
      </itemizedlist>
   <para>Therefore the whole example above (<computeroutput>4-05-27-2004-Thu-May</computeroutput>) would read: day 4 in the week (counting from 0), May 27 in the year 2004, which is a thursday in May.</para>
   <para>Note, that all fields within the string returned by <function>date$</function> have a fixed with (numbers are padded with zeroes); therefore it is easy to extract the various fields of a date format with <function>mid$</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
rem   Two ways to print the same ...


print mid$(date$,3,10)


dim fields$(6)
a=split(date$,fields$(),"-")
print fields$(2),"-",fields$(3),"-",fields$(4)
          </programlisting>
     <para>This example shows two different techniques to extract components from the value returned by <function>date$</function>. The <function>mid$</function>-function is the preferred way, but you could just as well <function>split</function> the return-value of <function>date$</function> at every "-" and store the result within an array of strings.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_time">time$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_dec">
<refmeta>
   <refentrytitle>dec()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>dec()</refname>
   <refpurpose>convert a base 2 or base 16 number into decimal form</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a=dec(number$)
a=dec(number$,base)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>dec</function>-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 (<varname>base</varname>) might be used to specify a base other than 16. However, currently only base 2 or base 16 are supported.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a binary number: " a$
print a$," is ",dec(a$)
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_bin"><function>bin$</function></link>, <link linkend="ref_hex"><function>hex$</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_default">
<refmeta>
   <refentrytitle>default</refentrytitle>
</refmeta>
<refnamediv>
   <refname>default</refname>
   <refpurpose>mark the <emphasis>default</emphasis>-branch within a <function><link linkend="ref_switch">switch</link></function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
switch a+3
case 1
  …
case 2
  …
default
  …
end switch
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>default</function>-clause is an optional part of the <function><link linkend="ref_switch">switch</link></function>-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 <function><link linkend="ref_case">case</link></function>-clause).</para>
   <para>So <function>default</function> specifies a default to be executed, if none of the explicitly named cases matches; hence its name.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Please enter a number between 0 and 6,"
print "specifying a day in the week."
input d
switch d
case 0:print "Monday":break
case 1:print "Tuesday":break
case 2:print "Wednesday":break
case 3:print "Thursday":break
case 4:print "Friday":break
case 5:print "Saturday":break
case 6:print "Sunday":break
default:print "Hey you entered something invalid !"
end switch
          </programlisting>
     <para>This program translates a number between 0 and 6 into the name of a weekday; the <function>default</function>-case is used to detect (and complain about) invalid input.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_sub"><function>sub</function></link>, <link linkend="ref_case"><function>case</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_dim">
<refmeta>
   <refentrytitle>dim</refentrytitle>
</refmeta>
<refnamediv>
   <refname>dim</refname>
   <refpurpose>create an array prior to its first use</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
dim array(x,y)
dim array$(x,y)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>dim</function>-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.</para>
   <para>When an array is created with the <function>dim</function>-statement, memory is allocated and all elements are initialized with either 0 (for numerical arrays) or "" (for string arrays).</para>
   <para>If the array already existed, and the <function>dim</function>-statement specifies a larger size than the current size, the array is enlarged and any old content is preserved.</para>
   <para>Note, that <function>dim</function> cannot be used to shrink an array: If you specify a size, that is smaller than the current size, the <function>dim</function>-command does nothing.</para>
   <para>Finally: To create an array, that is only known within a single subroutine, you should use the command <function><link linkend="ref_local">local</link></function>, which creates local variables as well as local arrays.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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),"\t";
    next p
    print
  next q
end sub
          </programlisting>
     <para>This example creates a 2-dimenional array (i.e. a <emphasis>matrix</emphasis>) with the <function>dim</function>-statement and fills it with random numbers. The second <function>dim</function>-statement enlarges the array, all new elements are filled with 0.</para>
     <para>The subroutine <function>printmatrix</function> just does, what its name says.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arraysize"><function>arraysize</function></link>, <link linkend="ref_arraydim"><function>arraydim</function></link>, <function><link linkend="ref_local">local</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_do">
<refmeta>
   <refentrytitle>do</refentrytitle>
</refmeta>
<refnamediv>
   <refname>do</refname>
   <refpurpose>start a (conditionless) <function>do-loop</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
do

loop</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Starts a loop, which is terminated by <function>loop</function>; everything between <function>do</function> and <function>loop</function> will be repeated forever. This loop has no condition, so it is an infinite loop; note however, that a <function><link linkend="ref_break">break</link></function>- or <function><link linkend="ref_goto">goto</link></function>-statement might be used to leave this loop anytime.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  a=a+1
  print a
  if (a>100) break
loop
          </programlisting>
     <para>This example prints the numbers between 1 and 101. The <function>break</function>-statement is used to leave the loop.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_loop"><function>loop</function></link>, <link linkend="ref_repeat"><function>repeat</function></link>, <link linkend="ref_while"><function>while</function></link>, <link linkend="ref_break"><function>break</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_doc">
<refmeta>
   <refentrytitle>doc</refentrytitle>
</refmeta>
<refnamediv>
   <refname>doc</refname>
   <refpurpose>special comment, which might be retrieved by the program itself</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
doc   This is a comment
docu  This is another comment
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Introduces a comment, which spans up to the end of the line. But other than the <link linkend="ref_rem"><function>rem</function></link>-comment, any <function>docu</function>-comment is collected within the special <function><link linkend="ref_docu">docu$</link></function>-array and might be retrieved later on. Moreover you might invoke <application>yabasic -docu foo.yab</application> on the <emphasis>commandline</emphasis> to retrieve the embedded documentation within the program <literal>foo.yab</literal>.</para>
   <para>Instead of <function>doc</function> you may just as well write <function>docu</function> or even <function>documentation</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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 "Please input a number: " x
print x*2
          </programlisting>
     <para>This program uses the comments within its code to print out a help message for the user.</para>
     <para>The contents of the <function>doc</function>-lines are retrieved from the <function>docu$</function>-array; if you do not want a comment to be collected within this array, use the <function>rem</function>-statement instead.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_docu"><function>docu$</function></link>, <link linkend="ref_rem"><function>rem</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_docu">
<refmeta>
   <refentrytitle>docu$</refentrytitle>
</refmeta>
<refnamediv>
   <refname>docu$</refname>
   <refpurpose>special array, containing the contents of all docu-statement within the program</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>a$=docu$(1)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Before your program is executed, <application>yabasic</application> collects the content of all the <function>doc</function>-statements within your program within this 1-dimensional array (well only those within the main-program, libraries are skipped).</para>
   <para>You may use the <function>arraysize</function> function to find out, how many lines it contains.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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 "First number: " b
input "Second number: " c


print "The sum of ",b," and ",c," is ",b+c
          </programlisting>
     <para>This program uses the embedded documentation to issue a usage-message.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
<para><link linkend="ref_arraysize"><function>arraydim</function></link>, <link linkend="ref_rem"><function>rem</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_dot">
<refmeta>
   <refentrytitle>dot</refentrytitle>
</refmeta>
<refnamediv>
   <refname>dot</refname>
   <refpurpose>draw a dot in the graphic-window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
dot x,y
clear dot x,y
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Draws a dot at the specified coordinates within your graphic-window. If <link linkend="ref_open_printer">printing</link> is in effect, the dot appears on your printout too.</para>
   <para>Use the functions <link linkend="ref_peek"><function>peek("winheight")</function></link> or <link linkend="ref_peek"><function>peek("winwidth")</function></link> to get the size of your window and hence the boundaries of the coordinates specified for the <function>dot</function>-command.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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)<100) in=in+1
  print 4*in/total
loop
          </programlisting>
     <para>This program uses a well known algorithm to compute &pgr;.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_line"><function>line</function></link>, <link linkend="ref_open_window"><function>open window</function></link></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_e">
      <title>E</title>


      <refentry id="ref_else">
<refmeta>
   <refentrytitle>else</refentrytitle>
</refmeta>
<refnamediv>
   <refname>else</refname>
   <refpurpose>mark an alternative within an <function>if</function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (…) then
  …
else
  …
endif
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>else</function>-statement introduces the alternate branch of an <function>if</function>-statement. I.e. it starts the sequence of statements, which is executed, if the condition of the <function>if</function>-statement is <emphasis>not</emphasis> true.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number: " a
if (mod(a,2)=1) then
  print a," is odd."
else
  print a," is even."
endif
          </programlisting>
     <para>This program detects, if the number you have entered is even or odd.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_if"><function>if</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_elsif">
<refmeta>
   <refentrytitle>elsif</refentrytitle>
</refmeta>
<refnamediv>
   <refname>elsif</refname>
   <refpurpose>starts an alternate condition within an <function>if</function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (…) then
  …
elseif (…)
  …
elsif (…) then
  …
else
  …
endif
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>elsif</function>-statement is used to select a single alternative among a series of choices.</para>
   <para>With each <function>elsif</function>-statement you may specify a condition, which is tested, if the main condition (specified with the <function>if</function>-statement) has failed. Note that <function>elsif</function> might be just as well written as <function>elseif</function>.</para>
   <para>Within the example below, two variables <function>a</function> and <function>b</function> are tested against a range of values. The variable <function>a</function> is tested with the <function>elsif</function>-statement. The very same tests are performed for the variable <function>b</function> too; but here an involved series of <function>if</function>-<function>else</function>-statements is employed, making the tests much more obscure.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number: " a
if (a<0) then
  print "less than 0"
elseif (a<=10) then
  print "between 0 and 10"
elsif (a<=20)
  print "between 11 and 20"
else
  print "over 20"
endif


input "Please enter another number: " b
if (b<0) then
  print "less than 0"
else
  if (b<=10) then
    print "between 0 and 10"
  else
    if (b<=20) then
      print "between 11 and 20"
    else
      print "over 20"
    endif
  endif
endif
          </programlisting>
     <para>Note, that the very same tests are performed for the variables <function>a</function> and <function>b</function>, but can be stated much more clearly with the <function>elsif</function>-statement.</para>
     <para>Note, that <function>elsif</function> might be written as <function>elseif</function> too, and that the keyword <function>then</function> is optional.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_if"><function>if</function></link>, <link linkend="ref_else"><function>else</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_end">
<refmeta>
   <refentrytitle>end</refentrytitle>
</refmeta>
<refnamediv>
   <refname>end</refname>
   <refpurpose>terminate your program</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
end
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Terminate your program. Much (but not exactly) like the <function><link linkend="ref_exit">exit</link></function> command.</para>
   <para>Note, that <function>end</function> may not end your program immediately; if you have opened a window or called <function>clear screen</function>, <application>yabasic</application> assumes, that your user wants to study the output of your program after it has ended; therfore it issues the line <computeroutput>---Program done, press RETURN---</computeroutput> and waits for a key to be pressed. If you do not like this behaviour, consider using <function><link linkend="ref_exit">exit</link></function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Do you want to continue ?"
input "Please answer y(es) or n(o): " a$
if (lower$(left$(a$,1))="n") then
  print "bye"
  end
fi
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_exit">exit</link></function></para>
</refsect1>
      </refentry>



      <refentry id="ref_endif">
<refmeta>
   <refentrytitle>endif</refentrytitle>
</refmeta>
<refnamediv>
   <refname>endif</refname>
   <refpurpose>ends an <function>if</function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (…) then
  …
endif
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>endif</function>-statement closes (or ends) an <function>if</function>-statement.</para>
   <para>Note, that <function>endif</function> may be written in a variety of other ways: <function>end if</function>, <function>end-if</function> or even <function>fi</function>.</para>
   <para>The <function>endif</function>-statement must be omitted, if the <function>if</function>-statement does not contain the keyword <function>then</function> (see the example below). Such an <link linkend="ref_if"><function>if</function></link>-statement without <function>endif</function> extends only over a single line.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "A number please: " a
if (a<10) then
  print "Your number is less than 10."
endif


REM  and now without endif


input "A number please: " a
if (a<10) print "Your number is less than 10."
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_if"><function>if</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_end_sub">
<refmeta>
   <refentrytitle>end sub</refentrytitle>
</refmeta>
<refnamediv>
   <refname>end sub</refname>
   <refpurpose>ends a subroutine definition</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
sub foo(…)
  …
end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Marks the end of a subroutine-definition (which starts with the <function>sub</function>-keyword).
   The whole concept of subroutines is explained within the entry for <link linkend="ref_sub"><function>sub</function></link>.
</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print foo(3)


sub foo(a)
  return a*2
end sub
          </programlisting>
     <para>This program prints out <computeroutput>6</computeroutput>. The subroutine <function>foo</function> simply returns twice its argument.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_sub"><function>sub</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_eof">
<refmeta>
   <refentrytitle>eof</refentrytitle>
</refmeta>
<refnamediv>
   <refname>eof</refname>
   <refpurpose>check, if an open file contains data</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open 1,"foo.bar"
if (eof(1)) then
   …
end if
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>eof</function>-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 <function>open</function>-function (or statement).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
a=open("foo.bar")
while(not eof(a))
  input #a,a$
  print a$
end while
          </programlisting>
     <para>This example will print the contents of the file "foo.bar". The <function>eof</function>-function will terminate the loop, if there is no more data left within the file. </para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_open"><function>open</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_eor">
<refmeta>
   <refentrytitle>eor()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>eor()</refname>
   <refpurpose>compute the bitwise <emphasis>exclusive or</emphasis> of its two arguments</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>print eor(a,b)</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>eor</function>-function takes two arguments and computes their bitwise <emphasis>exclusive or</emphasis>. See your favorite introductory text on informatics for an explanation of this function.</para>
   <para>The <function>xor</function>-function is the same as the <function>eor</function> function; both are synonymous; however they have each their own description, so you may check out the entry of <function><link linkend="ref_xor">xor</link></function> for a slightly different view.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=0 to 3
  for b=0 to 3
    print fill$(bin$(a))," eor ",fill$(bin$(b))," = ",fill$(bin$(eor(a,b)))
  next b
next a


sub fill$(a$)
  return right$("0"+a$,2)
end sub
          </programlisting>
     <para>This example prints a table, from which you may figure, how the <function>eor</function>-function is computed.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arithmetic_and"><function>and</function></link>, <link linkend="ref_arithmetic_or"><function>or</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_error">
<refmeta>
   <refentrytitle>error</refentrytitle>
</refmeta>
<refnamediv>
   <refname>error</refname>
   <refpurpose>raise an error and terminate your program</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>error "Wrong, wrong, wrong !!"</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number between 1 and 10: " a
if (a<1 or a>10) error "Oh no ..."
          </programlisting>
     <para>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.</para>
     <para>The error message would look like this:</para>
     <programlisting>
---Error in t.yab, line 2: Oh no ...
---Error: Program stopped due to an error
</programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para>Well, there <emphasis>should</emphasis> be a corresponding called <function>warning</function>; unfortunately ther is none yet.</para>
</refsect1>
      </refentry>


      <refentry id="ref_euler">
<refmeta>
   <refentrytitle>euler</refentrytitle>
</refmeta>
<refnamediv>
   <refname>euler</refname>
   <refpurpose>another name for the constant <function>2.71828182864</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>foo=euler</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>euler</function> is the well known constant named after <emphasis>Leonard Euler</emphasis>; its value is <function>2.71828182864</function>. <function>euler</function> is <emphasis>not</emphasis> a function, so parens are not allowed (i.e. <function>euler()</function> will produce an error). Finally, you may not assign to <function>euler</function>; it wouldn't sense anyway, because it is a constant.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print euler
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_pi">pi</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_execute2">
<refmeta>
   <refentrytitle>execute$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>execute$()</refname>
   <refpurpose>execute a user defined subroutine, which must return a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>print execute$("foo$","arg1","arg2")</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>execute$</function> can be used to execute a user defined subroutine, whose name may be specified as a string expression.</para>
   <para>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 <function><link linkend="ref_compile">compile</link></function> command) during the course of execution of your program.</para>
   <para>Note however, that the <function>execute$</function>-function is <emphasis>not</emphasis> 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).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print execute$("foo$","Hello","world !")
sub foo$(a$,b$)
  return a$+" "+b$
end sub
          </programlisting>
     <para>The example simply prints <computeroutput>Hello world !</computeroutput>, which is the return value of the user defined subroutine <function>foo$</function>. The same could be achieved by executing:</para>
     <programlisting>
print foo$(a$,b$)
</programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_compile">compile</link></function>, <function><link linkend="ref_execute">execute</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_execute">
<refmeta>
   <refentrytitle>execute()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>execute()</refname>
   <refpurpose>execute a user defined subroutine, which must return a number</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>print execute("bar","arg1","arg2")</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>execute</function>-function is the counterpart of the <function><link linkend="ref_execute2">execute$</link></function>-function (please see there for some caveats). <function>execute</function> executes subroutines, which returns a number.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print execute("bar",2,3)
sub bar(a,b)
  return a+b
end sub
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_compile">compile</link></function>, <function><link linkend="ref_execute2">execute$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_exit">
<refmeta>
   <refentrytitle>exit</refentrytitle>
</refmeta>
<refnamediv>
   <refname>exit</refname>
   <refpurpose>terminate your program</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
exit
exit 1
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Terminate your program and return any given value to the operating system. <function>exit</function> is similar to <function><link linkend="ref_end">end</link></function>, but it will terminate your program immediately, no matter what.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Do you want to continue ?"
input "Please answer y(es) or n(o): " a$
if (lower$(left$(a$,1))="n") exit 1
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_end">end</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_exp">
<refmeta>
   <refentrytitle>exp()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>exp()</refname>
   <refpurpose>compute the exponential function of its single argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
foo=exp(bar)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>This function computes <emphasis>e</emphasis> to the power of its argument, where <emphasis>e</emphasis> is the well known euler constant <function>2.71828182864</function>.</para>
   <para>The <function>exp</function>-function is the inverse of the <function>log</function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 100,100
for x=0 to 100
   dot x,100-100*exp(x/100)/euler
next x
          </programlisting>
     <para>This program plots part of the <function>exp</function>-function, however the range is rather small, so that you may not recognize the function from this plot.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_log">log</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_export">
<refmeta>
   <refentrytitle>export</refentrytitle>
</refmeta>
<refnamediv>
   <refname>export</refname>
   <refpurpose>mark a function as globally visible</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
export sub foo(bar)

end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>export</function>-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. <function>foo.baz</function> (where <function>foo</function> is the name of the library and <function>baz</function> the name of the subroutine); <emphasis>exported</emphasis> subroutines may be used without specifying the name of the library, e.g. <function>bar</function>.</para>
<para>Therefore <function>export</function> may only be useful within libraries.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <para>The library <filename>foo.bar</filename> (which is listed below) defines two functions <function>bar</function> and <function>baz</function>, however only the function <function>bar</function> is <emphasis>exported</emphasis> and therefore visible even outside the library; <function>baz</function> is <emphasis>not</emphasis> exported and may only be used within the library <computeroutput>foo.yab</computeroutput>:</para>
     <programlisting>
export sub bar()
  print "Hello"
end sub


sub baz()
  print "World"
end sub
          </programlisting>
     <para>Now within your main program <filename>cux.yab</filename> (which <function><link linkend="ref_import">import</link></function>s the library foo.yab); note that this program produces an error:</para>
     <programlisting>
import foo


print "Calling subroutine foo.bar (okay) ..."
foo.bar()
print "done."


print "Calling subroutine bar (okay) ..."
bar()
print "done."


print "Calling subroutine foo.baz (okay) ..."
foo.baz()
print "done."


print "Calling subroutine baz (NOT okay) ..."
baz()
print "done."


</programlisting>
     <para>The output when executing <command>yabasic foo.yab</command> is this:</para>
<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
</programlisting>
     <para>As the error message above shows, the subroutine <function>baz</function> must be qualified with the name of the library, if used outside the library, wherein it is defined (e.g. <function>foo.baz</function>. I.e. outside the library <filename>foo.yab</filename> you need to write <filename>foo.baz</filename>. <function>baz</function> alone would be an error.</para>
     
     <para>The subroutine <function>bar</function> (without adding the name of the library) however may (and probably should) be used in any program, which imports the library <filename>foo.yab</filename>.</para>
   <note>
     <para>In some sense the set of exported subroutines constitutes the <emphasis>interface</emphasis> of a library.</para>
   </note>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sub">sub</link></function>, <function><link linkend="ref_import">import</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_f">
      <title>F</title>


      <refentry id="ref_false">
<refmeta>
   <refentrytitle>false</refentrytitle>
</refmeta>
<refnamediv>
   <refname>false</refname>
   <refpurpose>a constant with the value of 0</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
okay=false
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The constant <function>false</function> can be assigned to variables which later appear in conditions (e.g. within an <function>if</function>-statement.</para>
   <para><function>false</function> may also be written as <function>FALSE</function> or even <function>FaLsE</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number between 1 and 10: " a
if (check_input(a)) print "Okay"


sub check_input(x)
  if (x>10 or x<1) return false
  return true
end sub
          </programlisting>
     <para>The subroutine <function>check_input</function> checks its argument and returns <function>true</function> or <function>false</function> according to the outcome of the check..</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_true">true</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_fi">
<refmeta>
   <refentrytitle>fi</refentrytitle>
</refmeta>
<refnamediv>
   <refname>fi</refname>
   <refpurpose>another name for <function><link linkend="ref_endif">endif</link></function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (…)

fi
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>fi</function> marks the end of an <function>if</function>-statement and is exactly equivilent to <function><link linkend="ref_endif">endif</link></function>, please see there for further information.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "A number please: " a
if (a<10) then
  print "Your number is less than 10."
fi
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_endif">endif</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_fill">
<refmeta>
   <refentrytitle>fill</refentrytitle>
</refmeta>
<refnamediv>
   <refname>fill</refname>
   <refpurpose>draw a filled <function>circle</function>s or <function>rectangle</function>s</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
fill rectangle 10,10,90,90
fill circle 50,50,20
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The keyword <function>fill</function> may be used within the <function><link linkend="ref_circle">circle</link></function> or <function><link linkend="ref_rectangle">rectangle</link></function> command and causes these shapes to be filled.</para>
   <para><function>fill</function> can be used in conjunction with and whereever the <function><link linkend="ref_clear">clear</link></function>-clause may appear. Used alone, <function>fill</function> will fill the interior of the shape (circle or rectangle); together with <function>clear</function> the whole shape (including its interior) is erased.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
          </programlisting>
     <para>This opens a window and draws a pacman-like figure.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_clear">clear</link></function>, <function><link linkend="ref_circle">circle</link></function>, <function><link linkend="ref_rectangle">rectangle</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_for">
<refmeta>
   <refentrytitle>for</refentrytitle>
</refmeta>
<refnamediv>
   <refname>for</refname>
   <refpurpose>starts a <function>for</function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
for a=1 to 100 step 2
  …
next a
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>for</function>-loop lets its numerical variable (<function>a</function> in the synopsis) assume all values within the given range. The optional <function>step</function>-clause may specify a value (default: 1) by which the variable will be incremented (or decremented, if <function>step</function> is negative).</para>
   <para>Any <function>for</function>-statement can be replaced by a set of <function>if</function>s and <function>goto</function>s; as you may infer from the example below this is normally not feasable. However if you want to know in detail how the <function>for</function>-statement works, you should study this example, which presents a <function>for</function>-statement and an <emphasis>exactly equivilant</emphasis> series of <function>if</function>s and <function>goto</function>s.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10 step 2:print a:next


a=1
label check
if (a>10) goto done
  print a
  a=a+2
goto check
label done
          </programlisting>
     <para>This example simply prints the numbers 1, 3, 5, 7 and 9. It does this twice: First with a simple <function>for</function>-statment and then with <function>if</function>s and <function>goto</function>s.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_step">step</link></function>, <function><link linkend="ref_next">next</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_frac">
<refmeta>
   <refentrytitle>frac()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>frac()</refname>
   <refpurpose>return the fractional part of its numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=frac(y)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>frac</function>-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.</para>
   <para>Refer to the example to learn how to rewrite <function>frac</function> by employing the <function>int</function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10
  print frac(sqr(a))
  print sqr(a)-int(sqr(a))
next a
          </programlisting>
     <para>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 <function>frac</function>-function and once by employing the <function><link linkend="ref_int">int</link></function>-function.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_int">int</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_g">
      <title>G</title>


      <refentry id="ref_getbit">
<refmeta>
   <refentrytitle>getbit$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>getbit$()</refname>
   <refpurpose>return a string representing the bit pattern of a rectangle within the graphic window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=getbit$(10,10,20,20)
a$=getbit$(10,10 to 20,20)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The function <function>getbit</function> 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 <function><link linkend="ref_putbit">putbit</link></function>-command. </para>
   <para>The <function>getbit$</function>-function might be used for simple animations (as in the example below).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>This example features a circle moving from left to right over the window.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_putbit">putbit</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_getscreen">
<refmeta>
   <refentrytitle>getscreen$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>getscreen$()</refname>
   <refpurpose>returns a string representing a rectangular section of the text terminal</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=getscreen$(2,2,20,20)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>getscreen$</function> 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).</para>   
   <para>Like most other commands dealing with advanced text output, <function>getscreen$</function> requires, that you have called <function>clear screen</function> before.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen


for a=1 to 1000:
print color("red") "1";
print color("green") "2";
print color("blue") "3";
next a  
screen$=getscreen$(10,10,40,10)
print at(10,10) " Please Press 'y' or 'n' ! "
a$=inkey$
putscreen screen$,10,10
          </programlisting>
     <para>This program fills the screen with coloured digits and afterwards asks the user for a choice (<computeroutput> Please press 'y' or 'n' ! </computeroutput>). 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 <function>getscreen$</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function>putscreen$</function></para>
</refsect1>
      </refentry>


      <refentry id="ref_glob">
<refmeta>
   <refentrytitle>glob()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>glob()</refname>
   <refpurpose>check if a string matches a simple pattern</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (glob(string$,pattern$)) …
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>glob</function>-function takes two arguments, a string and a (glob-) pattern, and checks if the string matches the pattern. However <function>glob</function> does <emphasis>not</emphasis> employ the powerful rules of regular expressions; rather it has only two <emphasis>special</emphasis> characters: <computeroutput>*</computeroutput> (which matches any number (even zero) of characters) and <computeroutput>?</computeroutput> (which matches exactly a single character).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10
  read string$,pattern$
  if (glob(string$,pattern$)) then
    print string$," matches ",pattern$
  else
    print string$," does not match ",pattern$
  endif
next a


data "abc","a*"
data "abc","a?"
data "abc","a??"
data "abc","*b*"
data "abc","*"
data "abc","???"
data "abc","?"
data "abc","*c"
data "abc","A*"
data "abc","????"
          </programlisting>
     <para>This program checks the string <computeroutput>abc</computeroutput> against various patterns and prints the result. The output is:</para>
     <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 ????
</screen>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para>There are no related commands.</para>
</refsect1>
      </refentry>


      <refentry id="ref_gosub">
<refmeta>
   <refentrytitle>gosub</refentrytitle>
</refmeta>
<refnamediv>
   <refname>gosub</refname>
   <refpurpose>continue execution at another point within your program (and return later)</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
gosub foo




label foo

return
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>gosub</function> remembers the current position within your program and then passes the flow of execution to another point (which is normally marked with a <function><link linkend="ref_label">label</link></function>). Later, when a <function>return</function>-statement is encountered, the execution is resumed at the previous location.</para>
   <para><function>gosub</function> is the traditional command for calling code, which needs to be executed from various places within your program. However, with <emphasis>subroutines</emphasis> yabasic offers a much more flexible way to achieve this (and more). Therefore <function>gosub</function> must to be considered obsolete.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Do you want to exit ? "
gosub ask
if (r$="y") exit


label ask
input "Please answer yes or no, by typing 'y' or 'n': ",r$
return
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_return">return</link></function>, <function><link linkend="ref_goto">goto</link></function>, <function><link linkend="ref_sub">sub</link></function>, <function><link linkend="ref_label">label</link></function>, <function><link linkend="ref_on_gosub">on gosub</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_goto">
<refmeta>
   <refentrytitle>goto</refentrytitle>
</refmeta>
<refnamediv>
   <refname>goto</refname>
   <refpurpose>continue execution at another point within your program (and never come back)</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
goto foo




label foo
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>goto</function>-statement passes the flow of execution to another point within your program (which is normally marked with a <function><link linkend="ref_label">label</link></function>).</para>
   <para><function>goto</function> is normally considered obsolete and harmful, however in yabasic it may be put to the good use of leaving loops (e.g. <function>while</function> or <function>for</function>) prematurely. Note however, that subroutines may <emphasis>not</emphasis> be left with the <function>goto</function>-statement.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Please press any key to continue."
print "(program will continue by itself within 10 seconds)"
for a=1 to 10
  if (inkey$(1)<>"") then goto done
next a
label done
print "Hello World !"
          </programlisting>
     <para>Here the <function>goto</function>-statment is used to leave the <function>for</function>-loop prematurely.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_gosub">gosub</link></function>, <function><link linkend="ref_on_goto">on goto</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_h">
      <title>H</title>


      <refentry id="ref_hex">
<refmeta>
   <refentrytitle>hex$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>hex$()</refname>
   <refpurpose>convert a number into hexadecimal</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print hex$(foo)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>hex$</function>-function converts a number into a string with its hexadecimal representation. <function>hex$</function> is the inverse of the <function>dec</function>-function.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open 1,"foo"
while(!eof(1))
  print right$("0"+hex$(peek(1)),2)," ";
  i=i+1
  if (mod(i,10)=0) print
end while
print
          </programlisting>
     <para>This program reads the file <computeroutput>foo</computeroutput> and prints its output as a <emphasis>hex</emphasis>-dump using the <function>hex</function>-function.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_dec">dec</link></function><function><link linkend="ref_bin">bin</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_i">
      <title>I</title>


      <refentry id="ref_if">
<refmeta>
   <refentrytitle>if</refentrytitle>
</refmeta>
<refnamediv>
   <refname>if</refname>
   <refpurpose>evaluate a condition and execute statements or not, depending on the result</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (…) then
  …
endif


if (…) …


if (…) then
  …
else
  …
endif


if (…) then
  …
elsif (…)
  …
elsif (…) then
  …
else
  …
endif
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>if</function>-statement is used to evaluate a conditions and take actions accordingly. (As an aside, please note that there is no real difference between <link linkend="ref_conditions_and_expressions">conditions and expressions</link>.)</para>
   <para>There are two major forms of the <function>if</function>-statement:</para>
   <itemizedlist>
     <listitem>
       <para>The <emphasis>one-line</emphasis>-form <emphasis>without</emphasis> the keyword <function>then</function>: <programlisting>if (…) …</programlisting> This form evaluates the condition and if the result is <constant>true</constant> executes all commands (seperated by colons) upt to the end of the line. There is neither an <function>endif</function> keyword nor an <function>else</function>-branch.</para>
     </listitem>
     <listitem>
       <para>The <emphasis>multi-line</emphasis>-form <emphasis>with</emphasis> the keyword <function>then</function>: <programlisting>if (…) then … elsif (…) … else … endif</programlisting> (where <function>elsif</function> and <function>else</function> are optional, whereas <function>endif</function> is not.</para>
       <para>According to the requirements of your program, you may specify:</para>
       <itemizedlist>
  <listitem>
    <para><function>elsif(…)</function>, which specifies a condition, that will be evaluated only if the condition(s) whithin <function>if</function> or any preceeding <function>elsif</function> did not match.</para>
  </listitem>
  <listitem>
    <para><function>else</function>, which introduces a sequence of commands, that will be executed, if none of the conditions above did match. </para>
  </listitem>
  <listitem>
    <para><function>endif</function> is required and ends the <function>if</function>-statement.</para>
  </listitem>
       </itemizedlist>
     </listitem>
   </itemizedlist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number between 1 and 4: " a
if (a<=1 or a>=4) error "Wrong, wrong !"
if (a=1) then
  print "one"
elsif (a=2)
  print "two"
elsif (a=3)
  print "three"
else
  print "four"
endif
          </programlisting>
     <para>The input-number between 1 and 4 is simply echoed as text (<computeroutput>one</computeroutput>, <computeroutput>two</computeroutput>, …). The example demonstrates both forms (<emphasis>short</emphasis> and <emphasis>long</emphasis>) of the <function>if</function>-statement (Note however, that the same thing can be done, probably somewhat more elegant, with the <function>switch</function>-statement).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_else">else</link></function>, <function><link linkend="ref_elsif">elsif</link></function>, <function><link linkend="ref_endif">endif</link></function>, <function><link linkend="ref_conditions_and_expressions">conditions and expressions</link></function>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_import">
<refmeta>
   <refentrytitle>import</refentrytitle>
</refmeta>
<refnamediv>
   <refname>import</refname>
   <refpurpose>import a library</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
import foo
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>import</function>-statment imports a library. It expects a single argument, which must be the name of a library (without the trailing <computeroutput>.yab</computeroutput>). This library will then be read and parsed and its subroutines (and variables) will be made available within the main program.</para>
   <para>Libraries will first be searched within the current directory (i.e. the directory within which you have invoked <application>yabasic</application>), then within a special directory, whose exact location depends on your system. Typical values would be <filename>/usr/lib</filename> under Unix or <filename>C:\yabasic\lib</filename> under Windows. However only <userinput>yabasic -help-usage</userinput> may tell the truth. The location of this second directory may be changed with the option <literal>-library</literal> (either under <link linkend="windows_options">Windows</link> or <link linkend="unix_options">Unix</link>).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <para>Lets say you have a <application>yabasic</application>-program <computeroutput>foo.yab</computeroutput>, which imports a library <computeroutput>lib.yab</computeroutput>. <computeroutput>foo.yab</computeroutput> reads:</para>
     <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)
          </programlisting>
     <para>Now the library <computeroutput>lib.yab</computeroutput> reads:</para>
     <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
</programlisting>
     <para>This program produces an error:</para>
     <para>
<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
</programlisting>
As you may see from the error message, <application>yabasic</application> is unable to find the subroutine <function>y</function> without specifying the name of the library (i.e. <function>lib.y</function>). The reason for this is, that <function>y</function>, other than <function>x</function>, is <emphasis>not</emphasis> exported from the library <filename>lib.yab</filename> (using the <function>export</function>-statement).
</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_export">export</link></function>, <function><link linkend="ref_sub">sub</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_inkey">
<refmeta>
   <refentrytitle>inkey$</refentrytitle>
</refmeta>
<refnamediv>
   <refname>inkey$</refname>
   <refpurpose>wait, until a key is pressed</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen
foo$=inkey$
inkey$
foo$=inkey$(bar)
inkey$(bar)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>inkeys$</function>-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, <function>inkey$</function> will wait indefinitely.</para>
   <para><function>inkey$</function> may only be used, if <function><link linkend="ref_clear_screen">clear screen</link></function> has been called at least once.</para>
   <para>For normal keys, <application>yabasic</application> simply returns the key, e.g. <computeroutput>a</computeroutput>, <computeroutput>1</computeroutput> or <computeroutput>!</computeroutput>. For function keys you will get <computeroutput>f1</computeroutput>, <computeroutput>f2</computeroutput> and so on. Other special keys will return these strings respectively: <computeroutput>enter</computeroutput>, <computeroutput>backspace</computeroutput>, <computeroutput>del</computeroutput>, <computeroutput>esc</computeroutput>, <computeroutput>scrnup</computeroutput> (for <emphasis>screen up</emphasis>), <computeroutput>scrndown</computeroutput> and <computeroutput>tab</computeroutput>. Modifier keys (e.g. <computeroutput>ctrl</computeroutput>, <computeroutput>alt</computeroutput> or <computeroutput>shift</computeroutput>) by themself can <emphasis>not</emphasis> be detected (however, if you press <computeroutput>shift</computeroutput> and e.g. <computeroutput>a</computeroutput> simultaniously, <function>inkey$</function> will return the letter <computeroutput>A</computeroutput> instead of <computeroutput>a</computeroutput> of course).</para>
   <para>If a graphical window has been opened (via <function>open window</function>) any mouseclick within this window will be returned by <function>inkey$</function> too. The string returned (e.g. <computeroutput>MB1d+0:0028,0061</computeroutput>, <computeroutput>MB2u+0:0028,0061</computeroutput> or <computeroutput>MB1d+1:0028,0061</computeroutput>) is constructed as follows: </para>
   <itemizedlist>
     <listitem>
       <para>Every string associated with a mouseclick will start with the fixed string <computeroutput>MB</computeroutput></para>
     </listitem>
     <listitem>
       <para>The next digit (<computeroutput>1</computeroutput>, <computeroutput>2</computeroutput> or <computeroutput>3</computeroutput>) specifies the mousebutton pressed.</para>
     </listitem>
     <listitem>
       <para>A single letter, <computeroutput>d</computeroutput> or <computeroutput>u</computeroutput>, specifies, if the mousebutton has been pressed or released: <computeroutput>d</computeroutput> stands for <emphasis>down</emphasis>, i.e. the mousebutton has been pressed; <computeroutput>u</computeroutput> means <emphasis>up</emphasis>, i.e. the mousebutton has been released.</para>
     </listitem>
     <listitem>
       <para>The plus-sign ('<computeroutput>+</computeroutput>'), which follows is always fixed.</para>
     </listitem>
     <listitem>
       <para>The next digit (in the range 0 to 7) encodes the modifier keys pressed, where <computeroutput>1</computeroutput> stands for <computeroutput>shift</computeroutput>, <computeroutput>2</computeroutput> stands for <computeroutput>alt</computeroutput> and <computeroutput>4</computeroutput> stands for <computeroutput>ctrl</computeroutput>.</para>
     </listitem>
     <listitem>
       <para>The next four digits (e.g. <computeroutput>0028</computeroutput>) contain the x-position, where the mousebutton has been pressed.</para>
     </listitem>
     <listitem>
       <para>The comma to follow is always fixed.</para>
     </listitem>
     <listitem>
       <para>The last four digits (e.g. <computeroutput>0061</computeroutput>) contain the y-position, where the mousebutton has been pressed.</para>
     </listitem>
   </itemizedlist>


   <para>All those fields are of fixed length, so you may use functions like <function>mid$</function> to extract certain fields. However, note that with <function>mousex</function>, <function>mousey</function>, <function>mouseb</function> and <function>mousemod</function> there are specialized functions to return detailed information about the mouseclick. Finally it should be noted, that <function>inkey$</function> will only register mouseclicks within the graphic-window; mouseclicks in the text-window cannot be detected.</para>
   <para><function>inkey$</function> 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, <function>inkey$</function> will wait for ever.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
open window 100,100
print "Press any key or press 'q' to stop."
repeat
  a$=inkey$
  print a$
until(a$="q")
          </programlisting>
     <para>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).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_clear_screen">clear screen</link></function>,<function><link linkend="ref_mousex">mousex</link></function>, <function><link linkend="ref_mousey">mousey</link></function>, <function><link linkend="ref_mouseb">mouseb</link></function>, <function><link linkend="ref_mousemod">mousemod</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_input">
<refmeta>
   <refentrytitle>input</refentrytitle>
</refmeta>
<refnamediv>
   <refname>input</refname>
   <refpurpose>read input from the user (or from a file) and assign it to a variable</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
input a
input a,b,c
input a$
input "Hello" a
input #1 a$
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>input</function> reads the new contents of one or many (numeric- or string-) variables, either from the keyboard (i.e. from <emphasis>you</emphasis>) or from a file. An optional first string-argument specifies a prompt, which will be issued before reading any contents.</para>
   <para>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.</para>
   <para>Note, that the input is split at spaces, i.e. if you enter a whole line consisting of many space-seperated word, the first <function>input</function>-statement will only return the first word; the other words will only be returned on subsequent calls to <function>input</function>; the same applies, if a single <function>input</function> 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 <function>line input</function>, which returns a whole line (including embedded spaces) at once.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter the name of a file to read: " a$
open 1,a$
while(!eof(1))
  input #1 b$
  print b$
wend
          </programlisting>
     <para>If this program is stored within a file <filename>test.yab</filename> and you enter this name when prompted for a file to read, you will see this output:</para>
     <para><screen>Please enter the name of a file to read: t.yab
input
"Please
enter
the
name
of
a
file
to
read:
"
a$
open
1,a$
while(!eof(1))
input
#1
b$
print
b$
wend
</screen>
</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_line_input">line input</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_instr">
<refmeta>
   <refentrytitle>instr()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>instr()</refname>
   <refpurpose>searches its second argument within the first; returns its position if found</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print instr(a$,b$)
if (instr(a$,b$)) …
pos=instr(a$,b$,x)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>instr</function>-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 <function>instr</function>-function returns 0; this makes this function usable within the condition of an <function>if</function>-statement (see the example below).</para>
   <para>If you supply a third, numeric argument to the <function>instr</function>-function, it will be used as a starting point for the search. Therefore <function>instr("abcdeabcdeabcde","e",8)</function> will return 10, because the search for an "<literal>e</literal>" starts at position 8 and finds the "<literal>e</literal>" at position 10 (and not the one at position 5).</para>


</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a text containing the string 'bumf': " a$
if (instr(a$,"bumf")) then
  print "Well done !"
else
  print "not so well ..."
endif
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_rinstr">rinstr</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_int">
<refmeta>
   <refentrytitle>int()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>int()</refname>
   <refpurpose>return the integer part of its single numeric argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print int(a)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>int</function>-function returns only the digits before the comma; <function>int(2.5)</function> returns <computeroutput>2</computeroutput> and <function>int(-2.3)</function> returns <computeroutput>-2</computeroutput>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a whole number between 1 and 10: " a
if (a=int(a) and a>=1 and a<=10) then
  print "Thanx !"
else
  print "Never mind ..."
endif
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_frac">frac</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_l">
      <title>L</title>


      <refentry id="ref_label">
<refmeta>
   <refentrytitle>label</refentrytitle>
</refmeta>
<refnamediv>
   <refname>label</refname>
   <refpurpose>mark a specific location within your program for <function>goto</function>, <function>gosub</function> or <function>restore</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
label foo




goto foo
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>label</function>-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: <function>goto</function>, <function>gosub</function> and <function>restore</function>.</para>
   <para>You may use labels safely within libraries, because a label (e.g. <computeroutput>foo</computeroutput>) does not collide with a label with the same name within the main program or within another library; <application>yabasic</application> will not mix them up.</para>
   <para>As an aside, please note, that line numbers are a special (however deprecated) case of labels; see the second example below.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 100
  if (rand(10)>5) goto done
next a
label done


10 for a=1 to 100
20   if (rand(10)>5) goto 40
30 next a
40
          </programlisting>
     <para>Within this example, the <function>for</function>-loop will probably be left prematurely with a <function>goto</function>-statement. This task is done <emphasis>twice</emphasis>: First with labels and then again with line numbers.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_gosub">gosub</link></function>, <function><link linkend="ref_goto">goto</link></function>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_left">
<refmeta>
   <refentrytitle>left$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>left$()</refname>
   <refpurpose>return (<emphasis>or change</emphasis>) left end of a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print left$(a$,2)
left$(b$,3)="foobar"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>left$</function>-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.</para>
   <para>Note, that the <function>left$</function>-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 <function>left$</function>-function. Note, that that way the <emphasis>length</emphasis> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please answer yes or no: " a$
l=len(a$):a$=lower$(a$):print "Your answer is ";
if (left$("yes",l)=a$ and l>=1) then
  print "yes"
elsif (left$("no",l)=a$ and l>=1) then
  print "no"
else
  print "?"
endif
          </programlisting>
     <para>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.</para>
     <para>This second example demonstrates the capability to <emphasis>assign</emphasis> to the <function>left$</function>-function.</para>
     <programlisting>
a$="Heiho World !"
print a$
left$(a$,5)="Hello"
print a$
</programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_right">right$</link></function>, <function><link linkend="ref_mid">mid$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_len()">
<refmeta>
   <refentrytitle>len()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>len()</refname>
   <refpurpose>return the length of a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=len(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>len</function>-function returns the length of its single string argument.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a password: " a$
if (len(a$)<6) error "Password too short !"
          </programlisting>
     <para>This example checks the length of the password, that the user has entered.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_left">left$</link></function>, <function><link linkend="ref_right">right$</link></function> and <function><link linkend="ref_mid">mid$</link></function>, </para>
</refsect1>
      </refentry>


      <refentry id="ref_line">
<refmeta>
   <refentrytitle>line</refentrytitle>
</refmeta>
<refnamediv>
   <refname>line</refname>
   <refpurpose>draw a line</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <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
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>line</function>-command draws a line. Simple as this is, the <function>line</function>-command has a large variety of forms as they are listed in the synopsis above. Lets look at them a little closer:</para>
   <itemizedlist>
     <listitem>
<para>A line has a starting and an end point; therefore the <function>line</function>-command (normally) needs four numbers as arguments, representing these two points. This is the first form appearing within the synopsis. </para>
     </listitem>
     <listitem>
       <para>You may seperate the two points with either '<computeroutput>,</computeroutput>' or <function>to</function>, which accounts for the second form of the <function>line</function>-command.</para>
     </listitem>
     <listitem>
       <para>The <function>line</function>-command may be used to draw a connected sequence of lines with a sequence of commands like <function>line x,y</function>; Each command will draw a line from the point where the last <function>line</function>-command left off, to the point specified in the arguments. Note, that you need to use the command <function>new curve</function> before you may issue such a <function>line</function>-command. See the example below.</para>
     </listitem>
     <listitem>
       <para>You may insert the word <function>to</function> for beauty: <function>line to x,y</function>, which does exactly the same as <function>line x,y</function></para>
     </listitem>
     <listitem>
       <para>Finally, you may choose not to draw, but to erase the lines; this can be done by prepending the phrase <function>clear</function>. This account for all the other forms of the <function>line</function>-command.</para>
     </listitem>
   </itemizedlist>


</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>This example draws a sine-curve (with an offset in x- and y-direction). Note, that the first <function>line</function>-command after <function>new curve</function> 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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_new_curve">new curve</link></function>, <function><link linkend="ref_close_curve">close curve</link></function>, <function><link linkend="ref_open_window">open window</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_line_input">
<refmeta>
   <refentrytitle>line input</refentrytitle>
</refmeta>
<refnamediv>
   <refname>line input</refname>
   <refpurpose>read in a whole line of text and assign it to a variable</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
line input a
line input a$
line input "Hello" a
line input #1 a$
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>In most respects <function>line input</function> is like the <function><link linkend="ref_input">input</link></function>-command: It reads the new contents of a variable, either from keyboard or from a file. However, <function>line input</function> always reads a complete line and assigns it to its variable. <function>line input</function> 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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
line input "Please enter your name (e.g. Frodo Beutelin): " a$
print "Hello ",a$
          </programlisting>
     <para>Note that the usage of <function>line input</function> is essential in this example; a simple <function>input</function>-statement would only return the string up to the first space, e.g. <computeroutput>Frodo</computeroutput>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_input">input</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_local">
<refmeta>
   <refentrytitle>local</refentrytitle>
</refmeta>
<refnamediv>
   <refname>local</refname>
   <refpurpose>mark a variable as local to a subroutine</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
sub foo()


  local a,b,c$,d(10),e$(5,5)


  …


end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>local</function>-command can (and should be) used to mark a variable (or array) as <emphasis>local</emphasis> 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 <emphasis>global</emphasis> in contrast.</para>
<para>Declaring variables within the subroutine as <emphasis>local</emphasis> helps to avoid hard to find bugs; therefore local variables should be used whenever possible.</para>
   <para>Note, that the parameters of your subroutines are always local.</para>
   <para>As you may see from the example, local arrays may be created without using the keyword <function>dim</function> (which is required only for global arrays).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
a=1
b=1
print a,b
foo()
print a,b


sub foo()
  local a
  a=2
  b=2
end sub
          </programlisting>
     <para>This example demonstrates the difference between <function>local</function> and global variables; it produces this output:</para>
     <para>
<screen>1 1
1 2
</screen>
</para>
     <para>As you may see, the content of the global variable <function>a</function> is unchanged after the subroutine <function>foo</function>; this is because the assignment <computeroutput>a=2</computeroutput> within the subroutine affects the <emphasis>local</emphasis> variable <computeroutput>a</computeroutput> only and not the global one. However, the variable <computeroutput>b</computeroutput> is never declared local and therefore the subroutine changes the global variable, which is reflected in the output of the second print-statement.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sub">sub</link></function>, <function><link linkend="ref_static">static</link></function>, <function><link linkend="ref_dim">dim</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_log">
<refmeta>
   <refentrytitle>log()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>log()</refname>
   <refpurpose>compute the natural logarithm</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a=log(x)
a=log(x,base)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>log</function>-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 <emphasis>euler</emphasis>-constant 2.71828… will be taken as the base.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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>10) r=10
  if (r<1) r=1
  fill circle x,y,r
next y:next x
          </programlisting>
     <para>This draws another nice plot.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_exp">exp</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_loop">
<refmeta>
   <refentrytitle>loop</refentrytitle>
</refmeta>
<refnamediv>
   <refname>loop</refname>
   <refpurpose>marks the end of an infinite loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
do
  …
loop
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>loop</function>-command marks the ends of a loop (which is started by <function>do</function>), wherein all statements within the loop are repeated forever. In this respect the <function>do loop</function>-loop is infinite, however, you may leave it anytime via <function>break</function> or <function>goto</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Hello, I will throw dice, until I get a 2 ..."
do
  r=int(rand(6))+1
  print r
  if (r=2) break
loop
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_do">do</link></function>, <function><link linkend="ref_for">for</link></function>, <function><link linkend="ref_repeat">repeat</link></function>, <function><link linkend="ref_while">while</link></function>, <function><link linkend="ref_break">break</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_lower">
<refmeta>
   <refentrytitle>lower$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>lower$()</refname>
   <refpurpose>convert a string to lower case</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
l$=lower$(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>lower$</function>-function accepts a single string-argument and converts it to all lower case.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a password: " a$
if (a$=lower$(a$)) error "Your password is NOT mixed case !"
          </programlisting>
     <para>This example prompts for a password and checks, if it is really lower case.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_upper">upper$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_ltrim">
<refmeta>
   <refentrytitle>ltrim$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>ltrim$()</refname>
   <refpurpose>trim spaces at the left end of a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=ltrim$(b$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>ltrim$</function>-function removes all whitespace from the left end of a string and returns the result.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please answer 'yes' or 'no' : " a$
a$=lower$(ltrim$(rtrim$(a$)))
if (len(a$)>0 and a$=left$("yes",len(a$))) then
  print "Yes ..."
else
  print "No ..."
endif
          </programlisting>
     <para>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 <emphasis>space</emphasis> before entering his answer.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_rtrim">rtrim$</link></function>, <function><link linkend="ref_trim">trim$</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_m">
      <title>M</title>


      <refentry id="ref_max">
<refmeta>
   <refentrytitle>max()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>max()</refname>
   <refpurpose>return the larger of its two arguments</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print max(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Return the <emphasis>maximum</emphasis> of its two arguments.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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,": ",m(a)
next a
          </programlisting>
     <para>Within the inner <function>for</function>-loop (the one with the loop-variable <function>b</function>), the example computes the maximum of 10 random numbers. The outer loop (with the loop variable <function>a</function>) now repeats this process 1000 times and counts, how often each maximum appears. The last loop finally reports the result.</para>
     <para>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 <computeroutput>:-)</computeroutput></para>


   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_min">min</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mid">
<refmeta>
   <refentrytitle>mid$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mid$()</refname>
   <refpurpose>return (<emphasis>or change</emphasis>) characters from within a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print mid$(a$,2,1)
print mid$(a$,2)
mid$(a$,5,3)="foo"
mid$(a$,5)="foo"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mid$</function>-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 <function>mid$</function>-function returns all characters up to the end of the string.</para>
   <para>Note, that you may assign to the <function>mid$</function>-function, i.e. <function>mid$</function> 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 <function>mid$</function>-function. Note, that that way the <emphasis>length</emphasis> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a string: " a$
for a=1 to len(a$)
  if (instr("aeiou",lower$(mid$(a$,a,1)))) mid$(a$,a,1)="e"
next a
print "When you turn everything to lower case and"
print "replace every vowel with 'e', your input reads:"
print
print a$
          </programlisting>
     <para>This example transforms the input string a bit, using the <function>mid$</function>-function to retrieve a character from within the string as well as to change it.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_left">left$</link></function> and <function><link linkend="ref_right">right$</link></function>.</para>
</refsect1>
      </refentry>


      <refentry id="ref_min">
<refmeta>
   <refentrytitle>min()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>min()</refname>
   <refpurpose>return the smaller of its two arguments</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print min(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Return the <emphasis>minimum</emphasis> of its two argument.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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,": ",m(a)
next a
          </programlisting>
     <para>For each iteration of the loop, the lower of two random number is recorded. The result is printed at the end.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_max">max</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mod">
<refmeta>
   <refentrytitle>mod()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mod()</refname>
   <refpurpose>compute the remainder of a division</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print mod(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mod</function>-function divides its two arguments and computes the remainder. Note, that <literal>a/b-int(a/b)</literal> and <literal>mod(a,b)</literal> are always equal.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
print at(10,10) "Please wait ";
p$="-\|/"
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
          </programlisting>
     <para>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 <function>mod()</function>-function comes into play).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_int">int</link></function>, <function><link linkend="ref_frac">frac</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mouseb">
<refmeta>
   <refentrytitle>mouseb</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mouseb</refname>
   <refpurpose>extract the state of the mousebuttons from a string returned by <function>inkey$</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
inkey$
print mouseb()
print mouseb
a$=inkey$
print mouseb(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mouseb</function>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <function>inkey$</function>-function. If a mousebutton has been pressed, the <function>mouseb</function>-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.</para>
   <para>The <function>mouseb</function>-function accepts zero or one arguments. A single argument should be a string returned by the <function>inkey$</function>-function; if <function>mouseb</function> is called without any arguments, it returns the values from the last call to <function>inkey$</function>, which are stored implicitly and internally by <application>yabasic</application>.</para>
   <note>
     <para>Note however, that the value returned by the <function>mouseb</function>-function does <emphasis>not</emphasis> reflect the <emphasis>current</emphasis> state of the mousebuttons. It rather extracts the information from the string passed as an argument (or from the last call to the <function>inkey$</function>-function, if no argument is passed). So the value returned by <function>mouseb</function> reflects the state of the mousebuttons at the time the <function>inkey$</function>-function has been called; as opposed to the time the <function>mouseb</function>-function is called.</para>
   </note>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
clear screen
print "Please draw lines; press (and keep it pressed)"
print "the left mousebutton for the starting point,"
print "release it for the end-point."
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
          </programlisting>
     <para>This is a maybe the most simplistic line-drawing program possible, catching presses as well as releases of the first mousebutton.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>   
   <para><function><link linkend="ref_inkey">inkey$</link></function>, <function><link linkend="ref_mousex">mousex</link></function>, <function><link linkend="ref_mousey">mousey</link></function> and <function><link linkend="ref_mousemod">mousemod</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mousemod">
<refmeta>
   <refentrytitle>mousemod</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mousemod</refname>
   <refpurpose>return the state of the modifier keys during a mouseclick</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
inkey$
print mousemod()
print mousemod
a$=inkey$
print mousemod(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mousemod</function>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <function>inkey$</function>-function if a mousebutton has been pressed. It returns the state of the keyboard modifiers (<literal>shift</literal>, <literal>ctrl</literal> or <literal>alt</literal>): If the <literal>shift</literal>-key is pressed, <function>mousemod</function> returns 1, for the <literal>alt</literal>-key 2 and for the <literal>ctrl</literal>-key 4. If more than one key is pressed, the sum of these values is returned, e.g. <function>mousemod</function> returns 5, if <literal>shift</literal> and <literal>ctrl</literal> are pressed simultanously.</para>
   <para>The <function>mousemod</function>-function accepts zero or one arguments. A single argument should be a string returned by the <function>inkey$</function>-function; if <function>mousemod</function> is called without any arguments, it returns the values from the last call to <function>inkey$</function> (which are stored implicitly and internally by yabasic).</para>
   <note>
     <para>Please see also the Note within the <function><link linkend="ref_mouseb">mouseb</link></function>-function.</para>
   </note>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") 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
          </programlisting>
     <para>This program draws a circle, whenever a mousebutton is pressed; the circles are filled, when any modifier is pressed, and empty if not.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_inkey">inkey$</link></function>, <function><link linkend="ref_mousex">mousex</link></function>, <function><link linkend="ref_mousey">mousey</link></function> and <function><link linkend="ref_mouseb">mouseb</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mousex">
<refmeta>
   <refentrytitle>mousex</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mousex</refname>
   <refpurpose>return the x-position of a mouseclick</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
inkey$
print mousex()
print mousex
a$=inkey$
print mousex(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mousex</function>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <function>inkey$</function>-function; It returns the x-position of the mouse as encoded within its argument.</para>
   <para>The <function>mousex</function>-function accepts zero or one arguments. A single argument should be a string returned by the <function>inkey$</function>-function; if <function>mousex</function> is called without any arguments, it returns the values from the last call to <function>inkey$</function> (which are stored implicitly and internally by yabasic).</para>
   <note>
     <para>Please see also the Note within the <function><link linkend="ref_mouseb">mouseb</link></function>-function.</para>
   </note>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") then
    line mousex,0 to mousex,200
  endif
loop
          </programlisting>
     <para>This example draws vertical lines at the position, where the mousebutton has been pressed.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_inkey">inkey$</link></function>, <function><link linkend="ref_mousemod">mousemod</link></function>, <function><link linkend="ref_mousey">mousey</link></function> and <function><link linkend="ref_mouseb">mouseb</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_mousey">
<refmeta>
   <refentrytitle>mousey</refentrytitle>
</refmeta>
<refnamediv>
   <refname>mousey</refname>
   <refpurpose>return the y-position of a mouseclick</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
inkey$
print mousey()
print mousey
a$=inkey$
print mousey(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>mousey</function>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <function>inkey$</function>-function. <function>mousey</function> returns the y-position of the mouse as encoded within its argument.</para>
   <para>The <function>mousey</function>-function accepts zero or one arguments. A single argument should be a string returned by the <function>inkey$</function>-function; if <function>mousey</function> is called without any arguments, it returns the values from the last call to <function>inkey$</function> (which are stored implicitly and internally by yabasic).</para>
   <note>
     <para>Please see also the Note within the <function><link linkend="ref_mouseb">mouseb</link></function>-function.</para>
   </note>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") then
    line 0,mousey to 200,mousey
  endif
loop
          </programlisting>
     <para>This example draws horizontal lines at the position, where the mousebutton has been pressed.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_inkey">inkey$</link></function>, <function><link linkend="ref_mousemod">mousemod</link></function>, <function><link linkend="ref_mousey">mousex</link></function> and <function><link linkend="ref_mouseb">mouseb</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_n">
      <title>N</title>


      <refentry id="ref_new_curve">
<refmeta>
   <refentrytitle>new curve</refentrytitle>
</refmeta>
<refnamediv>
   <refname>new curve</refname>
   <refpurpose>start a new curve, that will be drawn with the <function>line</function>-command</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
new curve
line to x,y
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>new curve</function>-function starts a new sequence of lines, that will be drawn by repeated <function>line to</function>-commands.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
  
          </programlisting>
     <para>This example defines a subroutine <function>ellipse</function> that draws an ellipse. Within this subroutine, the ellipse is drawn as a sequence of lines started with the <function>new curve</function> command and closed with <function>close curve</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_close_curve">close curve</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_next">
<refmeta>
   <refentrytitle>next</refentrytitle>
</refmeta>
<refnamediv>
   <refname>next</refname>
   <refpurpose>mark the end of a for loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
for a=1 to 10
next a
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>next</function>-keyword marks the end of a <function>for</function>-loop. All statements up to the <function>next</function>-keyword will be repeated as specified with the <function>for</function>-clause. Note, that the name of the variable is optional; so instead of <literal>next a</literal> you may write <literal>next</literal>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 300000
  for b=1 to 21+20*sin(pi*a/20)
    print "*";
  next b
  print
  sleep 0.1
next a
          </programlisting>
     <para>This example simply plots a sine-curve until you fall asleep.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_for">for</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_not">
<refmeta>
   <refentrytitle>not</refentrytitle>
</refmeta>
<refnamediv>
   <refname>not</refname>
   <refpurpose>negate an expression; can be written as <function>!</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (not a<b) then …
bad=!okay
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The keyword <function>not</function> (or <function>!</function> for short) is mostly used within conditions (e.g. within <function>if</function>- or <function>while</function>-statements). There it is employed to negate the condition or expression (i.e. turn <literal>TRUE</literal> into <literal>FALSE</literal> and vice versa)</para>
   <para>However <function>not</function> can be used within arithmetic calculations too., simply because there is no difference between arithmetic and logical expressions.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter three ascending numbers: " a,b,c
if (not (a<b and b<c)) error " the numbers you have entered are not ascending ..."
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_logical_and"><function>and</function></link>,<link linkend="ref_logical_or"><function>or</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_numparams">
<refmeta>
   <refentrytitle>numparams</refentrytitle>
</refmeta>
<refnamediv>
   <refname>numparams</refname>
   <refpurpose>return the number of parameters, that have been passed to a subroutine</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
sub foo(a,b,c)
  if (numparams=1) …
  …
end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Within a subroutine the local variable <function>numparam</function> or <function>numparams</function> 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 <function>numparams</function>.</para>
   <para>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 <function>numparams</function>) receive a value of <literal>0</literal> or <literal>""</literal> (empty string) respectively.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
a$="123456789"
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
          </programlisting>
     <para>When you run this example, it will print <computeroutput>456789</computeroutput> and <computeroutput>34567</computeroutput>. Take a look at the subroutine <function>part$</function>, 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 <function>numparams</function> variable.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sub">sub</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_o">
      <title>O</title>


      <refentry id="ref_on_gosub">
<refmeta>
   <refentrytitle>on gosub</refentrytitle>
</refmeta>
<refnamediv>
   <refname>on goto</refname>
   <refpurpose>jump to one of multiple <function>gosub</function>-targets</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
on a gosub foo,bar,baz
  …
label foo
  …
return


label bar
  …
return


label baz
  …
return
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>on gosub</function> statement uses its numeric argument (the one between <function>on</function> and <function>gosub</function>) to select an element from the list of labels, which follows after the <function>gosub</function>-keyword: If the number is 1, the program does a <function>gosub</function> 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.</para>
   <para>Note, that the <function>on gosub</function>-command can no longer be considered <emphasis>state of the art</emphasis>; people (not me !) may even start to mock you, if you use it.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  print "Please enter a number between 1 and 3: "
  print
  input "Your choice " a
  on a gosub bad,one,two,three,bad
loop


label bad
  print "No. Please between 1 and 3"
return


label one
  print "one"
return


label two
  print "two"
return


label three
  print "three"
return
          </programlisting>
     <para>Note, how invalid input (a number less than 1, or larger than 3) is automatically detected.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_goto">goto</link></function>, <function><link linkend="ref_on_gosub">on gosub/function></link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_on_goto">
<refmeta>
   <refentrytitle>on goto</refentrytitle>
</refmeta>
<refnamediv>
   <refname>on goto</refname>
   <refpurpose>jump to one of many <function>goto</function>-targets</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
on a goto foo,bar,baz
  …
label foo
  …
label bar
  …
label baz
  …
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>on goto</function> statement uses its numeric argument (the one between <function>on</function> and <function>goto</function> to select an element from the list of labels, which follows after the <function>goto</function>-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.</para>
   <para>Note, that (unlike the <function>goto</function>-command) the <function>on goto</function>-command can no longer be considered <emphasis>state of the art</emphasis>; people may (not me !) even start to mock you, if you use it.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
label over
print "Please Select one of these choices: "
print
print "  1 -- show time"
print "  2 -- show date"
print "  3 -- exit"
print
input "Your choice " 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
          </programlisting>
     <para>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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_goto">goto</link></function>, <function><link linkend="ref_on_gosub">on gosub/function></link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_on_interrupt">
<refmeta>
   <refentrytitle>on interrupt</refentrytitle>
</refmeta>
<refnamediv>
   <refname>on interrupt</refname>
   <refpurpose>change reaction on keyboard interrupts</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
on interrupt break

on interrupt continue
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>With the <function>on interrupt</function>-command you may change the way, how yabasic reacts on a keyboard interrupt; it comes in two variants: <function>on interrupt break</function> and <function>on interrupt continue</function>. A keyboard interrupt is produced, if you press <userinput>ctrl-C</userinput> on your keyboard; normally (and certainly after you have called <function>on interrupt break</function>), <application>yabasic</application> will terminate with an error message. However after the command <function>on interrupt continue</function> 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).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Please stand by while writing a file with random data ..."
on interrupt continue
open "random.data" for writing as #1
for a=1 to 100
  print #1 ran(100)
  print a," percent done."
  sleep 1
next a
close #1
on interrupt continue
          </programlisting>
     <para>This program writes a file with 100 random numbers. The <function>on interrupt continue</function> command insures, that the program will not be terminated on a keyboard interrupt and the file will be written entirely in any case. The <function>sleep</function>-command just stretches the process arificially to give you a chance to try a <userinput>ctrl-C</userinput>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para>There is no related command.</para>
</refsect1>
      </refentry>


      <refentry id="ref_open">
<refmeta>
   <refentrytitle>open</refentrytitle>
</refmeta>
<refnamediv>
   <refname>open</refname>
   <refpurpose>open a file</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open a,"file","r"
open #a,"file","w"
open #a,printer
open "file" for reading as a
open "file" for writing as #a
a=open("file")
a=open("file","r")
if (open(a,"file")) …
if (open(a,"file","w")) …
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>open</function>-command opens a file for reading or writing or a printer for printing text. <function>open</function> comes in a wide variety of ways; it requires these arguments:</para>
   <variablelist>
     <varlistentry>
       <term>filenumber</term>
       <listitem>
<para>In the synopsis this is <literal>a</literal> or <literal>#a</literal>. In <application>yabasic</application> 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 ('<literal>#</literal>'). Note, that specifying a filenumber is optional; if it is omitted, the <function>open</function>-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 <application>yabasic</application> from getting confused.</para>
       </listitem>
     </varlistentry>
     <varlistentry>
       <term>filename</term>
       <listitem>
  <para>In the synopsis above this is <literal>"file"</literal>. This string specifies the name of the file to open (note the important <link linkend="ref_windows_filenames">caveat</link> on specifying these filenames).</para>
       </listitem>
     </varlistentry>
     <varlistentry>
       <term>accessmode</term>
       <listitem>
<para>In the synopsis this is <literal>"r"</literal>, <literal>"w"</literal>, <literal>for reading</literal> or <literal>for writing</literal>. This string or clause specifies the mode in which the file is opened; it may be one of:
  <variablelist>
    <varlistentry>
      <term>"r"</term>
      <listitem>
   <para>Open the file for reading (may also be written as <literal>for reading</literal>). If the file does not exist, the command will fail. This mode is the default, i.e. if no mode is specified with the <function>open</function>-command, the file will be opened with this mode.</para>
      </listitem>
    </varlistentry>
    <varlistentry>
      <term>"w"</term>
      <listitem>
        <para>Open the file for writing (may also be written as <literal>for writing</literal>). If the file does not exist, it will be created.</para>
      </listitem>
    </varlistentry>


    <varlistentry>
      <term>"a"</term>
      <listitem>
        <para>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.</para>
      </listitem>
    </varlistentry>


    <varlistentry>
      <term>"b"</term>
      <listitem>
   <para>This letter may not appear alone, but may be combined with the other letters (e.g. <literal>"rb"</literal>) to open a file in binary mode (as opposed to text mode).</para>
      </listitem>
    </varlistentry>
  </variablelist>


       </para></listitem>
     </varlistentry>
   </variablelist>
   <para>As you may see from the synopsis, the <function>open</function>-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 <function>open</function>-function may be used within the condition of an <function>if</function>-statement.</para>
   <para>If the <function>open</function>-command fails, you may use <function><link linkend="ref_peek">peek("error")</link></function> to retrieve the exact nature of the error.</para>
   <para>Furthermore note, that there is another, somewhat separate usage of the <function>open</function>-command; if you specify the bareword <literal>printer</literal> 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 <function><link linkend="ref_open_printer">open printer</link></function>.</para>
   <para>Finally you may read the description for <function><link linkend="ref_peek">peek("error")</link></function> to learn which errors may have happened during an <function>open</function>-call.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open "foo.bar" for writing as #1
print #1 "Hallo !"
close #1
if (not open(1,"foo.bar")) error "Could not open 'foo.bar' for reading"
while(not eof(1))
  line input #1 a$
  print a$
wend
          </programlisting>
     <para>This example simply opens the file <literal>foo.bar</literal>, writes a single line, reopens it and reads its contents again.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_close">close</link></function>, <function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_peek">peek</link></function>, <function><link linkend="ref_peek">peek("error")</link></function> and <function><link linkend="ref_open_printer">open printer</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_open_printer">
<refmeta>
   <refentrytitle>open printer</refentrytitle>
</refmeta>
<refnamediv>
   <refname>open printer</refname>
   <refpurpose>open printer for printing graphics</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open printer
open printer "file"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>open printer</function>-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.</para>
   <para>A new piece of paper may be started with the <function>clear window</function>-command; the final (or only) page will appear after the <function>close printer</function>-command.</para>
   <para>Note, that you may specify a filename with <function>open printer</function>; 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.</para>
   <para>If you use <application>yabasic</application> under Unix, you will need a postscript printer (because <application>yabasic</application> produces postscript output). Alternatively you may use <emphasis>ghostscript</emphasis> to transfrom the postscript file into a form suitable for your printer; but that is beyond the responsibility of <application>yabasic</application>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 200,200
open printer
line 0,0 to 200,200
text 100,100,"Hallo"
close window
close printer
          </programlisting>
     <para>This example will open a window, draw a line and print some text within; everything will appear on your printer too.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_close_printer">close printer</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_open_window">
<refmeta>
   <refentrytitle>open window</refentrytitle>
</refmeta>
<refnamediv>
   <refname>open window</refname>
   <refpurpose>open a graphic window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open window x,y
open window x,y,"font"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>open window</function>-command opens a window of the specified size. Only one window can be opened at any given moment of time.</para>
   <para>An optional third argument specifies a font to be used for any <link linkend="ref_text">text</link> 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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_close_window">close window</link></function>, <function><link linkend="ref_text">text</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_logical_or">
<refmeta>
   <refentrytitle>logical or</refentrytitle>
</refmeta>
<refnamediv>
   <refname>or</refname>
   <refpurpose>logical or, used in conditions</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (a or b) …
while (a or b) …
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Used in conditions (e.g within <function><link linkend="ref_if">if</link></function> or <function><link linkend="ref_while">while</link></function>) to join two expressions. Returns <constant>true</constant>, if either its left or its right or both arguments are <constant>true</constant>; returns <constant>false</constant> otherwise.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a number"
if (a>9 or a<1) print "a is not between 1 and 9"
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_logical_and"><function>and</function></link>,<link linkend="ref_not"><function>not</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_arithmetic_or">
<refmeta>
   <refentrytitle>or()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>or()</refname>
   <refpurpose>arithmetic or, used for bit-operations</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=or(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Used to compute the bitwise <function>or</function> 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.</para>
   <para>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 <function>or</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print or(14,3)
          </programlisting>
     <para>This will print <computeroutput>15</computeroutput>. 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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_arithmetic_and"><function>oand</function></link>, <link linkend="ref_eor"><function>eor</function></link> and <link linkend="ref_not"><function>not</function></link></para>
</refsect1>
      </refentry>
    </sect1>


    <sect1 renderas="sect2" id="ref_p">
      <title>P</title>


      <refentry id="ref_pause">
<refmeta>
   <refentrytitle>pause</refentrytitle>
</refmeta>
<refnamediv>
   <refname>pause</refname>
   <refpurpose>pause, sleep, wait for the specified number of seconds</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
pause 5
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>pause</function>-command has many different names: You may write <function>pause</function>, <function>sleep</function> or <function>wait</function> interchangable; whatever you write, <application>yabasic</application> will always do exactly the same.</para>
   <para>The <function>pause</function>-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 <application>yabasic</application> will not wait at all. The minimal interval that can be waited depends on the system (Unix, Windows) you are using.</para>
   <para>The <function>pause</function>-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 <function><link linkend="ref_inkey">inkey$</link></function>-function, with a number of seconds as an argument).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
deg=0
do
  maxx=44+40*sin(deg)
  for x=1 to maxx
    print "*";
  next x
  pause 0.1+(maxx*maxx/(4*84*84))
  print
  deg=deg+0.1
loop
          </programlisting>
     <para>This example draws a sine-curve; due to the <function>pause</function>-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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sleep">sleep</link></function>, <function><link linkend="ref_wait">wait</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_peek">
<refmeta>
   <refentrytitle>peek</refentrytitle>
</refmeta>
<refnamediv>
   <refname>peek</refname>
   <refpurpose>retrieve various internal informations</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print peek("foo")
a=peek(#1)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>peek</function>-function has many different and mostly unrelated uses. It is a kind of grabbag for retrieving all kinds of numerical information, internal to <application>yabasic</application>. The meaning of the numbers returned be the <function>peek</function>-function depends on the string or number passed as an argument.</para>
   <para><function>peek</function> always returns a number, however the closely related <function><link linkend="ref_peek2">peek$</link></function>-function exists, which may be used to retrieve string information from among the internals of <application>yabasic</application>. Finally note, that some of the values which are retrieved with <function>peek</function> may even be changed, using the <function><link linkend="ref_poke">poke</link></function>-function.</para>
   <para>There are two variants of the <function>peek</function>-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.</para>


   <variablelist>


     <varlistentry>
       <term><function>peek(a), peek(#a)</function></term>
       <listitem>
  <para>Read a single character from the file <literal>a</literal> (which must be open of course).</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("winheight")</function></term>
       <listitem>
  <para>Return the height of the graphic-window in pixels. If none is open, this <function>peek</function> will return the height of the last window opened or 100, if none has been opened yet.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("winwidth")</function></term>
       <listitem>
  <para>Return the width of the graphic-window in pixels. If none is open, this <function>peek</function> will return the width of the last window opened or 100, if none has been opened yet.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("fontheight")</function></term>
       <listitem>
  <para>Return the height of the font used within the graphic window. If none is open, this <function>peek</function> will return the height of the last font used or 10, if no window has been opened yet.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("screenheight")</function></term>
       <listitem>
  <para>Return the height in characters of the window, wherein yabasic runs. If you have not called <function><link linkend="ref_clear_screen">clear screen</link></function> yet, this <function>peek</function>will return 0, regardless of the size of your terminal.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("screenwidth")</function></term>
       <listitem>
  <para>Return the width in characters of the window, wherein yabasic runs. If you have not called <function><link linkend="ref_clear_screen">clear screen</link></function> yet, this <function>peek</function>will return 0, regardless of the size of your terminal.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("argument")</function></term>
       <listitem>
  <para>Return the number of arguments, that have been passed to <application>yabasic</application> at invocation time. E.g. if <application>yabasic</application> has been called like this: <literal>yabasic foo.yab bar baz</literal>, then <function>peek("argument")</function> will return 2. This is because <literal>foo.yab</literal> is treated as the name of the program to run, whereas <literal>bar</literal> and <literal>baz</literal> are considered arguments to the program, which are passed on the commandline. <emphasis>Note</emphasis>, that for windows-users, who tend to click on the icon (as opposed to starting <application>yabasic</application> on the command line), this <function>peek</function>will mostly return 0.</para>
  <para>The function <function>peek("argument")</function> can be written as <function>peek("arguments")</function> too.</para>
  <para>You will want to check out the corresponding function <function><link linkend="ref_peek2">peek$("argument")</link></function> to actually <emphasis>retrieve</emphasis> the arguments. <emphasis>Note</emphasis>, that each call to <function>peek$("argument")</function> reduces the number returned by <function>peek("argument")</function>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("isbound")</function></term>
       <listitem>
  <para>Return <constant>true</constant>, if the executing <application>yabasic</application>-program is part of a standalone program; see the section about <link linkend="ref_standalone">creating a <emphasis>standalone</emphasis>-program</link> for details.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("version")</function></term>
       <listitem>
  <para>Return the version number of yabasic (e.g. 2.72).</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek("error")</function></term>
       <listitem>
  <para>Return a number specifying the nature of the last error in an <function>open</function>- or <function>seek</function>-statement. Normally an error within an <function>open</function>-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 <function>open</function> as a condition (e.g. <literal>if (open(#1,"foo")) …</literal>) the outcome (success or failure) of the <function>open</function>-operation will determine, if the condition evaluates to <constant>true</constant> or <constant>false</constant>. 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 <function>peek("error")</function> (as a number) or by <function>peek$("error")</function> (as a string)</para>
  <para>The table below shows the various error codes; the value returned by <function>peek$("error")</function> explains the nature of the error. Note, that the codes 10,11 and 12 refer to the <function>seek</function>-command.</para>
  
  <table frame="all">
    <title>Error codes</title>
    <tgroup cols="3">
      <thead>
        <row>
   <entry><function>peek("error")</function></entry>
   <entry><function>peek$("error")</function></entry>
   <entry>Explanation</entry>
        </row>
      </thead>
      <tbody>


        <row>
   <entry align="center">2</entry>
   <entry><computeroutput>Stream already in use</computeroutput></entry>
   <entry>Do not try to open one and the same filenumber twice; rather <function><link linkend="ref_close">close</link></function> it first.</entry>
        </row>


        <row>
   <entry align="center">3</entry>
   <entry><computeroutput>'x' is not a valid filemode</computeroutput></entry>
   <entry>The optional <emphasis>filemode</emphasis> argument, which may be passed to the <function><link linkend="ref_open">open</link></function>-function, has an invalid value</entry>
        </row>


        <row>
   <entry align="center">4</entry>
   <entry><computeroutput>could not open 'foo'</computeroutput></entry>
   <entry>The <function>open</function>-call did not work, no further explanation is available.</entry>
        </row>


        <row>
   <entry align="center">5</entry>
   <entry><computeroutput>reached maximum number of open files</computeroutput></entry>
   <entry>You have opened more files than your operating system permits.</entry>
        </row>


        <row>
   <entry align="center">6</entry>
   <entry><computeroutput>cannot open printer: already printing graphics</computeroutput></entry>
   <entry>The commands <function><link linkend="ref_open_printer">open printer</link></function> and <function><link linkend="ref_open">open #1,printer</link></function> 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.</entry>
        </row>
        
        <row>
   <entry align="center">7</entry>
   <entry><computeroutput>could not open line printer</computeroutput></entry>
   <entry>Well, it simply did not work.</entry>
        </row>


        <row>
   <entry align="center">9</entry>
   <entry><computeroutput>invalid stream number</computeroutput></entry>
   <entry>An attempt to use an invalid (e.g. negative) stream number; example: <literal>open(-1,"foo")</literal></entry>
        </row>


        <row>
   <entry align="center">10</entry>
   <entry><computeroutput>could not position stream x to byte y</computeroutput></entry>
   <entry><function><link linkend="ref_seek">seek</link></function> did not work.</entry>
        </row>


        <row>
   <entry align="center">11</entry>
   <entry><computeroutput>stream x not open</computeroutput></entry>
   <entry>You have tried to <function><link linkend="ref_seek">seek</link></function> within a stream, that has not been opened yet.</entry>
        </row>


        <row>
   <entry align="center">12</entry>
   <entry><computeroutput>seek mode 'x' is none of begin,end,here</computeroutput></entry>
   <entry>The argument, which has been passed to <function><link linkend="ref_seek">seek</link></function> is invalid.</entry>
        </row>


      </tbody>
    </tgroup>
  </table>
       </listitem>
     </varlistentry>


   </variablelist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open "foo" for reading as #1
open "bar" for writing as #2
while(not eof(#1))
  poke #2,chr$(peek(#1));
wend
          </programlisting>
     <para>This program will copy the file <filename>foo</filename> byte by byte to <filename>bar</filename>.</para>
     <para>Note, that each <function>peek</function> does something entirely different, and only one has been demonstrated above. Therefore you need to make up examples yourself for all the other <function>peek</function>s.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_peek2">peek$</link></function>, <function><link linkend="ref_poke">poke</link></function>, <function><link linkend="ref_open">open</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_peek2">
<refmeta>
   <refentrytitle>peek$</refentrytitle>
</refmeta>
<refnamediv>
   <refname>peek$</refname>
   <refpurpose>retrieve various internal string-informations</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print peek$("foo")
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>peek$</function>-function has many different and unrelated uses. It is a kind of grabbag for retrieving all kinds of string information, internal to <application>yabasic</application>; the exact nature of the strings returned be the <function>peek$</function>-function depends on the string passed as an argument.</para>
   <para><function>peek$</function> always returns a string, however the closely related <function><link linkend="ref_peek">peek</link></function>-function exists, which may be used to retrieve numerical information from among the internals of <application>yabasic</application>. Finally note, that some of the values which are retrieved with <function>peek$</function> may even be changed, using the <function><link linkend="ref_poke">poke</link></function>-function.</para>
   <para>The following list shows all possible arguments to <function>peek$</function>:</para>


   <variablelist>


     <varlistentry>
       <term><function>peek$("infolevel")</function></term>
       <listitem>
  <para>Returns either <literal>"debug"</literal>, <literal>"note"</literal>, <literal>"warning"</literal>, <literal>"error"</literal> or <literal>"fatal"</literal>, depending on the current infolevel. This value can be specified with an option (either under <link linkend="windows_options">windows</link> or <link linkend="unix_options">unix</link>) on the commandline or changed during the execution of the program with the corresponding <function><link linkend="ref_poke">poke</link></function>; however, normally only the author of <application>yabasic</application> (<emphasis>me</emphasis> !) would want to change this from its default value <literal>"warning"</literal>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("textalign")</function></term>
       <listitem>
  <para>Returns one of nine possible strings, specifying the default alignment of text within the graphics-window. The alignment-string returned by this <function>peek</function> describes, how the <function><link linkend="ref_text">text</link></function>-command aligns its string-argument with respect to the coordinates supplied. However, this value does <emphasis>not apply</emphasis>, if the <function>text</function>-command explicitly specifies an alignment. Each of these strings is two characters long. The first character specifies the horizontal alignment and can be either <literal>l</literal>, <literal>r</literal> or <literal>c</literal>, which stand for <wordasword>left</wordasword>, <wordasword>right</wordasword> or <wordasword>center</wordasword>. The second character specifies the vertical alignment and can be one of <literal>t</literal>, <literal>b</literal> or <literal>c</literal>, which stand for <wordasword>top</wordasword>, <wordasword>bottom</wordasword> or <wordasword>center</wordasword> respectively.</para>
  <para>You may change this value with the corresponding command <function>poke "textalign",…</function>; the initial value is <literal>lb</literal>, 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 <function>text</function>-command.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("windoworigin")</function></term>
       <listitem>
  <para>This <function>peek</function> 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 <function>poke "windoworigin",x,y</function> or specified as the argument of the <function><link linkend="ref_origin">origin</link></function> command; see there for a detailed description of the string, which might be returned by this <function>peek</function>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("error")</function></term>
       <listitem>
  <para>Return a string describing the nature of the last error in an <function>open</function>- or <function>seek</function>-statement. See the corresponding <function><link linkend="ref_peek">peek("error")</link></function> for a detailed description.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("library")</function></term>
       <listitem>
  <para>Return the name of the library, this statement is contained in. See the <function><link linkend="ref_import">import</link></function>-command for a detailed description or for more about libraries.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("os")</function></term>
       <listitem>
  <para>This <function>peek</function> returns the name of the operating system, where your program executes. This can be either <literal>windows</literal> or <literal>unix</literal>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("font")</function></term>
       <listitem>
  <para>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 <function><link linkend="ref_open_window">open window</link></function>-command.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>peek$("argument")</function></term>
       <listitem>
  <para>Return one of the arguments, that have been passed to <application>yabasic</application> at invocation time (the next call will return the the second argument, and so on). E.g. if <application>yabasic</application> has been called like this: <literal>yabasic foo.yab bar baz</literal>, then the first call to <function>peek$("argument")</function> will return <literal>bar</literal>. This is because <literal>foo.yab</literal> is treated as the name of the program to run, whereas <literal>bar</literal> and <literal>baz</literal> are considered arguments to this program, which are passed on the commandline. The second call to <function>peek$("argument")</function> will return <literal>baz</literal>. <emphasis>Note</emphasis>, that for windows-users, who tend to click on the icon (as opposed to starting <application>yabasic</application> on the command line), this <function>peek</function>will mostly return the empty string.</para>
  <para>Note, that <function>peek$("argument")</function> can be written as <function>peek$("arguments")</function>.</para>
  <para>Finally you will want to check out the corresponding function <function><link linkend="ref_peek">peek("argument")</link></function>.</para>


       </listitem>
     </varlistentry>


   </variablelist>



</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "You have supplied these arguments: "
while(peek("argument"))
  print peek("argument"),peek$("argument")
wend
          </programlisting>
     <para>If you save this program in a file <filename>foo.yab</filename> and execute it via <userinput>yabasic t.yab a b c</userinput> (for windows users: please use the commandline for this), your will get this output:</para>
<screen>
3a
2b
1c
</screen>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_peek">peek</link></function>, <function><link linkend="ref_poke">poke</link></function>, <function><link linkend="ref_open">open</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_pi">
<refmeta>
   <refentrytitle>pi</refentrytitle>
</refmeta>
<refnamediv>
   <refname>pi</refname>
   <refpurpose>a constant with the value <computeroutput>3.14159</computeroutput></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print pi
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>pi</function> is <literal>3.14159265359</literal> (well at least for <application>yabasic</application>); do not try to assign to pi (e.g. <literal>pi=22/7</literal>) this would not only be mathematically dubious, but would also result in a syntax error.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=0 to 180
  print "The sine of ",a," degrees is ",sin(a*pi/180)
next a
          </programlisting>
     <para>This program uses <function>pi</function> to transform an angle from degrees into radians.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_euler">euler</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_poke">
<refmeta>
   <refentrytitle>poke</refentrytitle>
</refmeta>
<refnamediv>
   <refname>poke</refname>
   <refpurpose>change selected internals of <application>yabasic</application></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
poke "foo","bar"
poke "foo",baz
poke #a,"bar"
poke #a,baz
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>poke</function>-command may be used to change details of <application>yabasic</application>s behaviour. Like the related function <function>peek</function>, <function>poke</function> does many different things, depending on the arguments supplied.</para>
   <para>Here are the different things you can do with <function>poke</function>:</para>
   <variablelist>


     <varlistentry>
       <term><function>poke "textalign","cc"</function></term>
       <listitem>
  <para>This <function>poke</function> changes the <emphasis>default</emphasis> alignment of text with respect to the coordinates supplied within the <function>text</function>-command. However, this value does <emphasis>not apply</emphasis>, if the <function>text</function>-command explicitly specifies an alignment. The second argument (<literal>"cc"</literal> in the example) must always be two characters long; the first character can be one of <literal>l</literal> (<wordasword>left</wordasword>), <literal>r</literal> (<wordasword>right</wordasword>) or <literal>c</literal> (<wordasword>center</wordasword>); the second character can be either <literal>t</literal> (<wordasword>top</wordasword>), <literal>b</literal> (<wordasword>bottom</wordasword>) or <literal>c</literal> (<wordasword>center</wordasword>); see the corresponding <function><link linkend="ref_peek2">peek$("textalign")</link></function> for a detailed description of this argument.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>poke "windoworigin","lt"</function></term>
       <listitem>
  <para>This <function>poke</function> moves the origin of the coordinate system of the window to the specified position. The second argument (<literal>"lt"</literal> in the example) must always be two characters long; the first character can be one of <literal>l</literal> (<wordasword>left</wordasword>), <literal>r</literal> (<wordasword>right</wordasword>) or <literal>c</literal> (<wordasword>center</wordasword>); the second character can be either <literal>t</literal> (<wordasword>top</wordasword>), <literal>b</literal> (<wordasword>bottom</wordasword>) or <literal>c</literal> (<wordasword>center</wordasword>). Together those two characters specify the new position of the coordinate-origin. See the corresponding <function><link linkend="ref_peek2">peek$("windoworigin")</link></function> for a more in depth description of this argument.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>poke "infolevel","debug"</function></term>
       <listitem>
  <para>Change the amount of internal information, that <application>yabasic</application> outputs during execution.</para>
  <para>The second argument can be either <literal>"debug"</literal>, <literal>"note"</literal>, <literal>"warning"</literal>, <literal>"error"</literal> or <literal>"fatal"</literal>. However, normally you will not want to change this from its default value <literal>"warning"</literal>.</para>
  <para>See also the related <function><link linkend="ref_peek2">peek$("infolevel")</link></function>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><function>poke #1,a</function></term>
       <listitem>
  <para>Write the given byte (<literal>a</literal> in the example above) to the specified stream (<literal>#a</literal> in the example).</para>
  <para>See also the related function function <function><link linkend="ref_peek">peek(#1)</link></function>.</para>
       </listitem>
     </varlistentry>


   </variablelist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Hello, now you will see, how much work"
print "a simple for-loop involves ..."
input "Please press return " a$
poke "infolevel","debug"
for a=1 to 10:next a
          </programlisting>
     <para>This example only demonstrates one of the many <function>poke</function>s, which are described above: The program switches the infolevel to <literal>debug</literal>, which makes <application>yabasic</application> produce a lot of debug-messages during the subsequent <function>for</function>-loop.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_peek">peek</link></function>, <function><link linkend="ref_peek2">peek$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_print">
<refmeta>
   <refentrytitle>print</refentrytitle>
</refmeta>
<refnamediv>
   <refname>print</refname>
   <refpurpose>Write to terminal or file</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print "foo",a$,b
print "foo","a$,b;
print #a "foo",a$
print #a "foo",a$;
print a using "##.###"
print reverse "foo"
print at(10,10) a$,b
print @(10,10) a$,b
print color("red","blue") a$,b
print color("magenta") a$,b
print color("green","yellow") at(5,5) a$,b
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>print</function>-statement outputs strings or characters, either to your terminal (also known as <wordasword>console</wordasword>) or to an open file.</para>
   <para>To understand all those uses of the <function>print</function>-statement, let's go throught the various lines in the synopsis above:</para>
   <variablelist>


     <varlistentry>
       <term><literal>print "foo",a$,b</literal></term>
       <listitem>
  <para>Print the string <literal>foo</literal> as well as the contents of the variables <literal>a$</literal> and <literal>b</literal> onto the screen, silently adding a <emphasis>newline</emphasis>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print "foo",a$,b;</literal></term>
       <listitem>
  <para>(Note the trailing semicolon !) This statement does the same as the one above; only the implicit <emphasis>newline</emphasis> is skipped, which means that the next <function>print</function>-statement will append seamlessly.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print #a "foo",a$</literal></term>
       <listitem>
  <para>This is the way to write to files. The file with the number <literal>a</literal> must be open already, an implicit <emphasis>newline</emphasis> is added. Note the file-number <literal>#a</literal>, which starts with a hash ('<literal>#</literal>') amd is separated from the rest of the statement by a space only. The file-number (contained in the variable <literal>a</literal>) must have been returned by a previous <function><link linkend="ref_open">open</link></function>-statement (e.g. <literal>a=open("bar")</literal>).</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print #a "foo",a$;</literal></term>
       <listitem>
  <para>The same as above, but without the implicit <emphasis>newline</emphasis>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print a using "##.###"</literal></term>
       <listitem>
  <para>Print the number <varname>a</varname> with as many digits before and after the decimal dot as given by the number of '<literal>#</literal>'-signs. See the entries for <function><link linkend="ref_using">using</link></function> and <function><link linkend="ref_str">str$</link></function> for a detailed description of this format.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print reverse "foo"</literal></term>
       <listitem>
  <para>As all the <function>print</function>-variants to follow, this form of the <function>print</function>-statement can only be issued after <function><link linkend="ref_clear_screen">clear screen</link></function> has been called. The strings and numbers after the <literal>reverse</literal>-clause are simply printed inverse (compared to the normal <function>print</function>-statement).</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print at(10,10) a$,b</literal></term>
       <listitem>
  <para>Print at the specified (x,y)-position. This is only allowed after <function>clear screen</function> has been called. You may want to query <function><link linkend="ref_peek2">peek$("screenwidth")</link></function> or <function><link linkend="ref_peek2">peek$("screenheight")</link></function> to learn the actual size of your screen. You may add a semicolon to suppress the implicit newline.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print @(10,10) a$,b</literal></term>
       <listitem>
  <para>This is exactly the same as above, however, <literal>at</literal> may be written as <literal>@</literal>.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print color("red","blue") at(5,5) a$,b</literal></term>
       <listitem>
  <para>Print with the specified fore- (<literal>"red"</literal>) and background (<literal>"blue"</literal>) color (or colour). The possible values are <literal>"black"</literal>, <literal>"white"</literal>, <literal>"red"</literal>, <literal>"blue"</literal>, <literal>"green"</literal>, <literal>"yellow"</literal>, <literal>"cyan"</literal> or <literal>"magenta"</literal>. Again, you need to call <literal>clear screen</literal> first and add a semicolon if you want to suppress the implicit newline.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print color("magenta") a$,b</literal></term>
       <listitem>
  <para>You may specify the foreground color only.</para>
       </listitem>
     </varlistentry>


     <varlistentry>
       <term><literal>print color("green","yellow") a$,b</literal></term>
       <listitem>
  <para>A color and a position (in this sequence, not the other way around) may be specified at once.</para>
       </listitem>
     </varlistentry>


   </variablelist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
columns=peek("screenwidth")
lines=peek("screenheight")
dim col$(7)
for a=0 to 7:read col$(a):next a
data "black","white","red","blue","green","yellow","cyan","magenta"


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) "*"
  i=i+1
next a
          </programlisting>
     <para>This example draws a cloured ellipse within the text window.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_at">at</link></function><function>, <function><link linkend="ref_color">color</link></function>, <link linkend="ref_input">input</link></function>, <function><link linkend="ref_clear_screen">clear screen</link></function>, <function><link linkend="ref_using">using</link></function>, <function><link linkend="ref_semicolon">;</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_putbit">
<refmeta>
   <refentrytitle>putbit</refentrytitle>
</refmeta>
<refnamediv>
   <refname>putbit</refname>
   <refpurpose>draw a rectangle of pixels into the graphic window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open window 200,200

a$=getbit(20,20,50,50)

putbit a$,30,30
putbit a$ to 30,30
putbit a$,30,30,"or"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>putbit</function>-command is the counterpart of the <function><link linkend="ref_getbit">getbit</link></function>-function. <function>putbit</function> requires a string as returned by the <function><link linkend="ref_getbit">getbit</link></function>-function. Such a string contains a rectangle from the graphic window; the <function>putbit</function>-function puts such a rectangular region back into the graphic-window.</para>
   <para>Note, that the <function>putbit</function>-command currently accepts a third argument. However only the string value <literal>"or"</literal> 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).</para>
   <para>Note, that the format of the string returned by this function is due to change as soon as <application>yabasic</application> will learn, how to deal with colors.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
c$="41,41:0000000000000000000000000400000000cff1000000ffff100000ffff700008fffff30008ffffff0008ffffff3008fffffff000fffffff100fffffff700ffffffff10efffffff30cfffffff70cffffffff18ffffffff30ffffffff70effffffff0cffffffff1cffffffff30ffffffff70effffffff0cffffffff18ffffffff30ffffffff70cfffffff708ffffffff00ffffffff10cfffffff100fffffff100effffff3008ffffff3000efffff30008fffff30000cffff100000ffff1000000ff700000000000000000000000000000000000"


open window 200,200
do
  x=ran(200)
  y=ran(200)
  putbit c$,x,y,"or"
loop
          </programlisting>
     <para>This program uses a precanned string (containing the image of a circle) and draws it repeatedly into the graphic-window. The mode <literal>"or"</literal> ensures, that no pixels will be cleared.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_getbit">getbit$</link></function>, <function><link linkend="ref_open_window">open window</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_putscreen">
<refmeta>
   <refentrytitle>putscreen</refentrytitle>
</refmeta>
<refnamediv>
   <refname>putscreen</refname>
   <refpurpose>draw a rectangle of characters into the text terminal</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen

a$=getscreen$(5,5,10,10)

putscreen a$,7,7
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>putscreen</function>-command is the counterpart of the <function><link linkend="ref_getscreen">getscreen$</link></function>-function. <function>putscreen</function> requires a string as returned by the <function><link linkend="ref_getscreen">getscreen</link></function>-function. Such a string contains a rectangular detail from the terminal; the <function>putscreen</function>-function puts such a region back into the terminal-window.</para>
   <para>Note, that <function><link linkend="ref_clear_screen">clear screen</link></function> must have been called before.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
for a=1 to 200
  print color("red") "Hallo !";
  print color("blue") "Welt !";
next a
r$=getscreen$(0,0,20,20)
for x=0 to 60
  putscreen r$,x,0
  sleep 0.1
next x
          </programlisting>
     <para>This example prints the string <literal>"Hallo !Welt !"</literal> all over the screen and then moves a rectangle from one side to the other.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_getscreen">getscreen$</link></function>, <function><link linkend="ref_clear_screen">clear screen</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_r">
      <title>R</title>


      <refentry id="ref_ran()">
<refmeta>
   <refentrytitle>ran()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>ran()</refname>
   <refpurpose>return a random number</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print ran()
x=ran(y)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>ran</function>-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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
c=peek("screenwidth")-1
l=peek("screenheight")


dim col$(8)
for a=0 to 7:read col$(a):next a
data "black","white","red","blue","green","yellow","cyan","magenta"


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) "*";
loop
          </programlisting>
     <para>This example will print a cloured bell-curve.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_int">int</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_read">
<refmeta>
   <refentrytitle>read</refentrytitle>
</refmeta>
<refnamediv>
   <refname>read</refname>
   <refpurpose>read data from <function>data</function>-statements</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
read a$,a

data "Hello !",7
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>read</function>-statement retrieves literal data, which is stored within <function>data</function>-statements elsewhere in your program.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
read num
dim col$(num)
for a=1 to num:read col$(a):next a
clear screen
print "These are the colours known to yabasic:\n"
for a=1 to num
  print colour(col$(a)) col$(a)
next a


data 8,"black","white","red","blue"
data "green","yellow","cyan","magenta"
          </programlisting>
     <para>This program prints the names of the colors known to <application>yabasic</application> in those very colors.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_data">data</link>, <function><link linkend="ref_restore">restore</link></function></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_rectangle">
<refmeta>
   <refentrytitle>rectangle</refentrytitle>
</refmeta>
<refnamediv>
   <refname>rectangle</refname>
   <refpurpose>draw a rectangle</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <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
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>rectangle</function>-command (also known as <function>box</function> or <function>rect</function>, 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 <function>clear</function> and <function>fill</function> (which may appear both and in any sequence) the rectangle can be cleared and filled respectively.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>This example draws a nice animated pattern; watch it for a couple of hours, to see how it develops.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_window">open window</link></function>, <function><link linkend="ref_open_printer">open printer</link></function>, <function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_circle">circle</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_redim">
<refmeta>
   <refentrytitle>redim</refentrytitle>
</refmeta>
<refnamediv>
   <refname>redim</refname>
   <refpurpose>create an array prior to its first use. A synonym for <function>dim</function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
See the <function><link linkend="ref_dim">dim</link></function>-command.
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>redim</function>-command does exactly the same as the <function><link linkend="ref_dim">dim</link></function>-command; it is just a <emphasis>synonym</emphasis>. <function>redim</function> has been around in older versions of <acronym>basic</acronym> (not even <application>yabasic</application>) for many years; therefore it is supported in <application>yabasic</application> for compatibility reasons.</para>
   <para>Please refer to the entry for the <function><link linkend="ref_dim">dim</link></function>-command for further information.</para>
</refsect1>
      </refentry>


      <refentry id="ref_rem">
<refmeta>
   <refentrytitle>rem</refentrytitle>
</refmeta>
<refnamediv>
   <refname>rem</refname>
   <refpurpose>start a comment</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
rem  Hey, this is a comment
#    this is a comment too
// even this
print "Not a comment" #    This is an error !!
print "Not a comment"://   But this is again a valid comment
print "Not a comment" //   even this.
print "Not a comment" rem  and this !
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>rem</function> introduces a comment (like <literal>#</literal> or <literal>//</literal>), that extends up to the end of the line.</para>
   <para>Those comments do not even need a colon ('<literal>:</literal>' infront of them); they (<literal>rem</literal>, <literal>#</literal> and <literal>//</literal>) all behave alike except for <literal>#</literal>, which may only appear at the very beginning of a line; therefore the fourth example in the synopsis above (<literal>print "Not a comment" #    This is an error !!</literal>) is indeed an error.</para>
   <para>Note, that <function>rem</function> is an abbreviation for <emphasis>remark</emphasis>. <function>remark</function> however is <emphasis>not</emphasis> a valid command in <application>yabasic</application>.</para>
   <para>Finally note, that a comment intoduced with '<literal>#</literal>' may have a special meaning under unix; see the entry for <link linkend="ref_hash">#</link> for details.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
#
rem   comments on data structures
#     are more useful than
//    comments on algorithms.
rem
          </programlisting>
     <para>This program does nothing, but in a splendid and well commented way.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_hash">#</link></function>, <function><link linkend="ref_double_slash">//</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_repeat">
<refmeta>
   <refentrytitle>repeat</refentrytitle>
</refmeta>
<refnamediv>
   <refname>repeat</refname>
   <refpurpose>start a <function>repeat</function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
repeat
  …
until (…)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>repeat</function>-loop executes all the statements up to the final <function>until</function>-keyword over and over. The loop is executed as long as the condition, which is specified with the <function>until</function>-clause, becomes true. By construction, the statements within the loop are executed at least once.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
x=0
clear screen
print "This program will print the numbers from 1 to 10"
repeat
  x=x+1
  print x
  print "Press any key for the next number, or 'q' to quit"
  if (inkey$="q") break
until(x=10)
          </programlisting>
     <para>This program is pretty much useless, but self-explanatory.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_until">until</link></function>, <function><link linkend="ref_break">break</link></function>, <function><link linkend="ref_while">while</link></function>, <function><link linkend="ref_do">do</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_restore">
<refmeta>
   <refentrytitle>restore</refentrytitle>
</refmeta>
<refnamediv>
   <refname>restore</refname>
   <refpurpose>reposition the <function>data</function>-pointer</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <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
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>restore</function>-command may be used to <emphasis>reset</emphasis> the reading of <function>data</function>-statements, so that the next <function>read</function>-statement will read data from the first <function>data</function>-statement.</para>
   <para>You may specify a <link linkend="ref_label">label</link> with the <function>restore</function>-command; in that case, the next <function>read</function>-statement will read data starting at the given label. If the label is omitted, reading data will begin with the first <function>data</function>-statement within your program.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Which language (german/english) ? " l$
if (instr("german",l$)>0) then
  restore german
else
  restore english
endif


for a=1 to 3
  read x,x$
  print x,"=",x$
next a


label english
data 1,"one",2,"two",3,"three"
label german
data 1,"eins",2,"zwei",3,"drei"
          </programlisting>
     <para>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.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_read">read</link></function>, <function><link linkend="ref_data">data</link></function>, <function><link linkend="ref_label">label</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_return">
<refmeta>
   <refentrytitle>return</refentrytitle>
</refmeta>
<refnamediv>
   <refname>return</refname>
   <refpurpose>return from a subroutine or a gosub</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
gosub foo

label foo

return


sub bar(baz)
  …
  return quertz
end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>return</function>-statement serves two different (albeit somewhat related) purposes. The probably more important use of <function>return</function> 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 <function>return</function>-statement might be accompanied by a string or number, which constitutes the <emphasis>return value</emphasis> of the subroutine.</para>
   <para>However, even if the subroutine should return a value, the <function>return</function>-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 <function>return</function>-statements within your subroutine; it's a nice way of controlling the flow of execution.</para>
   <para>The second (but historcially first) use of <function>return</function> is to return to the position, where a prior <function><link linkend="ref_gosub">gosub</link></function> has left off. In that case <function>return</function> may <emphasis>not</emphasis> carry a value.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  read a$
  if (a$="") then
    print
    end
  endif
  print mark$(a$)," ";
loop


data "The","quick","brown","fox","jumped"
data "over","the","lazy","dog",""


sub mark$(a$)
  if (instr(lower$(a$),"q")) return upper$(a$)
  return a$
end sub
          </programlisting>
     <para>This example features a subroutine <function>mark$</function>, that returns its argument in upper case, if it contains the letter "q", or unchanged otherwise. In the test-text the word <literal>quick</literal> will end up beeing marked as <literal>QUICK</literal>.</para>
     <para>The example above demonstrates <function>return</function> within subroutines; please see <link linkend="ref_gosub"><function>gosub</function></link> for an example of how to use <function>return</function> in this context.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><link linkend="ref_sub"><function>sub</function></link>, <link linkend="ref_gosub"><function>gosub</function></link></para>
</refsect1>
      </refentry>


      <refentry id="ref_reverse">
<refmeta>
   <refentrytitle>reverse</refentrytitle>
</refmeta>
<refnamediv>
   <refname>reverse</refname>
   <refpurpose>print reverse (background and foreground colors exchanged)</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen

print reverse "foo"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>reverse</function> may be used to <function>print</function> text in reverse. <function>reverse</function> is not a seperate command, but part of the <function>print</function>-command; it may be included just after the <function>print</function> and can only be issued once that <function>clear screen</function> has been issued.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen


print "1 ";
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 " ";
  c=c+1
loop
          </programlisting>
     <para>This program prints numbers from 1 on and marks each prime number in reverse.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_at">at</link></function><function>, <function><link linkend="ref_color">color</link></function>, <link linkend="ref_print">print</link></function>, <function><link linkend="ref_clear_screen">clear screen</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_right">
<refmeta>
   <refentrytitle>right$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>right$()</refname>
   <refpurpose>return (<emphasis>or change</emphasis>) the right end of a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print right$(a$,2)
right$(b$,2)="baz"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>right$</function>-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, <function>right$</function> simply returns the requested number of chars from the right end of the given string.</para>
   <para>Note, that the <function>right$</function>-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 <function>right$</function>-function. Note, that that way the <emphasis>length</emphasis> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Please enter a length either in inch or centimeter"
print "please add 'in' or 'cm' to mark the unit."
input "Length: " a$
if (right$(a$,2)="in") then
   length=val(a$)*2.56
elsif (right$(a$,2)="cm") then
   length=val(a$)
else
   error "Invalid input: "+a$
endif
          </programlisting>
     <para>This program allows the user to enter a length qulified with a unit (either inch or centimeter).</para>
     <para>This second example demonstrates the capability to <emphasis>assign</emphasis> to the <function>right$</function>-function.</para>
     <programlisting>
a$="Heiho World !"
print a$
right$(a$,7)="dwarfs."
print a$
</programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_right">right$</link></function> and <function><link linkend="ref_mid">mid$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_rinstr">
<refmeta>
   <refentrytitle>rinstr()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>rinstr()</refname>
   <refpurpose>find the rightmost occurence of one string within the other</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
pos=rinstr("Thequickbrownfox","equi")
pos=rinstr(a$,b$,x)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>rinstr</function>-function accepts two string-arguments and tries to find the second within the first. However, unlike the <function><link linkend="ref_instr">instr</link></function>, the <function>rinstr</function>-function finds the <emphasis>rightmost</emphasis> (or last) occurence of the string; whereas the <function>instr</function>-function finds the <emphasis>leftmost</emphasis> (or first) occurence. In any case however, the position is counted from the left.</para>
   <para>If you supply a third, numeric argument to the <function>rinstr</function>-function, it will be used as a starting point for the search. Therefore <function>rinstr("abcdeabcdeabcde","e",8)</function> will return 5, because the search for an "<literal>e</literal>" starts at position 8 and finds the first one at position 5.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print rinstr("foofoofoobar","foo")
          </programlisting>
     <para>This simple example will print <computeroutput>7</computeroutput>, because it finds the <emphasis>rightmost</emphasis> among the three occurences of <literal>foo</literal> within the string. Note, that</para>
     <informalexample>
       <programlisting>
print instr("foofoofoobar","foo")
</programlisting>
     </informalexample>
     <para>would have printed <computeroutput>1</computeroutput>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_instr">instr</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_rtrim">
<refmeta>
   <refentrytitle>rtrim$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>rtrim$()</refname>
   <refpurpose>trim spaces at the right end of a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=rtrim$(b$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>rtrim$</function>-function removes all wthitespace from the right end of a string and returns the result.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open 1,"foo"
dim lines$(100)
l=1
while(not eof(1))
  input #1 a$
  a$=rtrim$(a$)
  if (right$(line$,1)="\\") then
    line$=line$+" "+a$
  else
    lines$(l)=line$
    l=l+1
    line$=a$
  endif
end while
print "Read ",l," lines"
          </programlisting>
     <para>This example reads the file <filename>foo</filename> allowing for <emphasis>continuation lines</emphasis>, which are marked by a <literal>\</literal>, which appears as the last character on a line. For convenience whitespace at the right end of a line is trimmed with <function>rtrim</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_ltrim">ltrim$</link></function>, <function><link linkend="ref_trim">trim$</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_s">
      <title>S</title>


      <refentry id="ref_screen">
<refmeta>
   <refentrytitle>screen</refentrytitle>
</refmeta>
<refnamediv>
   <refname>screen</refname>
   <refpurpose>as <function>clear screen</function> clears the text window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The keyword <function>screen</function> appears only within the sequence <function><link linkend="ref_clear_screen">clear screen</link></function>; please see there for a description.</para>
</refsect1>
<refsect1>
   <title>See also</title>
<para><function><link linkend="ref_clear_screen">clear screen</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_seek">
<refmeta>
   <refentrytitle>seek()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>seek()</refname>
   <refpurpose>change the position within an open file</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open 1,"foo"
seek #1,q
seek #1,x,"begin"
seek #1,y,"end"
seek #1,z,"here"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>seek</function>-command changes the position, where the next <function>input</function> (or <function>peek</function>) 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 <function>seek</function>-command, allowing you to change the position, where the next piece of data will be read from the file.</para>
   <para><function>seek</function> 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:</para>
   <variablelist>
     <varlistentry>
       <term><literal>begin</literal></term>
       <listitem>
  <para>Count from the beginning of the file.</para>
       </listitem>
     </varlistentry>
     <varlistentry>
       <term><literal>end</literal></term>
       <listitem>
  <para>Count from the end of the file.</para>
       </listitem>
     </varlistentry>
     <varlistentry>
       <term><literal>here</literal></term>
       <listitem>
  <para>Count from the current position within the file.</para>
       </listitem>
     </varlistentry>
   </variablelist>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open #1,"count.dat","w"
for a=1 to 10
  print #1,"00000000";
  if (a<10) print #1,";";
next a


dim count(10)
do
  x=int(ran(10))
  i=i+1
  if (mod(i,1000)=0) print ".";
  count(x)=count(x)+1
  curr$=right$("00000000"+str$(count(x)),8)
  seek #1,9*x,"begin"
  print #1,curr$;
loop
          </programlisting>
     <para>This example increments randomly one of ten counters (in the array <literal>count()</literal>); however, the result is always kept and updated within the file <filename>count.dat</filename>, so even in case of an unexpected interrupt, the result will not be lost.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_tell">tell</link></function>, <function><link linkend="ref_open">open</link></function>, <function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_peek">peek</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sig">
<refmeta>
   <refentrytitle>sig()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sig()</refname>
   <refpurpose>return the sign of its argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a=sig(b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Return <literal>+1</literal>, <literal>-1</literal> or <literal>0</literal>, if the single argument is positive, negative or zero.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
clear screen
dim c$(3):c$(1)="red":c$(2)="white":c$(3)="green"
do
  num=ran(100)-50
  print color(c$(2+sig(num))) num
loop
          </programlisting>
     <para>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)</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_abs">abs</link></function>, <function><link linkend="ref_int">int</link></function>, <function><link linkend="ref_frac">frac</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sin">
<refmeta>
   <refentrytitle>sin()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sin()</refname>
   <refpurpose>return the sine of its single argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
y=sin(angle)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>sin</function>-function expects an angle (in radian, <emphasis>not</emphasis> degree) and returns its sine.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>This program draws a circle (ignoring the existence of the <function><link linkend="ref_circle">circle</link></function>-command).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_asin">asin</link></function>, <function><link linkend="ref_cos">cos</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sleep">
<refmeta>
   <refentrytitle>sleep</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sleep</refname>
   <refpurpose>pause, sleep, wait for the specified number of seconds</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
sleep 4
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>sleep</function>-command has many different names: You may write <function>pause</function>, <function>sleep</function> or <function>wait</function> interchangable; whatever you write, <application>yabasic</application> will always do exactly the same.</para>
   <para>Therefore you should refer to the entry for the <function><link linkend="ref_pause">pause</link></function>-function for further information.</para>
</refsect1>
      </refentry>


      <refentry id="ref_split">
<refmeta>
   <refentrytitle>split()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>split()</refname>
   <refpurpose>split a string into many strings</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
dim w$(10)

num=split(a$,w$())
num=split(a$,w$(),s$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>split</function>-function requires a string (containing the text to be split), a <link linkend="ref_array_references">reference</link> to a string-array (which will receive the resulting strings, i.e. the <emphasis>tokens</emphasis>) and an optional string (with a set of characters, at which to split, i.e. the <emphasis>delimiters</emphasis>).</para>
   <para>The <function>split</function>-function views its first argument (a string) as a list of <emphasis>tokens</emphasis> separated by <emphasis>delimiters</emphasis> and it will store the list of tokens within the array-reference you have supplied; normally (i.e. if you omit the third, which is the delimiter-argument) the function will regard <emphasis>space</emphasis> or <emphasis>tab</emphasis> as delimiters for tokens; however by supplying a third argument, you may split at <emphasis>any single</emphasis> of the characters within this string. E.g. if you supply <literal>":;"</literal> as the third argument, then colon (<literal>:</literal>) or semicolon (<literal>;</literal>) will delimit tokens.</para>
   <para>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 <function><link linkend="ref_token">token</link></function>-function, if you do not like this behaviour. In some way, the <function>split</function>-function focuses on the separators (other than the <function>token</function>-function, which focuses on the <emphasis>tokens</emphasis>), hence its name.</para>
   <para>The second argument is a <link linkend="ref_array_references">reference</link> 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.</para>
   <para>The first argument finally contains the text, that will be split into tokens. The <function>split</function>-function returns the number of tokens that have been found.</para>
   <para>Please see the examples below for some hints on the exact behaviour of the <function>split</function>-function and how it differs from the <function>token</function>-function:</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "This program will help you to understand, how the"
print "split()-function exactly works and how it behaves"
print "in certain special cases."
print
print "Please enter a line containing tokens separated"
print "by either '=' or '-'"
dim t$(10)
do
  print
  input "Please enter a line: " l$
  num=split(l$,t$(),"=-")
  print num," Tokens: ";
  for a=1 to num
    if (t$(a)="") then
      print "(EMPTY)";
    else
      print t$(a);
    endif
    if (a<num) print ",";
  next a
  print
loop
          </programlisting>
     <para>This program prints the following output:</para>
     <para>
<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)
</screen>
</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_token">token</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sqr">
<refmeta>
   <refentrytitle>sqr()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sqr()</refname>
   <refpurpose>compute the square of its argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a=sqr(b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>sqr</function>-function computes the square of its numerical argument (i.e. it multiplies its argument with itself).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10
  print a,sqr(a),a**2
next a
          </programlisting>
     <para>As you may see from the output, <function>sqr</function> can be written as <function>**2</function> (or <function>^2</function>) too.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sqrt">sqrt</link></function>, <function><link linkend="ref_pow">**</link></function>, <function><link linkend="ref_pow">^</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sqrt">
<refmeta>
   <refentrytitle>sqrt()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sqrt()</refname>
   <refpurpose>compute the square root of its argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>to be written</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>sqrt</function>-function computes the square root of its numerical argument.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 5
  print a,sqrt(a),a**(1/2)
next a
          </programlisting>
     <para>As you may see from the output, <function>sqrt</function> can be written as <function>**(1/2)</function> (or <function>^(1/2)</function>) too.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sqr">sqr</link></function>, <function><link linkend="ref_pow">**</link></function>, <function><link linkend="ref_pow">^</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_static">
<refmeta>
   <refentrytitle>static</refentrytitle>
</refmeta>
<refnamediv>
   <refname>static</refname>
   <refpurpose>preserves the value of a variable between calls to a subroutine</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
sub foo()


  static a


  …


end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>static</function> keyword can be used within subroutines to mark variables as <emphasis>static</emphasis>. This has two effects: First, the variable is <emphasis>local</emphasis> to the subroutine, i.e. its value is not know outside the subroutine (this is the effect of the <function><link linkend="ref_local">local</link></function> keyword). Second, the <function>static</function>-keyword arranges things, so that the variable keeps its value between invocations of the subroutine (this is different from the <function>local</function>-keyword).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
foo()
foo()
foo()


sub foo()
  static a
  local b
  a=a+1
  b=b+1
  print a,b
end sub
          </programlisting>
     <para>This program shows the difference between <function>static</function> and <function>local</function> variables within a subroutine; it produces this output:</para>
     <para>
<screen>1 1
2 1
3 1
</screen>
</para>
     <para>The output shows, that the <function>static</function> variable <varname>a</varname> keeps its value between subroutine calls, whereas <varname>b</varname> is initialized with the value 0 at every call to the subroutine <function>foo</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sub">sub</link></function>, <function><link linkend="ref_local">local</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_step">
<refmeta>
   <refentrytitle>step</refentrytitle>
</refmeta>
<refnamediv>
   <refname>step</refname>
   <refpurpose>specifies the increment step in a for-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
for a=1 to 10 step 3
  …
next a
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>Specify, by which amount the loop-variable of a <function><link linkend="ref_for">for</link></function>-loop will be incremented at each step.</para>
   <para>The <function>step</function> (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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for x=1 to 1000 step y
  y=x+y
  print x," ",y," ";
next x
print
          </programlisting>
     <para>This program computes the fibonacci numbers between 1 and 1000.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_for">for</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_str">
<refmeta>
   <refentrytitle>str$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>str$()</refname>
   <refpurpose>convert a number into a string</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=str$(a)
b$=str$(x,"##.###")
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>str$</function>-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 <emphasis>format</emphasis> 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: <emphasis>C-style</emphasis> and <emphasis>basic-style</emphasis>; 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 '<literal>#</literal>'.</para>
   <para>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 <emphasis>exactly</emphasis> otherwise.</para>
  <table frame="all">
    <title>Examples for the format argument</title>
    <tgroup cols="2">
      <thead>
        <row>
   <entry><function>Example string</function></entry>
    <entry><function>Result for converting 1000*<constant>pi</constant></function></entry>
   <entry><function>Description</function></entry>
        </row>
      </thead>
      <tbody>


        <row>
    <entry><literal>%2.5f</literal></entry>
    <entry><literal>3141.59265</literal></entry>
    <entry>The '<literal>2</literal>' determines the minimum length of the output; but if needed (as in the example) the output can be longer. The '<literal>5</literal>' is the number of digits after the decimal point.</entry>
        </row>


        <row>
    <entry><literal>%12.5f</literal></entry>
    <entry><literal>xx3141.59265</literal></entry>
    <entry>Two spaces (which appear as '<literal>x</literal>') are added to pad the output to the requested length of 12 characters.</entry>
        </row>


        <row>
    <entry><literal>%012.5g</literal></entry>
    <entry><literal>0000003141.6</literal></entry>
    <entry>The '<literal>g</literal>' requests, that the precision ('<literal>5</literal>') specifies the <emphasis>overall</emphasis> number of digits (before and after the decimal point).</entry>
        </row>


        <row>
    <entry><literal>%-12.5f</literal></entry>
    <entry><literal>3141.59265xx</literal></entry>
    <entry>The '<literal>-</literal>' requests the output to be left-centered (therefor the filling space appears at thi right).</entry>
        </row>


        <row>
    <entry><literal>#####.##</literal></entry>
    <entry><literal>x3141.59</literal></entry>
    <entry>Each '<literal>#</literal>' specifies a digit (either before or after the dot), the '<literal>.</literal>' specifies the position of the dot. As 1000*<constant>pi</constant> does not have enough digits, the 5 requested digits before the dot are filled up with a space (which shows up as an '<literal>x</literal>').</entry>
        </row>


        <row>
    <entry><literal>#####</literal></entry>
    <entry><literal>x3142</literal></entry>
    <entry>Each '<literal>#</literal>' specifies a digit (either before or after the dot), the '<literal>.</literal>' specifies the position of the dot. As 1000*<constant>pi</constant> does not have enough digits, the 5 requested digits before the dot are filled up with a space (which shows up as a '<literal>x</literal>').</entry>
        </row>


        <row>
    <entry><literal>##.###</literal></entry>
    <entry><literal>******</literal></entry>
    <entry>As 1000*<constant>pi</constant> has 4 digits infront of the decimal dot and the format only specifies 2, <application>yabasic</application> does not know what to do; therefore it chooses to fill it all up with stars '<literal>*</literal>'.</entry>
        </row>


      </tbody>
    </tgroup>
  </table>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  input "Please enter a format string: " f$
  a$=str$(1000*pi,f$)
  for a=1 to len(a$)
    if (mid$(a$,a,1)=" ") mid$(a$,a,1)="x"
  next a
  print a$
loop
          </programlisting>
     <para>This is the program, that has been used to get the results shown in the table above.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_using">using</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_sub">
<refmeta>
   <refentrytitle>sub</refentrytitle>
</refmeta>
<refnamediv>
   <refname>sub</refname>
   <refpurpose>declare a user defined subroutine</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
foo(2,"hello")




sub foo(bar,baz$)
  …
  return qux
  …
end sub
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>sub</function>-keyword starts the definition of a <emphasis>user defined subroutine</emphasis>. With user defined subroutines you are able to somewhat extend <application>yabasic</application> 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).</para>
   <para>The name of the subroutine follows after the keyword <function>sub</function>. If the name (in the synopsis: <function>foo</function>) ends on a '<literal>$</literal>', the subroutine should return a string (with the <function><link linkend="ref_return">return</link></function>-statement), otherwise a number.</para>
   <para>After the name of the subroutine <application>yabasic</application> 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 <function><link linkend="ref_peek">peek("argument")</link></function> you may find out, how many arguments have really been passed while calling the subroutine.</para>
<para>Parameters of a subroutine are always local variables (see the keyword <function><link linkend="ref_local">local</link></function> for more explanation).</para>
   <para>From within the subroutine you may return any time with the keyword <function><link linkend="ref_return">return</link></function>; along with the <function>return</function>-keyword you may specify the return value. Note that more than one <function>return</function> is allowed within a single subroutine.</para>
   <para>Finally, the keyword <function>end sub</function> ends the subroutine definition. Note, that the definition of a subroutine <emphasis>need not</emphasis> appear within the program <emphasis>before</emphasis> the first call to this sub.</para>
   <note>
     <para>As <emphasis>braces</emphasis> have two uses in <application>yabasic</application> (i.e. for supplying arguments to a subroutine as well as to list the indices of an array). <application>yabasic</application> can not tell apart an array from a subroutine with the same name. Therefore you <emphasis>cannot</emphasis> define a subroutine with the same name as an array !</para>
   </note>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <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
          </programlisting>
     <para>This example is not the recommended way to compute prime numbers. However it gives a nice demonstration of using a subroutine.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_local">local</link></function>, <function><link linkend="ref_static">static</link></function>, <function><link linkend="ref_peek">peek</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_switch">
<refmeta>
   <refentrytitle>switch</refentrytitle>
</refmeta>
<refnamediv>
   <refname>switch</refname>
   <refpurpose>select one of many alternatives depending on a value</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
switch a
  case 1
  case 2
  …
end switch




switch a$
  case "a"
  case "b"
end switch
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>switch</function>-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 <function><link linkend="ref_case">case</link></function>-clause. If the expression equals the value given in a <function>case</function>-clause, the subsequent statements are executed.</para>
   <para>The <function><link linkend="ref_default">default</link></function>-clause allows to specify commands, which should be executed, if none of <function>case</function>-clauses matches.</para>
   <para>Note, that many <function>case</function>-clauses might be clustered (e.g. <literal>case "a":case "b":case "c"</literal>). Or put another way: You need a <function>break</function>-statement at the end of a <function>case</function>-branch, if you do not want to run into the next <function>case</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a single digit: " n
switch n
  case 0:print "zero":break
  case 1:print "one":break
  case 2:print "two":break
  case 3:print "three":break
  case 4:print "four":break
  case 5:case 6: case 7:case 8:case 9
    print "Much !":break
  default:print "Hey ! That was more than a single digit !"
end switch
          </programlisting>
   <para>This example translates a single digit into a string; note, how the cases 5 to 7 are clustered.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_switch">switch</link></function>, <function><link linkend="ref_case">case</link></function>, <function><link linkend="ref_break">break</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_system">
<refmeta>
   <refentrytitle>system$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>system$()</refname>
   <refpurpose>hand a statement over to your operating system and return its output</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print system$("dir")
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>system$</function>-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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter the name of a directory: " d$
print
print "This is the contents of the '"+d$+"':"
print system$("dir "+d$)
          </programlisting>
     <para>This example lists the contents of a directory, employing the <application>dir</application>-command  (which is about the only program, that is known under Unix as well as Windows).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_system">system</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_system2">
<refmeta>
   <refentrytitle>system()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>system()</refname>
   <refpurpose>hand a statement over to your operating system and return its exitcode</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
ret=system("foo")
system("bar")
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>system</function>-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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Please enter the name of the file, that should be deleted."
input f$
if (system("rm "+f$+" >/dev/null 2>&1")) then
  print "Error !"
else
  print "okay."
endif
          </programlisting>
     <para>This program is Unix-specific: It uses the Unix-command <function>rm</function> to remove a file.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_system2">system$</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_t">
      <title>T</title>


      <refentry id="ref_tan">
<refmeta>
   <refentrytitle>tan()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>tan()</refname>
   <refpurpose>return the tangens of its argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
foo=tan(bar)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>tan</function>-function computes the tangens of its arguments (which should be specified in radian).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=0 to 45
  print tan(a*pi/180)
next a
          </programlisting>
     <para>This example simply prints the tangens of all angles between 0 and 45 degree.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_atan">atan</link></function>, <function><link linkend="ref_sin">sin</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_tell">
<refmeta>
   <refentrytitle>tell</refentrytitle>
</refmeta>
<refnamediv>
   <refname>tell</refname>
   <refpurpose>get the current position within an open file</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open #1,"foo"
  …
position=tell(#1)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>tell</function>-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.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open #1,"foo","w"
print #1 "Hello World !"
close #1


open #1,"foo"
seek #1,0,"end"
print tell(#1)
close 1
          </programlisting>
     <para>This example (mis)uses <function>tell</function> to get the size of the file. The <function>seek</function> positions the file pointer at the end of the file, therefor the call to <function>tell</function> returns the total length of the file.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_tell">tell</link></function>, <function><link linkend="ref_open">open</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_text">
<refmeta>
   <refentrytitle>text</refentrytitle>
</refmeta>
<refnamediv>
   <refname>text</refname>
   <refpurpose>write text into your graphic-window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
text x,y,"foo"
text x,y,"foo","l"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>text</function>-function displays a text-string (the third argument) at the given position (the first two arguments) within an already <function><link linkend="ref_open_window">open</link></function>ed <function><link linkend="ref_open_window">window</link></function>. 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 <function><link linkend="ref_open_window">open window</link></function>-statement).</para>
   <para>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 <literal>l</literal>, <literal>r</literal> or <literal>c</literal>, which stand for <wordasword>left</wordasword>, <wordasword>right</wordasword> or <wordasword>center</wordasword>. The second character specifies the vertical alignment and can be one of <literal>t</literal>, <literal>b</literal> or <literal>c</literal>, which stand for <wordasword>top</wordasword>, <wordasword>bottom</wordasword> or <wordasword>center</wordasword> respectively. If you omit this alignment argument, the default <literal>"lb"</literal> applies; however this default may be changed with <function><link linkend="ref_poke">poke "textalign","xx"</link></function></para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open window 500,200
clear screen
data "lt","lc","lb","ct","cc","cb","rt","rc","rb"
for a=1 to 9
  read align$
  print "Alignment: ",align$
  line 50*a-15,100,50*a+15,100
  line 50*a,85,50*a,115
  text 50*a,100,"Test",align$
  inkey$
next a
          </programlisting>
     <para>This program draws nine crosses and writes the same text at each; however it goes through all possible nine alignment strings, showing their effect.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_window">open window</link></function>, <function><link linkend="ref_peek">peek</link></function>, <function><link linkend="ref_poke">poke</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_then">
<refmeta>
   <refentrytitle>then</refentrytitle>
</refmeta>
<refnamediv>
   <refname>then</refname>
   <refpurpose>tell the long from the short form of the <function>if</function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
if (a<b) then
  …
endif
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The keyword <function>then</function> is part of the <function><link linkend="ref_if">if</link></function>-statement; please see there for further explanations. However, not every <function>if</function>-statement requires the keyword <function>then</function>: If the keyword <function>then</function> is present, the <function>if</function>-clause may extend over more than one line, and the keyword <function>endif</function> is required to end it. If the keyword <function>then</function> is <emphasis>not</emphasis> present, the <function>if</function>-statement extends up to the end of the line, and any <function>endif</function> would be an error.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
if (1<2) then
  print "Hello ";
endif


if (2<3) print "world"
if (2<1)
  print "!"
          </programlisting>
     <para>This example prints <literal>Hello world</literal>. Note, that no exclamation mark (<literal>!</literal>) is printed, which might come as a surprise and may be changed in future versions of <application>yabasic</application>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_if">if</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_time">
<refmeta>
   <refentrytitle>time$</refentrytitle>
</refmeta>
<refnamediv>
   <refname>time$</refname>
   <refpurpose>return a string containing the current time</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print time$
print time$()
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>time$</function> function returns the current time in four fields separated by hyphens '<literal>-</literal>'. The fields are:</para>
   <para>
<itemizedlist>
       <listitem>
  <para>The current hour in the range from 0 to 23, padded with zeroes (e.g. <literal>00</literal> or <literal>04</literal>) to a length of two characters.</para>
       </listitem>
       <listitem>
  <para>The number of minutes, padded with zeroes.</para>
       </listitem>
       <listitem>
  <para>The number of seconds, padded with zeroes.</para>
       </listitem>
       <listitem>
  <para>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.</para>
       </listitem>
     </itemizedlist>
</para>
   <para>At the time of writing this documentation, <function>time$</function> returns <computeroutput>22-58-53-0</computeroutput>. Note, that the first three of the four fields returned by <function>time$</function> have a fixed width; therefore it is easy to extract some fields with the usual string-functions <function><link linkend="ref_mid">mid$</link></function> (and others).</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Hello it is ",time$
print "An empty for-loop with ten million iterations takes ";
s=val(mid$(time$,10))
for a=1 to 10000000:next a
e=val(mid$(time$,10))
print e-s," seconds"
          </programlisting>
     <para>This program benchmarks the <function>for</function>-loop and uses the fourth field of the string returned by <function>time$</function>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_date">date</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_to">
<refmeta>
   <refentrytitle>to</refentrytitle>
</refmeta>
<refnamediv>
   <refname>to</refname>
   <refpurpose>this keyword appears as part of other statements</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
for a=1 to 100 step 2
  …
next a


line x,y to a,b
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>to</function>-keyword serves two purposes (which are not related at all):</para>
   <itemizedlist>
     <listitem>
       <para>within <function><link linkend="ref_for">for</link></function>-statements, to specify the upper bound of the loop.</para>
     </listitem>
     <listitem>
       <para>Within any graphical command (e.g. <function>line</function>), that requires two points (i.e. four numbers) as arguments, a comma '<literal>,</literal>' might be replaced with the keyword <literal>to</literal>. I.e. instead of <literal>100,100,200,200</literal> you may write <literal>100,100 to 200,200</literal> in such commands.</para>
     </listitem>
   </itemizedlist>
</refsect1>
<refsect1>
   <title>Example</title>
   <para>Pleas see the command listed under "See also" for examples.</para>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_for">for</link></function>, <function><link linkend="ref_line">line</link></function>, <function><link linkend="ref_rectangle">rectangle</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_token">
<refmeta>
   <refentrytitle>token()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>token()</refname>
   <refpurpose>split a string into multiple strings</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
dim w$(10)

num=token(a$,w$())
num=token(a$,w$(),s$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>token</function>-function accepts a string (containing the text to be split), a <link linkend="ref_array_references">reference</link> to a string-array (which will receive the resulting strings, i.e. the <emphasis>tokens</emphasis>) and an optional string (with a set of characters, at which to split, i.e. the <emphasis>delimiters</emphasis>).</para>
   <para>The <function>token</function>-function regards its first argument as a list of <emphasis>tokens</emphasis> separated by <emphasis>delimiters</emphasis> and it will store the list of tokens within the array-reference that has been supplied; normally (i.e. if you omit the third, the delimiter-argument) the function will regard <emphasis>space</emphasis> or <emphasis>tab</emphasis> as delimiters for tokens; however by supplying a third argument, you may split at <emphasis>any single</emphasis> of the characters within this string. E.g. if you supply <literal>":;"</literal> as the third argument, then colon (<literal>:</literal>) or semicolon (<literal>;</literal>) will delimit tokens.</para>
   <para>Note, that <function>token</function> will never produce empty tokens, even if two or more separators follow in sequence. Refer to the closely related <function><link linkend="ref_token">split</link></function>-function, if you do not like this behaviour. In some way, the <function>token</function>-function focuses on the tokens and not on the separators (other than the <function>split</function>-function, which focuses on the separators).</para>
   <para>The second argument is a <link linkend="ref_array_references">reference</link> 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.</para>
   <para>The first argument finally contains the text, that will be split into tokens. The <function>token</function>-function returns the number of tokens, that have been found.</para>
   <para>Please see the examples below for some hints on the exact behaviour of the <function>token</function>-function and how it differs from the <function>split</function>-function:</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "This program will help you to understand, how the"
print "token()-function exactly works and how it behaves"
print "in certain special cases."
print
print "Please enter a line containing tokens separated"
print "by either '=' or '-'"
dim t$(10)
do
  print
  input "Please enter a line: " l$
  num=token(l$,t$(),"=-")
  print num," Tokens: ";
  for a=1 to num
    if (t$(a)="") then
      print "(EMPTY)";
    else
      print t$(a);
    endif
    if (a<num) print ",";
  next a
  print
loop
          </programlisting>
This program prints the following output:
     <para>
<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
</screen>
</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_split">split</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_trim">
<refmeta>
   <refentrytitle>trim$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>trim$()</refname>
   <refpurpose>remove leading and trailing spaces from its argument</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
a$=trim$(b$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>trim$</function>-function removes all whitespaces from the left and from the right end of a string and returns the result. Calling <function>trim$</function> is equivalent to calling <function>rtrim$(ltrim$())</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
do
  input "Continue ? Please answer yes or no: " a$
  a$=lower$(trim$(a$))
  if (len(a$)>0 and a$=left$("no",len(a$)) exit
loop
          </programlisting>
     <para>This example asks for an answer (<literal>yes</literal> or <literal>no</literal>) and removes spaces with <function>trim$</function> to make the comparison with the string <literal>"no"</literal> more bulletproof.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_ltrim">ltrim$</link></function>, <function><link linkend="ref_rtrim">rtrim$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_true">
<refmeta>
   <refentrytitle>true</refentrytitle>
</refmeta>
<refnamediv>
   <refname>true</refname>
   <refpurpose>a constant with the value of 1</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
okay=true
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The constant <function>true</function> can be assigned to variables which will later appear in conditions (e.g. an <function>if</function>-statement.</para>
   <para><function>true</function> may also be written as <function>TRUE</function> or even <function>TrUe</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a string of all upper letters: " a$
if (is_upper(a$)) print "Okay"


sub is_upper(a$)
  if (a$=upper$(a$)) return true
  return false
end sub
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_false">false</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_u">
      <title>U</title>


      <refentry id="ref_until">
<refmeta>
   <refentrytitle>until</refentrytitle>
</refmeta>
<refnamediv>
   <refname>until</refname>
   <refpurpose>end a <function>repeat</function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
repeat
  …
until (…)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>until</function>-keyword ends a loop, which has been introduced by the <function><link linkend="ref_repeat">repeat</link></function>-keyword. <function>until</function> requires a condition in braces (or an expression, see <link linkend="ref_conditions_and_expressions">here</link> for details) as an argument; the loop will continue <emphasis>until</emphasis> this condition evaluates to true.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
c=1
s=1
repeat
  l=c
  s=-(s+sig(s))
  c=c+1/s
  print c
until(abs(l-c)<0.000001)
          </programlisting>
     <para>This program calculates the sequence 1/1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+ … ; please let me know, if you know against which value this converges.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_repeat">repeat</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_upper">
<refmeta>
   <refentrytitle>upper$()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>upper$()</refname>
   <refpurpose>convert a string to upper case</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
u$=upper$(a$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>upper$</function>-function accepts a single string argument and converts it to all upper case.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
line input "Please enter a sentence without the letter 'e': " l$
p=instr(upper$(l$),"E")
if (p) then
  l$=lower$(l$)
  mid$(l$,p,1)="E"
  print "Hey, you are wrong, see here!"
  print l$
else
  print "Thanks."
endif
          </programlisting>
     <para>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).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_lower">lower$</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_using">
<refmeta>
   <refentrytitle>using</refentrytitle>
</refmeta>
<refnamediv>
   <refname>using</refname>
   <refpurpose>Specify the format for printing a number</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print a using "##.###"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>using</function>-keyword may appear as part of the <function>print</function>-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.</para>
   <para>The possible values for the format argument (<literal>"##.###"</literal> in the synopsis above) are described within the entry for the <function><link linkend="ref_str">str$</link></function>-function. In fact the <function>using</function> clause is closely related to the <function>str$</function>-function; the former can always be rewritten using the latter; i.e. <literal>print foo using bar$</literal> is always equivalent to <literal>print str$(foo,bar$)</literal>. Therefore you should check out <function><link linkend="ref_str">str$</link></function> to learn more.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
for a=1 to 10
  print sqrt(ran(10000*a)) using "#########.#####"
next a
          </programlisting>
     <para>This example prints a column of square roots of random number, nicely aligned at the decimal dot.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_str">str$</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_v">
      <title>V</title>


      <refentry id="ref_val()">
<refmeta>
   <refentrytitle>val()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>val()</refname>
   <refpurpose>converts a string to a number</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=val(x$)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>val</function>-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 <function>val</function>-function returns zero.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
input "Please enter a length, either in inches (in) or centimeters (cm) " l$
if (right$(l$,2)="in") then
  l=val(l$)*2.51
else
  l=val(l$)
print "You have entered ",l,"cm."
          </programlisting>
     <para>This example queries for a length and checks, if it has been specified in inches or centimeters. The length is then converted to centimeters.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_str">str$</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_w">
      <title>W</title>


      <refentry id="ref_wait">
<refmeta>
   <refentrytitle>wait</refentrytitle>
</refmeta>
<refnamediv>
   <refname>wait</refname>
   <refpurpose>pause, sleep, wait for the specified number of seconds</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
wait 4
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>wait</function>-command has many different names: You may write <function>pause</function>, <function>sleep</function> or <function>wait</function> interchangeable; whatever you write, <application>yabasic</application> will always do exactly the same.</para>
   <para>Therefore you should refer to the entry for the <function><link linkend="ref_pause">pause</link></function>-function for further information.</para>
</refsect1>
      </refentry>


      <refentry id="ref_wend">
<refmeta>
   <refentrytitle>wend</refentrytitle>
</refmeta>
<refnamediv>
   <refname>wend</refname>
   <refpurpose>end a <function><link linkend="ref_while">while</link></function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
while(a<b)
  …
wend
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>wend</function>-keyword marks the end of a <function><link linkend="ref_while">while</link></function>-loop. Please see the <function><link linkend="ref_while">while</link></function>-keyword for more details.</para>
   <para><function>wend</function> can be written as <function>end while</function> or even <function>end-while</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
line input "Please enter a sentence: " a$
p=instr(a$,"e")
while(p)
  mid$(a$,p,1)="E"
  p=instr(a$,"e")
wend
print a$
          </programlisting>
     <para>This example reads a sentence and converts every occurence of the letter <literal>e</literal> into uppercase (<literal>E</literal>).</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_while">while</link></function> (which is just the following entry).</para>
</refsect1>
      </refentry>


      <refentry id="ref_while">
<refmeta>
   <refentrytitle>while</refentrytitle>
</refmeta>
<refnamediv>
   <refname>while</refname>
   <refpurpose>start a <function>while</function>-loop</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
while(…)
  …
wend
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>while</function>-keyword starts a <function>while</function>-loop, i.e. a loop that is excuted as long as the condition (which is specified in braces after the keyword <function>while</function>) evaluates to <constant>true</constant>.</para>
   <para>Note, that the body of such a <function>while</function>-loop will not be executed at all, if the condition following the <function>while</function>-keyword is not true initially.</para>
   <para>If you want to leave the loop prematurely, you may use the <function><link linkend="ref_break">break</link></function>-statement.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
open #1,"foo"
while(!eof(1))
  line input #1 a$
  print a$
wend
          </programlisting>
     <para>This program reads the file <literal>foo</literal> and prints it line by line.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_until">until</link></function>, <function><link linkend="ref_break">break</link></function>, <function><link linkend="ref_wend">wend</link></function>, <function><link linkend="ref_do">do</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_origin">
<refmeta>
   <refentrytitle>window origin</refentrytitle>
</refmeta>
<refnamediv>
   <refname>origin</refname>
   <refpurpose>move the origin of a window</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
open window 200,200
origin "cc"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>origin</function>-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.</para>
   <para>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 <literal>l</literal>, <literal>c</literal> and <literal>r</literal>. In vertical position the allowed positions are top, center and bottom; encoded by the letters <literal>t</literal>, <literal>c</literal> and <literal>b</literal>. Taking the letters together, you arrive at a string, which might be passed as an argument to the command; e.g. <literal>"cc"</literal> or <literal>"rt"</literal>.</para>
</refsect1>
<refsect1>
   <title>Example</title>100,100
   <informalexample>
     <programlisting>
open window 200,200
window origin "cc"
circle 0,0,60
          </programlisting>
     <para>This example draws a circle, centered at the center of the window.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_open_window">open window</link></function></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2"  id="ref_x">
      <title>X</title>


      <refentry id="ref_xor">
<refmeta>
   <refentrytitle>xor()</refentrytitle>
</refmeta>
<refnamediv>
   <refname>xor()</refname>
   <refpurpose>compute the exclusive or</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
x=xor(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <function>xor</function> computes the bitwise <emphasis>exclusive or</emphasis> 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.</para>
   <para>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 <function>and</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print xor(7,4)
          </programlisting>
     <para>This will print <computeroutput>3</computeroutput>. 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.</para>
   <para>The <function>eor</function>-function is the same as the <function>xor</function> function; both are synonymous; however they have each their own description, so you may check out the entry of <function><link linkend="ref_eor">eor</link></function> for a slightly different view.</para>


   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_arithmetic_and">and</link></function>, <link linkend="ref_arithmetic_or"><function>or</function></link>, <link linkend="ref_eor"><function>eor</function></link>, <link linkend="ref_not"><function>not</function></link></para>
</refsect1>
      </refentry>


    </sect1>


    <sect1 renderas="sect2" id="ref_special_characters">
      <title>Special characters</title>


      <refentry id="ref_hash">
<refmeta>
   <refentrytitle>#</refentrytitle>
</refmeta>
<refnamediv>
   <refname>#</refname>
   <refpurpose>either a comment or a marker for a file-number</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
# This is a comment, but the line below not !
open #1,"foo"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The hash ('<literal>#</literal>') has two totally unrelated uses:</para>
   <itemizedlist>
     <listitem>
       <para>A hash might appear in commands related with file-io. <application>yabasic</application> uses simple numbers to refer to open files (within <function><link linkend="ref_input">input</link></function>, <function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_peek">peek</link></function> or <function><link linkend="ref_eof">eof</link></function>). 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 <emphasis>this</emphasis> entry is about the second use (as a comment).</para>
     </listitem>
     <listitem>
       <para>As the <emphasis>very first</emphasis> character within a line, a hash introduces comments (similar to <function>rem</function>).</para>
     </listitem>
   </itemizedlist>
   <para> '<literal>#</literal>' as a comment is common in most scripting languages and has a special use under Unix: If the <emphasis>very first line</emphasis> of any Unix-program begins with the character sequence '<literal>#!</literal>' ("she-bang", 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 <application>yabasic</application>-program starts with '<literal>#!/usr/local/bin/yabasic</literal>', the program <filename>/usr/local/bin/yabasic</filename> will be invoked to execute the rest of the program. As a remark for windows-users: This mechanism ensures, that <application>yabasic</application> will be invoked to execute your program; the ending of the file (e.g. <literal>.yab</literal>) will be ignored by Unix.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
# This line is a valid comment
print "Hello " : # But this is a syntax error, because
print "World!" : # the hash is not the first character !
          </programlisting>
     <para>Note, that this example will produce a syntax error and is <emphasis>not</emphasis> a valid program !</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_input">input</link></function>, <function><link linkend="ref_print">print</link></function>, <function><link linkend="ref_peek">peek</link></function> or <function><link linkend="ref_eof">eof</link></function>, <function><link linkend="ref_double_slash">//</link></function>, <function><link linkend="ref_rem">rem</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_double_slash">
<refmeta>
   <refentrytitle>//</refentrytitle>
</refmeta>
<refnamediv>
   <refname>//</refname>
   <refpurpose>starts a comment</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
//  This is a comment !
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The double-slash ('<literal>//</literal>') is (besides <literal>REM</literal> and '<literal>#</literal>') the third way to start a comment. '<literal>//</literal>' is the latest and greatest in the field of commenting and allows <application>yabasic</application> to catch up with such cool languages like C++ and Java.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
// Another comment.
print "Hello world !" // Another comment
          </programlisting>
     <para>Unlike the example given for '<literal><link linkend="ref_hash">#</link></literal>' this example is syntactically correct and will not produce an error.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para> <function><link linkend="ref_hash">#</link></function>, <function><link linkend="ref_rem">rem</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_at_sign">
<refmeta>
   <refentrytitle>@</refentrytitle>
</refmeta>
<refnamediv>
   <refname>@</refname>
   <refpurpose>synonymous to <function><link linkend="ref_at">at</link></function></refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
clear screen

print @(a,b)
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>As '<literal>@</literal>' is simply a synonym for <literal>at</literal>, please see <function><link linkend="ref_at">at</link></function> for further information.</para>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_at">at</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_colon">
<refmeta>
   <refentrytitle>:</refentrytitle>
</refmeta>
<refnamediv>
   <refname>:</refname>
   <refpurpose>separate commands from each other</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print "Hello ":print "World"
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The <emphasis>colon</emphasis> ('<literal>:</literal>') separates multiple commands on a single line.</para>
   <para>The <emphasis>colon</emphasis> and the <emphasis>newline</emphasis>-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) <emphasis>short</emphasis> <function>if</function>, which is an <function>if</function>-statement without the keyword <function>then</function>. Please see the entry for <function><link linkend="ref_if">if</link></function> for more details.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
if (a<10) print "Hello ":print "World !"
          </programlisting>
     <para>This example demonstrates the difference between colon and newline as described above.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_if">if</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_semicolon">
<refmeta>
   <refentrytitle>;</refentrytitle>
</refmeta>
<refnamediv>
   <refname>;</refname>
   <refpurpose>suppress the implicit newline after a <function><link linkend="ref_print">print</link></function>-statement</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print "foo",bar;
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para>The semicolon ('<literal>;</literal>') may only appear at the last position within a <function><link linkend="ref_print">print</link></function>-statement. It supresses the implicit newline, which <application>yabasic</application> normally adds after each <function>print</function>-statement.</para>
   <para>Put another way: Normally the output of each <function>print</function>-statement appears on a line by itself. If you rather want the output of many <function>print</function>-statements to appear on a single line, you should end the <function>print</function>-statement with a semicolon.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print "Hello ";:print "World !"
          </programlisting>
     <para>This example prints <computeroutput>Hello World !</computeroutput> <emphasis>in a single line</emphasis>.</para>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_print">print</link></function></para>
</refsect1>
      </refentry>


      <refentry id="ref_pow">
<refmeta>
   <refentrytitle>** or ^</refentrytitle>
</refmeta>
<refnamediv>
   <refname>** or ^</refname>
   <refpurpose>raise its first argument to the power of its second</refpurpose>
</refnamediv>
<refsynopsisdiv>
   <synopsis>
print 2**b
print 3^4
</synopsis>
</refsynopsisdiv>
<refsect1>
   <title>Description</title>
   <para><function>**</function> (or <function>^</function>, 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; <function>**</function> 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 <emphasis>real</emphasis> number (as opposed to a <emphasis>complex</emphasis> number); this means, that the power can <emphasis>not</emphasis> 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 <function>**</function> may be used to compute arbitrary roots: e.g. <function>x**0.5</function> computes the square root of <function>x</function>.</para>
</refsect1>
<refsect1>
   <title>Example</title>
   <informalexample>
     <programlisting>
print 2**0.5
          </programlisting>
   </informalexample>
</refsect1>
<refsect1>
   <title>See also</title>
   <para><function><link linkend="ref_sqrt">sqrt</link></function></para>
</refsect1>
      </refentry>


    </sect1>
  </chapter>



  <chapter id="chapter_ref_concepts">
    <title>A grab-bag of some general concepts and terms</title>
    <para>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 <application>yabasic</application>. 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 <link linkend="chapter_ref_words">alphabetical list of commands</link> refers to them.</para>
    <sect1 renderas="sect2" id="ref_logical_shortcuts">
      <title>Logical shortcuts</title>
      <para><emphasis>Logical shortcuts</emphasis> are no special language construct and there is no keyword for them; they are just a way to evaluate <emphasis>logical expressions</emphasis>. Logical expressions (i.e. a series of conditions or comparisons joined by <link linkend="ref_arithmetic_and"><function>and</function></link> or <link linkend="ref_arithmetic_or"><function>or</function></link>) are only evaluated until the final result of the expression can be determined. An example:</para>
      <informalexample>
<programlisting>
if (a<>0 and b/a>2) print "b is at least twice as big as a"
</programlisting>
      </informalexample>
      <para>
      The logical expression <literal>a<>0 and b/a>2</literal> consists of two comparisons, both of which must be true, if the <function>print</function> statement should be executed. Now, if the first comparison (<literal>a<>0</literal>) is <constant>false</constant>, the whole logical expression can never be <constant>true</constant> and the second comparison (<literal>b/a>2</literal>) need not be evaluated.
      </para>
      <para>This is exactly, how <application>yabasic</application> 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.</para>
      <para>In practice, this has the following consequences:</para>
      <itemizedlist>
<listitem>
   <para>If two or more comparisons are joined with <function>and</function> and one comparison results in <constant>false</constant>, the logical expression is evaluated no further and the overall result is <constant>false</constant>.</para>
</listitem>
<listitem>
   <para>If two or more comparisons are joined with <function>or</function> and one comparison results in <constant>true</constant>, the logical expression is evaluated no further and the result is <constant>true</constant>.</para>
</listitem>
      </itemizedlist>
      <para><quote>Nice, but whats this good for ?</quote>, I hear you say. Well, just have another look at the example, especially the second comparison (<literal>b/a>2</literal>); deviding <literal>b</literal> by <literal>a</literal> is potentially hazardous: If <literal>a</literal> equals zero, the expression will cause an error and your program will terminate. To avoid this, the first part of the comparison (<literal>a<>0</literal>) checks, if the second one can be evaluated without risk. This pre-checking is the most common usage and primary motivation for <emphasis>logical shortcuts</emphasis> (and the reason why most programming languages implement them).</para>
    </sect1>




    <sect1 renderas="sect2" id="ref_conditions_and_expressions">
      <title>Conditions and expressions</title>
      <para>Well, bottomline there is no difference or distinction between <emphasis>conditions</emphasis> and <emphasis>expressions</emphasis>, at least as <application>yabasic</application> 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 <function>if</function>-statement). So the constructs shown in the example below are all totally valid:</para>
      <informalexample>
<programlisting>
input "Please enter a number between 1 and 10: " a


rem   Assigning the result of a comparison to a variable
okay=a>=1 and a<=10


rem   Use a variable within an if-statement
if (not okay) error "Wrong, wrong !"
</programlisting>
      </informalexample>
      <para>So conditions and expressions are really the same thing (at least as long as yabasic is concerned). Therefore the terms <wordasword>conditions</wordasword> and <wordasword>expression</wordasword> can really be used interchangeably, at least in theory. In reality the term <wordasword>condition</wordasword> is used in connection with <function>if</function> or <function>while</function> whereas the term <wordasword>expression</wordasword> tends to be used more often within arithmetic context.</para>
    </sect1>




    <sect1 renderas="sect2" id="ref_array_references">
      <title>References on arrays</title>
      <para><emphasis>References on arrays</emphasis> are the only way to refer to an array <emphasis>as a whole</emphasis> and to pass it to subroutines or functions like <link linkend="ref_arraydim"><function>arraydim</function></link> or <link linkend="ref_arraysize"><function>arraysize</function></link>. Whereas (for example) <literal>a(2)</literal> designates the second element of the array <literal>a</literal>, <literal>a()</literal> (with empty braces) refers to the array <literal>a</literal> itself. <literal>a()</literal> is called an <emphasis>array reference</emphasis>.</para>
      <para>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:</para>
      <itemizedlist>
<listitem>
   <para><emphasis>Speed and space:</emphasis> Creating a copy of an array would be a time- and resourceconsuming operation; passing just a reference is cheap and fast.</para>
</listitem>
<listitem>
   <para>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.</para>
</listitem>
      </itemizedlist>
    </sect1>




    <sect1 renderas="sect2" id="ref_windows_filenames">
      <title>Specifying Filenames under Windows</title>
      <para>As you probably know, windows uses the character '<literal>\</literal>' to separate the directories within a pathname; an example would be <literal>C:\yabasic\yabasic.exe</literal> (the usual location of the <application>yabasic</application> executable). However, the very same character '<literal>\</literal>' is used to contstruct <link linkend="ref_escape_sequences">escape sequences</link>, not only in <application>yabasic</application> but in most other programming languages.</para>
      <para>Therefore the string <literal>"C:\t.dat"</literal> does <emphasis>not</emphasis> specify the file <literal>t.dat</literal> within the directory <literal>C:</literal>; this is because the sequence '<literal>\t</literal>' is translated into the tab-character. To specify this filename, you need to use the string <literal>"C:\\t.dat"</literal> (note the double slash '<literal>\\</literal>').</para>
    </sect1>




    <sect1 renderas="sect2" id="ref_escape_sequences">
      <title>Escape-sequences</title>
      <para><emphasis>Escape-sequences</emphasis> 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).</para>
      <para>Escape-sequences may occur within any string at any position; they are replaced at <emphasis>parsetime</emphasis> (opposed to <emphasis>runtime</emphasis>), i.e. as soon as <application>yabasic</application> discovers the string, with their corresponding <emphasis>special</emphasis> character. As a consequence of this <function>len("\a")</function> returns 1, because <application>yabasic</application> replaces <function>"\a"</function> with the matching special character just before the program executes.</para>
      <table frame="all">
<title>Escape sequences</title>
<tgroup cols="2">
   <thead>
     <row>
       <entry>Escape Seqence</entry>
       <entry>Matching special character</entry>
     </row>
   </thead>
   <tbody>
     <row>
       <entry><computeroutput>\n</computeroutput></entry>
       <entry><emphasis>newline</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\t</computeroutput></entry>
       <entry><emphasis>tabulator</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\v</computeroutput></entry>
       <entry><emphasis>vertical tabulator</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\b</computeroutput></entry>
       <entry><emphasis>backspace</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\r</computeroutput></entry>
       <entry><emphasis>carriage return</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\f</computeroutput></entry>
       <entry><emphasis>formfeed</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\a</computeroutput></entry>
       <entry><emphasis>alert</emphasis> (i.e. a beeping sound)</entry>
     </row>
     <row>
       <entry><computeroutput>\\</computeroutput></entry>
       <entry><emphasis>backslash</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\'</computeroutput></entry>
       <entry><emphasis>single quote</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\"</computeroutput></entry>
       <entry><emphasis>double quote</emphasis></entry>
     </row>
     <row>
       <entry><computeroutput>\x</computeroutput><emphasis>HEX</emphasis></entry>
       <entry><function>chr$(</function><emphasis>HEX</emphasis><function>)</function> (see below)</entry>
     </row>
   </tbody>
</tgroup>
      </table>
      <para>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
     <acronym>ascii</acronym>-charset:
     For example \x012 is transformed into the character <function>chr$(18)</function> (or <function>chr$(dec("12",16))</function>. Note that \x requires a
     hexa-decimal number (and the hexa-decimal string "12" corresponds to the decimal number 18).</para>
      </sect1>



    <sect1 renderas="sect2" id="ref_standalone">
      <title>Creating a <emphasis>standalone</emphasis> program from your yabasic-program</title>
      <note>
<para>The <function>bind</function>-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.</para>
      </note>
      <para>Sometimes you may want to give one of your yabasic-programs to other people. However, what if those other people do not have <application>yabasic</application> installed ? In that case you may create a <emphasis>standalone</emphasis>-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 <application>yabasic</application> installed. Having created a standalone program, you may pass it around like any other program (e.g. one written in <application>C</application>) and you can be sure that your program will execute right away.</para>
      <para>Such a standalone-program is simply created by copying the full <application>yabasic</application>-interpreter and your yabasic-program together into a single, new program, whose name might be chosen at will (under windows of course it should have the ending <filename>.exe</filename>). If you decide to create a standalone-program, there are three bits in yabasic, that you may use:</para>
      <itemizedlist>
<listitem>
   <para>The <function><link linkend="ref_bind">bind</link></function>-command, which does the actual job of creating the standalone program from the <application>yabasic</application>-interpreter and your program.</para>
</listitem>
<listitem>
   <para>The command-line Option <literal>-bind</literal> (available under <link linkend="windows_options">windows</link> and <link linkend="unix_options">Unix</link>), which does the same from the command-line.</para>
</listitem>
<listitem>
   <para>The special <function><link linkend="ref_peek">peek("isbound")</link></function>, which may be used to check, if the <application>yabasic</application>-program containing this <function>peek</function> is bound to the interpreter as part of a standalone program.</para>
</listitem>
      </itemizedlist>
      <para>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.</para>
    <sect3>
<title>Creating a standalone-program from the commandline</title>
<para>Let's say you have the following <emphasis>very</emphasis> simple program within the file <filename>foo.yab</filename>:</para>
<informalexample>
   <programlisting>
print "Hello World !"
</programlisting>
</informalexample>
<para>Normally you would start this <application>yabasic</application>-program by typing <userinput>yabasic foo.yab</userinput> and as a result the string <computeroutput>Hello World !</computeroutput> would appear on your screen. However, to create a <emphasis>standalone</emphasis>-program from <filename>foo.yab</filename> you would type:</para>
<informalexample>
   <para><userinput>yabasic -bind foo.exe foo.yab</userinput></para>
</informalexample>
<para>This command does <emphasis>not</emphasis> execute your program <filename>foo.yab</filename> but rather create a <emphasis>standalone</emphasis>-program <filename>foo.exe</filename>. Note: under Unix you would probably name the standalone program <filename>foo</filename> or such, omitting the windows-specific ending <filename>.exe</filename>. </para>
<para><application>Yabasic</application> will confirm by printing something like: <computeroutput>---Info: Successfully bound 'yabasic' and 'foo.yab' into 'foo.exe'</computeroutput>.</para>
<para>After that you will find a program <filename>foo.exe</filename> (which must be made <emphasis>executable</emphasis> with the <command>chmod</command>-command under Unix first). Now, executing this program <filename>foo.exe</filename> (or <filename>foo</filename> under Unix) will produce the output <computeroutput>Hello World !</computeroutput>.</para>
<para>This newly created program <filename>foo.exe</filename> might be passed around to anyone, even if he does not have <application>yabasic</application> installed.</para>
      </sect3>
    <sect3>
<title>Creating a standalone-program from within your program</title>
<para>It is possible to write a <application>yabasic</application>-program, that binds itself to the <application>yabasic</application>-interpreter. Here is an example:</para>
<informalexample>
   <programlisting>
if (!peek("isbound")) then
  bind "foo"
  print "Successfully created the standalone executable 'foo' !"
  exit
endif


print "Hello World !"
</programlisting>
</informalexample>
<para>If you run this program (which may be saved in the file <filename>foo.yab</filename>) via <userinput>yabasic foo.yab</userinput>, the <function><link linkend="ref_peek">peek("isbound")</link></function> in the first line will check, if the program is already part of a standalone-program. If <emphasis>not</emphasis> (i.e. if the <application>yabasic</application>-interpreter and the <application>yabasic</application>-program are seperate files) the <function><link linkend="ref_bind">bind</link></function>-command will create a standalone program <filename>foo</filename> containing both. As a result you would see the output <computeroutput>Successfully created the standalone executable 'foo' !</computeroutput>. Note: Under Windows you would probably choose the filename <filename>foo.exe</filename>.</para>
<para>Now, if you run this standalone executable <filename>foo</filename> (or <filename>foo.exe</filename>), the very same <application>yabasic</application>-program that is shown above will be executed again. However, this time the <function><link linkend="ref_peek">peek("isbound")</link></function> will return <constant>TRUE</constant> and therefore the condition of the <function>if</function>-statement is <emphasis>false</emphasis> and the three lines after <function>then</function> are <emphasis>not</emphasis> executed. Rather the last <function>print</function>-statement will run, and you will see the output <computeroutput>Hello World !</computeroutput>.</para>
<para>That way a <application>yabasic</application>-program may turn itself into a standalone-program.</para>
      </sect3>
    <sect3>
<title>Downsides of creating a standalone program</title>
<para>Now, before you go out and turn all your <application>yabasic</application>-programs into standalone programs, please take a second to consider the downsides of doing so:</para>
<itemizedlist>
     <listitem>
       <para>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 <application>yabasic</application> themselves.</para>
     </listitem>
   <listitem>
     <para>There is no easy way to extract your <application>yabasic</application>-program from within the standalone program: If you ever want to change it, you need to have it around seperately.</para>
   </listitem>
   <listitem>
     <para>If a new version of <application>yabasic</application> becomes available, again you need to recreate all of your standalone programs to take advantage of bugfixes and improvements.</para>
   </listitem>
   </itemizedlist>
<para>So, beeing able to create a standalone program is certainly a good thin, but certainly <emphasis>not</emphasis> a silver bullet.</para>
      </sect3>
    <sect3>
<title>See also</title>
<para>The <link linkend="ref_bind"><function>bind</function></link>-command, the <link linkend="ref_peek"><function>peek</function></link>-function and the commandline options for <link linkend="unix_options">Unix</link> and <link linkend="windows_options">Windows</link>.</para>
      </sect3>
    </sect1>


  </chapter>


  <chapter id="chapter_examples">
    <title>A few example programs</title>
    <sect1>
      <title>A very simple program</title>
      <para>The program below is a very simple program:</para>
      <programlisting>
repeat
  input "Please enter the first number, to add " a
  input "Please enter the second number, to add " b
  print a+b
until(a=0 and b=0)
</programlisting>
      <para>This program requests two numbers, which it than adds. The process is repeated until you enter zero (or nothing) twice.</para>
    </sect1>
    <sect1>
      <title>A part of the demo of yabasic</title>
      <para>The listing below is an abbreviated and slightly refreshed version of the <emphasis>demo</emphasis> of yabasic. However this demo has been written <emphasis>before</emphasis> some of the more advanced features of <application>yabasic</application> have been implemented. For example <emphasis>subroutines</emphasis> have only been retrofitted on the original version of this demo. So please do not take this as a particular good example of <application>yabasic</application>-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).</para>
    <programlisting>


//
// This program demoes yabasic
//



//  Check, if screen is large enough
clear screen
sw=peek("screenwidth"):sh=peek("screenheight")
if (sw<78 or sh<24) then
  print
  print "  Sorry, but your screen is to small to run this demo !"
  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("cyan","magenta") at(7,2) "################################"
print colour("cyan","magenta") at(7,3) "################################"
print colour("cyan","magenta") at(7,4) "################################"
print colour("yellow","blue") at(8,3) " This is the demo for yabasic "
yoff=7
for a=1 to mmnum
  if (a=mmnum) then ydisp=1:else ydisp=0:fi
  if (a=ysel) then
    print colour("blue","green") at(5,yoff+ydisp+a) mmtext$(a);
  else
    print at(5,yoff+ydisp+a) mmtext$(a);
  endif
next a
print at(3,sh-3) "Move selection with CURSOR KEYS (or u and d),"
print at(3,sh-2) "Press RETURN or SPACE to choose, ESC to quit."



do    // loop for keys pressed
  rev=1
  do    // loop for blinking
    k$=inkey$(0.4)
    if (k$="") then
      if (ysel=mmnum) then
        if (rev=1) then
          print colour("blue","green") at(5,yoff+mmnum+1) mmtext$(mmnum);
          rev=0
        else
          print colour("yellow","red") 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$="up" or k$="u") then
    if (ysel=1) then ysel=mmnum else ysel=ysel-1 fi
    redraw():heal():continue
  fi
  if (k$="down" or k$="d") then
    if (ysel=mmnum) then ysel=1 else ysel=ysel+1 fi
    redraw():heal():continue
  fi
  if (k$=" " or k$="enter" or k$="right") then
    on ysel gosub overview,bitmap,endit,notyet
    goto mainloop
  fi
  if (k$="esc") then
    endit()
  fi
  beep
  print at(3,sh-5) "Invalid key: ",k$,"         "
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("blue","green") at(5,yoff+ysel+ydisp) mmtext$(ysel);
  return
end sub



//  erase a line
sub heal()
  print at(3,sh-5) "                                                       "
  return
end sub



//  Go here to exit
label endit
  print at(3,sh-8) "Hope you liked it ...\n   ";
  exit
return



//  Present a short overview
label overview
  clear screen
  print "\n  Yabasic is a quite traditional basic: It comes with"
  print "  print, input, for-next-loops, goto, gosub, while and"
  print "  repeat and even user defined procedures and libraries."
  print "\n  Yabasic has the usual functions, from sin(), int() to mid$();"
  print "  more advanced functions are date$ (is ",date$,"),"
  print "  or token$(), system$(), ran() and glob$()."
  print "\n  Yabasic makes it easy to open a window, draw lines"
  print "  and print the resulting picture."
  print "\n  Yabasic programs are interpreted and run under Unix"
  print "  and Windows. Yabasic is small (around 200k) and"
  print "  free, i.e. subject to the GNU copyleft."
  print "\n  Finally, this demo itself is written in yabasic and"
  print "  gives an idea of what can be done with the language."
  print "\n\n\n  While you read this, I am calculating prime numbers,"
  print "  Press any key to return to main menu ..."
  can=1
  print at(6,19) "This is a prime number: "
  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))<>"") then return:fi
goto nextcan



//  Show some animated bitmaps
label bitmap
  clear screen
  print at(5,5) "Yabasic offers limited support for bitmapped graphics."
  print at(5,6) "You can retrieve and alter rectangular regions of"
  print at(5,7) "the graphics window with a single command."
  print reverse at(5,12) " Press any key to return to main menu ... "
  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)<=tick) then
        if (pics(a,4)=tick) then
          bitblit pics$(pics(a,3)) to pics(a,1),pics(a,2),"xor"
        endif
        x=cx+50-ran(100):y=cy+50-ran(100)
        if (ran(10)>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),"xor"          
        endif
      endif
    next a
    tick=tick+1
    cx=cx+vx:cy=cy+vy
    if (cx<-30 or cx>400) then cx=cx-vx:vx=-vx fi
    if (cy<-30 or cy>400) then cy=cy-vy:vy=-vy fi
  if (inkey$(0.1)="") then goto picloop fi
  close window
return



//  data for bitmaps
label pics
data "24,24:00000000000000000000000008f1000eff000fff308f9f30cf0c70e30870e30070e00070e07070e07870e0fc70e1ff30e1ff3ec1cf1ec3000fc700cf8f3cf78ffff30efff000ff00"
data "24,24:00c10000e10000f10000f10008f30008f30008f700fff700ffff30ffffffefffffefffff0ffff70eff700eff000cff100eff300fff70cfff70ef7ef1ef1cf3e700e3e100c3000000"
data "24,24:0000000000700e00700e00700e00700e10700e38700c38700c7c30087c3000fe1000ff1000ef0000e70000c70000c30000c30000e10000f10000f0000c70000c70000c3000000000"
data "24,24:000000000000008700008f30008f7000cf7000c37000e97000f97000f83008f8300878300cf8300ef8300efb300eef700fcf700f0f708700f0c700f1c300e1c100e1000000000000"
data "24,24:0000000000000cf1000cff000cff300cbf300c3c700838700c30700cff700cff700cff700c9f700c1c700e10700e10700f38708fff708fff7083ff10000000000000000000000000"



//  Go here for a feature not yet implemented
label notyet
  clear screen
  print "\n\n  Sorry this section is not yet implemented !"
  print "  Press any key to return to main menu ..."
  inkey$
return



//  Data section ...
label mmdata
//  Data for main menu: Number and text of entries in main menu
data 3
data " Yabasic in a nutshell "
data " Animated Bitmaps "
data " Exit this demo "


   </programlisting>


    </sect1>


  </chapter>



  <chapter id="chapter_copyright">
    <title>The Copyright of <application>yabasic</application></title>
    <para><application>yabasic</application> may be copied only under the terms of the <emphasis><ulink url="http://www.yabasic.de/artistic.htm">Artistic License</ulink></emphasis> or the <emphasis><ulink url="http://www.yabasic.de/gpl.htm">GNU General Public License</ulink></emphasis> (GPL), both of which are distributed with <application>yabasic</application>.</para>
    <para><citation>Can't you make up your mind ?!</citation>, I hear you say. Umm, well <emphasis>yes</emphasis>. In fact I do not want to read or try to understand them both, so I have put the burden on <emphasis>you</emphasis> (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.</para>
    <para>Here is a list of things that are possible under the terms of the Artistic License:</para>
    <itemizedlist>
      <listitem>
<para>Put <application>yabasic</application> on your own homepage or CD and even charge for the service of distributing <application>yabasic</application>.</para>
      </listitem>
      <listitem>
<para>Write your own <application>yabasic</application>-programs, pack your program and <application>yabasic</application> into a package and sell the whole thing.</para>
      </listitem>
      <listitem>
<para>Modify <application>yabasic</application> and add or remove features, sell the modified version.</para>
      </listitem>
    </itemizedlist>
  </chapter>



</book>