Man page - yabasic(1)
Packages contains this manual
Manual
yabasic
NAMESYNOPSIS
DESCRIPTION
AUTHOR
SEE ALSO
BUGS
NAME
yabasic - yet another Basic
SYNOPSIS
yabasic [OPTIONS] [FILENAME [ARGUMENTS]]
DESCRIPTION
Yabasic implements the most common and simple elements of the basic language. It comes with goto/gosub, with various loops, with user defined subroutines and libraries. Yabasic does simple graphics and printing. Yabasic runs under Unix and Windows, it is small, open source and free.
This man-page is derived from yabasic.htm, which too should be installed on your system; per default in
/usr/local/share/applications/yabasic/yabasic.htm.
The same information can also be found on www.yabasic.de
Here is its content:
\hâ\n[lss]uâYabasic
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâTable of Contents
\hâ\n[lss]uâ1. Introduction
\hâ\n[lss]uâAbout
this document
\hâ\n[lss]uâAbout yabasic
\hâ\n[lss]uâ2. The yabasic-program under Windows
\hâ\n[lss]uâStarting
yabasic
\hâ\n[lss]uâOptions
\hâ\n[lss]uâThe context Menu
\hâ\n[lss]uâ3. The yabasic-program under Unix
\hâ\n[lss]uâStarting
yabasic
\hâ\n[lss]uâOptions
\hâ\n[lss]uâSetting defaults
\hâ\n[lss]uâ4.
Command line options of yabasic
\hâ\n[lss]uâ5. Some features of yabasic,
explained by topic
\hâ\n[lss]uâprint,
input and others
\hâ\n[lss]uâControl statements: loops, if and
switch
\hâ\n[lss]uâDrawing and painting
\hâ\n[lss]uâReading from and writing to files
\hâ\n[lss]uâSubroutines and Libraries
\hâ\n[lss]uâString processing
\hâ\n[lss]uâArithmetic and numbers
\hâ\n[lss]uâData and such
\hâ\n[lss]uâOther interesting commands.
\hâ\n[lss]uâ6. All commands and functions of yabasic listed by topic
\hâ\n[lss]uâNumber
processing and conversion
\hâ\n[lss]uâConditions and control structures
\hâ\n[lss]uâData keeping and processing
\hâ\n[lss]uâString processing
\hâ\n[lss]uâFile operations and printing
\hâ\n[lss]uâSubroutines and libraries
\hâ\n[lss]uâOther commands
\hâ\n[lss]uâGraphics and printing
\hâ\n[lss]uâ7. All commands and functions of yabasic grouped alphabetically
\hâ\n[lss]uâA
\hâ\n[lss]uâB
\hâ\n[lss]uâC
\hâ\n[lss]uâD
\hâ\n[lss]uâE
\hâ\n[lss]uâF
\hâ\n[lss]uâG
\hâ\n[lss]uâH
\hâ\n[lss]uâI
\hâ\n[lss]uâL
\hâ\n[lss]uâM
\hâ\n[lss]uâN
\hâ\n[lss]uâO
\hâ\n[lss]uâP
\hâ\n[lss]uâR
\hâ\n[lss]uâS
\hâ\n[lss]uâT
\hâ\n[lss]uâU
\hâ\n[lss]uâV
\hâ\n[lss]uâW
\hâ\n[lss]uâX
\hâ\n[lss]uâSpecial characters
\hâ\n[lss]uâReserved Words
\hâ\n[lss]uâ8. Some general concepts and terms
\hâ\n[lss]uâLogical
shortcuts
\hâ\n[lss]uâConditions and expressions
\hâ\n[lss]uâReferences on arrays
\hâ\n[lss]uâSpecifying Filenames under Windows
\hâ\n[lss]uâEscape-sequences
\hâ\n[lss]uâCreating a standalone program from
your yabasic-program
\hâ\n[lss]uâ9. A few example programs
\hâ\n[lss]uâA
very simple program
\hâ\n[lss]uâThe demo of yabasic
\hâ\n[lss]uâ10. The Copyright of yabasic
\hâ\n[lss]uâChapter 1. Introduction
\hâ\n[lss]uâAbout
this document
\hâ\n[lss]uâAbout yabasic
\hâ\n[lss]uâAbout this document
\hâ\n[lss]uâThis
document describes yabasic. You will find information about
the yabasic
\hâ\n[lss]uâinterpreter (the program yabasic
under Unix or yabasic.exe under Windows) as
\hâ\n[lss]uâwell as the language (which is, of
course, a sort of basic) itself.
\hâ\n[lss]uâThis document applies to version 2.82 of yabasic
\hâ\n[lss]uâHowever,
this document does not contain the latest news about yabasic
or a FAQ.
\hâ\n[lss]uâAs such information tends to change
rapidly, it is presented online only at
\hâ\n[lss]uâwww.yabasic.de.
\hâ\n[lss]uâAlthough
basic has its reputation as a language for beginning
programmers, this
\hâ\n[lss]uâis not an introduction to
programming at large. Rather this text assumes, that
\hâ\n[lss]uâthe reader has some (moderate)
experience with writing and starting computer
\hâ\n[lss]uâprograms.
\hâ\n[lss]uâAbout yabasic
\hâ\n[lss]uâyabasic
is a traditional basic interpreter. It understands most of
the typical
\hâ\n[lss]uâbasic-constructs, like goto, gosub,
line numbers, read, data or
\hâ\n[lss]uâstring-variables with a trailing
â$â. But on the other hand, yabasic implements
\hâ\n[lss]uâsome more advanced
programming-constructs like subroutines or libraries (but
\hâ\n[lss]uânot objects). yabasic works much the
same under Unix and Windows.
\hâ\n[lss]uâyabasic
puts emphasis on giving results quickly and easily;
therefore simple
\hâ\n[lss]uâcommands are provided to open a
graphic window, print the graphics or control
\hâ\n[lss]uâthe console screen and get keyboard
or mouse information. The example below
\hâ\n[lss]uâopens a window, draws a circle and
prints the graphic:
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâopen printer
\hâ\n[lss]uâcircle 50,50,40
\hâ\n[lss]uâtext 10,50,"Press any key to
get a printout"
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâclose window
\hâ\n[lss]uâThis
example has fewer lines, than it would have in many other
programming
\hâ\n[lss]uâlanguages. In the end however
yabasic lacks behind more advanced and modern
\hâ\n[lss]uâprogramming languages like C++ or
Java. But as far as it goes it tends to give
\hâ\n[lss]uâyou results more quickly and
easily.
\hâ\n[lss]uâChapter 2. The yabasic-program under Windows
\hâ\n[lss]uâStarting
yabasic
\hâ\n[lss]uâOptions
\hâ\n[lss]uâThe context Menu
\hâ\n[lss]uâStarting yabasic
\hâ\n[lss]uâOnce, yabasic has been set up correctly, there are three ways to start it:
\hâ\n[lss]uâ1.
Right click on your desktop: The desktop menu appears with a
submenu named
\hâ\n[lss]uânew. From this submenu choose
yabasic. This will create a new icon on your
\hâ\n[lss]uâdesktop. If you right click on this
icon, its context menu will appear;
\hâ\n[lss]uâchoose Execute to execute the
program.
\hâ\n[lss]uâ2.
As a variant of the way described above, you may simply
create a file with
\hâ\n[lss]uâthe ending .yab (e.g. with your
favorite editor). Everything else then
\hâ\n[lss]uâworks as described above.
\hâ\n[lss]uâ3.
From the start-menu: Choose yabasic from your start-menu. A
console-window
\hâ\n[lss]uâwill open and you will be asked to
type in your program. Once you are
\hâ\n[lss]uâfinished, you need to type return
twice, and yabasic will parse and execute
\hâ\n[lss]uâyour program.
\hâ\n[lss]uâNote
\hâ\n[lss]uâThis
is not the preferred way of starting yabasic ! Simply
because the
\hâ\n[lss]uâprogram, that you have typed, can
not be saved and will be lost inevitably
\hâ\n[lss]uâ! There is no such thing as a
save-command and therefore no way to conserve
\hâ\n[lss]uâthe program, that you have typed.
This mode is only intended for quick
\hâ\n[lss]uâhacks, and short programs.
\hâ\n[lss]uâOptions
\hâ\n[lss]uâUnder
Windows yabasic will mostly be invoked by double-clicking on
an
\hâ\n[lss]uâappropriate icon; this way you do
not have a chance to specify any of the
\hâ\n[lss]uâcommand line options below. However,
advanced users may change the librarypath
\hâ\n[lss]uâin the registry, which has the same
effect as specifying it as an option on the
\hâ\n[lss]uâcommand line.
\hâ\n[lss]uâSee
the chapter on options for a complete list of all options,
either on Unix
\hâ\n[lss]uâor Windows.
\hâ\n[lss]uâThe context Menu
\hâ\n[lss]uâLike
every other icon under Windows, the icon of every
yabasic-program has a
\hâ\n[lss]uâcontext menu offering the most
frequent operations, that may be applied to a
\hâ\n[lss]uâyabasic-program.
\hâ\n[lss]uâExecute
\hâ\n[lss]uâThis
will invoke yabasic to execute your program. The same
happens, if you
\hâ\n[lss]uâdouble click on the icon.
\hâ\n[lss]uâEdit
\hâ\n[lss]uânotepad will be invoked, allowing you to edit your program.
\hâ\n[lss]uâView docu
\hâ\n[lss]uâThis
will present the embedded documentation of your program.
Embedded
\hâ\n[lss]uâdocumentation is created with the
special comment doc.
\hâ\n[lss]uâChapter 3. The yabasic-program under Unix
\hâ\n[lss]uâStarting
yabasic
\hâ\n[lss]uâOptions
\hâ\n[lss]uâSetting defaults
\hâ\n[lss]uâStarting yabasic
\hâ\n[lss]uâIf
your system administrator (vulgo root) has installed yabasic
correctly,
\hâ\n[lss]uâthere are three ways to start
it:
\hâ\n[lss]uâ1.
You may use your favorite editor (emacs, vi ?) to put your
program into a
\hâ\n[lss]uâfile (e.g. foo). Make sure that the
very first line starts with the
\hâ\n[lss]uâcharacters â#!â followed
by the full pathname of yabasic (e.g. â#!/usr/
\hâ\n[lss]uâlocal/bin/yabasicâ). This
she-bang-line ensures, that your Unix will invoke
\hâ\n[lss]uâyabasic to execute your program (see
also the entry for the hash
\hâ\n[lss]uâ-character). Moreover, you will need
to change the permissions of your
\hâ\n[lss]uâyabasic-program foo, e.g. chmod u+x
foo. After that you may invoke yabasic
\hâ\n[lss]uâto invoke your program by simply
typing foo (without even mentioning
\hâ\n[lss]uâyabasic). However, if your
PATH-variable does not contain a single dot
\hâ\n[lss]uâ(â.â) you will have to
type the full pathname of your program: e.g. /home/
\hâ\n[lss]uâihm/foo (or at least ./foo).
\hâ\n[lss]uâ2.
Save your program into a file (e.g. foo) and type yabasic
foo. This
\hâ\n[lss]uâassumes, that the directory, where
yabasic resides, is contained within
\hâ\n[lss]uâyour PATH-variable.
\hâ\n[lss]uâ3.
Finally your may simply type yabasic (maybe it will be
necessary to include
\hâ\n[lss]uâits full pathname). This will make
yabasic come up and you will be asked to
\hâ\n[lss]uâtype in your program. Once you are
finished, you need to type return twice,
\hâ\n[lss]uâand yabasic will parse and execute
your program.
\hâ\n[lss]uâNote
\hâ\n[lss]uâThis
is not the preferred way of starting yabasic ! Simply
because the
\hâ\n[lss]uâprogram, that you have typed, can
not be saved and will be lost inevitably
\hâ\n[lss]uâ! There is no such thing as a
save-command and therefore no way to conserve
\hâ\n[lss]uâthe program, that you have typed.
This mode is only intended for quick
\hâ\n[lss]uâhacks, and short programs, i.e. for
using yabasic as some sort of fancy
\hâ\n[lss]uâdesktop calculator.
\hâ\n[lss]uâOptions
\hâ\n[lss]uâyabasic accepts a number of options on the command line.
\hâ\n[lss]uâSee
chapter on options for a complete list of all options,
either on Unix or
\hâ\n[lss]uâWindows.
\hâ\n[lss]uâSetting defaults
\hâ\n[lss]uâIf
you want to set some options once for all, you may put them
into your
\hâ\n[lss]uâX-Windows resource file. This is
usually the file .Xresources or some such
\hâ\n[lss]uâwithin your home directory (type man
X for details).
\hâ\n[lss]uâHere is a sample section, which may appear within this file:
\hâ\n[lss]uâyabasic*foreground:
blue
\hâ\n[lss]uâyabasic*background: gold
\hâ\n[lss]uâyabasic*geometry: +10+10
\hâ\n[lss]uâyabasic*font: 9x15
\hâ\n[lss]uâThis
will set the foreground color of the graphic-window to blue
and the
\hâ\n[lss]uâbackground color to gold. The window
will appear at position 10,10 and the text
\hâ\n[lss]uâfont will be 9x15.
\hâ\n[lss]uâChapter 4. Command line options of yabasic
\hâ\n[lss]uâHere
are the options, that yabasic accepts on the command line
(both under Unix
\hâ\n[lss]uâand Windows).
\hâ\n[lss]uâAll
the options below may be abbreviated (and one hyphen may be
dropped), as
\hâ\n[lss]uâlong as the abbreviation does not
become ambiguous. For example, you may write
\hâ\n[lss]uâ-e instead of --execute.
\hâ\n[lss]uâ--help or -?
\hâ\n[lss]uâPrints
a short help message, which itself describes two further
\hâ\n[lss]uâhelp-options.
\hâ\n[lss]uâ--version
\hâ\n[lss]uâPrints the version of yabasic.
\hâ\n[lss]uâ--infolevel INFOLEVEL
\hâ\n[lss]uâChange
the infolevel of yabasic, where INFOLEVEL can be one of
debug, note,
\hâ\n[lss]uâwarning, error, fatal and bison (the
default is warning). This option
\hâ\n[lss]uâchanges the amount of
debugging-information yabasic produces. However,
\hâ\n[lss]uânormally only the author of yabasic
(me !) would want to change this.
\hâ\n[lss]uâ--execute A-PROGRAM-AS-A-SINGLE-STRING
\hâ\n[lss]uâWith
this option you may specify some yabasic-code to be executed
right
\hâ\n[lss]uâaway. This is useful for very short
programs, which you do not want to save
\hâ\n[lss]uâto a file. If this option is given,
yabasic will not read any code from a
\hâ\n[lss]uâfile. E.g.
\hâ\n[lss]uâyabasic -e âfor a=1 to 10:print a*a:next aâ
\hâ\n[lss]uâprints the square numbers from 1 to 10.
\hâ\n[lss]uâ--bind NAME-OF-STANDALONE-PROGRAM
\hâ\n[lss]uâCreate
a standalone program (whose name is specified by
\hâ\n[lss]uâNAME-OF-STANDALONE-PROGRAM) from the
yabasic-program, that is specified on
\hâ\n[lss]uâthe command line. See the section
about creating a standalone-program for
\hâ\n[lss]uâdetails.
\hâ\n[lss]uâ--geometry +X-POSITION+Y-POSITION
\hâ\n[lss]uâSets
the position of the graphic window, that is opened by open
window (the
\hâ\n[lss]uâsize of this window, of course, is
specified within the open
\hâ\n[lss]uâwindow-command). An example would be
-geometry +20+10, which would place
\hâ\n[lss]uâthe graphic window 10 pixels below
the upper border and 20 pixels right of
\hâ\n[lss]uâthe left border of the screen. This
value cannot be changed, once yabasic
\hâ\n[lss]uâhas been started.
\hâ\n[lss]uâ-fg FOREGROUND-COLOR or --foreground FOREGROUND-COLOR
\hâ\n[lss]uâUnix
only. Define the foreground color for the graphics-window
(that will
\hâ\n[lss]uâbe opened with open window). The
usual X11 color names, like red, green, ?
\hâ\n[lss]uâare accepted. This value cannot be
changed, once yabasic has been started.
\hâ\n[lss]uâ-bg BACKGROUND-COLOR or --background BACKGROUND-COLOR
\hâ\n[lss]uâUnix
only. Define the background color for the graphics-window.
The usual
\hâ\n[lss]uâX11 color names are accepted. This
value cannot be changed, once yabasic
\hâ\n[lss]uâhas been started.
\hâ\n[lss]uâ--display X11-DISPLAY-SPECIFICATION
\hâ\n[lss]uâUnix
only. Specify the display, where the graphics window of
yabasic should
\hâ\n[lss]uâappear. Normally this value will be
already present within the environment
\hâ\n[lss]uâvariable DISPLAY.
\hâ\n[lss]uâ--font NAME-OF-FONT
\hâ\n[lss]uâUnder
Unix. Name of the font, which will be used for text within
the
\hâ\n[lss]uâgraphics window.
\hâ\n[lss]uâ--font NAME-OF-FONT
\hâ\n[lss]uâUnder
Windows. Name of the font, which will be used for
graphic-text; can
\hâ\n[lss]uâbe any of decorative, dontcare,
modern, roman, script, swiss. You may
\hâ\n[lss]uâappend a fontsize (measured in
pixels) to any of those fontnames; for
\hâ\n[lss]uâexample -font swiss30 chooses a
swiss-type font with a size of 30 pixels.
\hâ\n[lss]uâ--docu NAME-OF-A-PROGRAM
\hâ\n[lss]uâPrint
the embedded documentation of the named program. The
embedded
\hâ\n[lss]uâdocumentation of a program consists
of all the comments within the program,
\hâ\n[lss]uâwhich start with the special keyword
doc. This documentation can also be
\hâ\n[lss]uâseen by choosing the corresponding
entry from the context-menu of any
\hâ\n[lss]uâyabasic-program.
\hâ\n[lss]uâ--check
\hâ\n[lss]uâCheck
for possible compatibility problems within your
yabasic-program. E.g.
\hâ\n[lss]uâthis option reports, if you are
using a function, that has recently
\hâ\n[lss]uâchanged.
\hâ\n[lss]uâ--librarypath DIRECTORY-WITH-LIBRARIES
\hâ\n[lss]uâChange
the directory, wherein libraries will be searched and
imported (with
\hâ\n[lss]uâthe import-command). See also import
for more information about the way,
\hâ\n[lss]uâlibraries are searched.
\hâ\n[lss]uâ--
\hâ\n[lss]uâDo
not try to parse any further options; rather pass the
subsequent words
\hâ\n[lss]uâfrom the commandline to yabasic.
\hâ\n[lss]uâChapter 5. Some features of yabasic, explained by topic
\hâ\n[lss]uâprint,
input and others
\hâ\n[lss]uâControl statements: loops, if and
switch
\hâ\n[lss]uâDrawing and painting
\hâ\n[lss]uâReading from and writing to files
\hâ\n[lss]uâSubroutines and Libraries
\hâ\n[lss]uâString processing
\hâ\n[lss]uâArithmetic and numbers
\hâ\n[lss]uâData and such
\hâ\n[lss]uâOther interesting commands.
\hâ\n[lss]uâThis
chapter has sections for some of the major features of
yabasic and names a
\hâ\n[lss]uâfew commands related with each area.
So, depending on your interest, you find
\hâ\n[lss]uâthe most important commands of this
area named; the other commands from this
\hâ\n[lss]uâarea may then be discovered through
the links in the see also-section.
\hâ\n[lss]uâprint, input and others
\hâ\n[lss]uâThe
print-command is used to put text on the text screen. Here,
the term text
\hâ\n[lss]uâscreen stands for your terminal
(under Unix) or the console window (under
\hâ\n[lss]uâWindows).
\hâ\n[lss]uâAt
the bottom line, print simply outputs its argument to the
text window.
\hâ\n[lss]uâHowever, once you have called clear
screen you may use advanced features like
\hâ\n[lss]uâprinting colors or copying areas of
text with getscreen$ or putscreen.
\hâ\n[lss]uâYou
may ask the user for input with the input-command; use
inkey$ to get each
\hâ\n[lss]uâkey as soon as it is pressed.
\hâ\n[lss]uâControl statements: loops, if and switch
\hâ\n[lss]uâOf
course, yabasic has the goto- and gosub-statements; you may
go to a label or
\hâ\n[lss]uâa line number (which is just a
special kind of label). goto, despite its bad
\hâ\n[lss]uâreputation ([goto considered
harmful]), has still its good uses; however in
\hâ\n[lss]uâmany cases you are probably better
off with loops like repeat-until, while-wend
\hâ\n[lss]uâor do-loop; you may leave any of
these loops with the break-statement or start
\hâ\n[lss]uâthe next iteration immediately with
continue.
\hâ\n[lss]uâDecisions
can be made with the if-statement, which comes either in a
short and
\hâ\n[lss]uâa long form. The short form has no
then-keyword and extends up to the end of
\hâ\n[lss]uâthe line. The long form extends up
to the final endif and may use some of the
\hâ\n[lss]uâkeywords then (which introduces the
long form), else or elsif.
\hâ\n[lss]uâIf
you want to test the result of an expression against many
different values,
\hâ\n[lss]uâyou should probably use the
switch-statement.
\hâ\n[lss]uâDrawing and painting
\hâ\n[lss]uâYou
need to call open window before you may draw anything with
either line,
\hâ\n[lss]uâcircle, rectangle or triangle; all
of these statements may be decorated with
\hâ\n[lss]uâclear or fill. If you want to change
the colour for drawing, use colour. Note
\hâ\n[lss]uâhowever, that there can only be a
single window open at any given moment in
\hâ\n[lss]uâtime.
\hâ\n[lss]uâEverything
you have drawn can be send to your printer too, if you use
the open
\hâ\n[lss]uâprinter command.
\hâ\n[lss]uâTo
allow for some (very) limited version of animated graphics,
yabasic offers
\hâ\n[lss]uâthe commands getbit$ and putbit,
which retrieve rectangular regions from the
\hâ\n[lss]uâgraphics-window into a string or
vice versa.
\hâ\n[lss]uâIf you want to sense mouse-clicks, you may use the inkey$-function.
\hâ\n[lss]uâReading from and writing to files
\hâ\n[lss]uâBefore
you may read or write a file, you need to open it; once you
are done,
\hâ\n[lss]uâyou should close it. Each open file
is designated by a simple number, which
\hâ\n[lss]uâmight be stored within a variable
and must be supplied if you want to access
\hâ\n[lss]uâthe file. This is simply done by
putting a hash (â#â) followed by the number of
\hâ\n[lss]uâthe file after the keyword input
(for reading from) or print (for writing to a
\hâ\n[lss]uâfile) respectively.
\hâ\n[lss]uâIf
you need more control, you may consider reading and writing
one byte at a
\hâ\n[lss]uâtime, using the multi-purpose
commands peek and poke.
\hâ\n[lss]uâSubroutines and Libraries
\hâ\n[lss]uâThe
best way to break any yabasic-program into smaller, more
manageable chunks
\hâ\n[lss]uâare subroutines and libraries. They
are yabasicâs most advanced means of
\hâ\n[lss]uâstructuring a program.
\hâ\n[lss]uâSubroutines
are created with the command sub. they accept parameters and
may
\hâ\n[lss]uâreturn a value. Subroutines can be
called much like any builtin function of
\hâ\n[lss]uâyabasic; therefore they allow one to
extend the language itself.
\hâ\n[lss]uâOnce
you have created a set of related subroutines and you feel
that they could
\hâ\n[lss]uâbe useful in other programs too, you
may collect them into a library. Such a
\hâ\n[lss]uâlibrary is contained within a
separate file and may be included in any of your
\hâ\n[lss]uâprograms, using the keyword import,
which see.
\hâ\n[lss]uâString processing
\hâ\n[lss]uâyabasic
has a set of functions to extract parts from a string:
left$, mid$ and
\hâ\n[lss]uâright$. Note, that all of them can
be assigned to, i.e. they may change part of
\hâ\n[lss]uâa string.
\hâ\n[lss]uâIf
you want to split a string into tokens you should use the
functions token or
\hâ\n[lss]uâsplit.
\hâ\n[lss]uâSome
functions are handy for normalizing a string: upper$ and
lower$ convert a
\hâ\n[lss]uâstring to all upper or lower case
respectively, whereas chomp$ cuts of any
\hâ\n[lss]uâtrailing newline character, but only
if present.
\hâ\n[lss]uâchr$ and str$ convert a string into a number, both in different ways.
\hâ\n[lss]uâTo
analyze a string use instr (finding one string within the
other) or glob
\hâ\n[lss]uâ(testing a string against a simple
pattern).
\hâ\n[lss]uâTo concatenate strings use the operator + like in a$ + b$.
\hâ\n[lss]uâYou may also see the complete list of a string processing functions.
\hâ\n[lss]uâArithmetic and numbers
\hâ\n[lss]uâYabasic
handles numbers and arithmetic: You may calculate
trigonometric
\hâ\n[lss]uâfunctions like sin or atan, or
logarithms (with log). Bitwise operations, like
\hâ\n[lss]uâand or or are available as well min
or max (calculate the minimum or maximum of
\hâ\n[lss]uâits argument) or mod or int
(reminder of a division or integer part or a
\hâ\n[lss]uânumber).
\hâ\n[lss]uâConversion
between numerical bases can be done with hex$ and dec. And
you may
\hâ\n[lss]uâwrite hexadecimal constants in the
usual way, e.g.
\hâ\n[lss]uâprint 0xff
\hâ\n[lss]uâ. All calculations in yabasic are done with double precision.
\hâ\n[lss]uâData and such
\hâ\n[lss]uâYou
may store data within your program within data-statements;
during execution
\hâ\n[lss]uâyou will probably want to read it
into arrays, which must have been dimed
\hâ\n[lss]uâbefore.
\hâ\n[lss]uâOther interesting commands.
\hâ\n[lss]uâ*
Yabasic programs may start other programs with the commands
system and
\hâ\n[lss]uâsystem$.
\hâ\n[lss]uâ*
peek and poke allow one to get and set internal information;
either for the
\hâ\n[lss]uâoperating system (i.e. Unix or
Windows) or yabasic itself.
\hâ\n[lss]uâ*
The current time or date can be retrieved with (guess what
!) time$ and
\hâ\n[lss]uâdate$.
\hâ\n[lss]uâChapter 6. All commands and functions of yabasic listed by topic
\hâ\n[lss]uâNumber
processing and conversion
\hâ\n[lss]uâConditions and control structures
\hâ\n[lss]uâData keeping and processing
\hâ\n[lss]uâString processing
\hâ\n[lss]uâFile operations and printing
\hâ\n[lss]uâSubroutines and libraries
\hâ\n[lss]uâOther commands
\hâ\n[lss]uâGraphics and printing
\hâ\n[lss]uâNumber processing and conversion
\hâ\n[lss]uâabs()
\hâ\n[lss]uâreturns the absolute value of its
numeric argument
\hâ\n[lss]uâacos()
\hâ\n[lss]uâreturns the arcus cosine of its
numeric argument
\hâ\n[lss]uâand()
\hâ\n[lss]uâthe bitwise arithmetic and
\hâ\n[lss]uâasin()
\hâ\n[lss]uâreturns the arcus sine of its
numeric argument
\hâ\n[lss]uâatan()
\hâ\n[lss]uâreturns the arctangent of its
numeric argument
\hâ\n[lss]uâbin$()
\hâ\n[lss]uâconverts a number into a sequence of
binary digits
\hâ\n[lss]uâcos()
\hâ\n[lss]uâreturn the cosine of its single
argument
\hâ\n[lss]uâdec()
\hâ\n[lss]uâconvert a base 2 or base 16 number
into decimal form
\hâ\n[lss]uâeor()
\hâ\n[lss]uâcompute the bitwise exclusive or of
its two arguments
\hâ\n[lss]uâeuler
\hâ\n[lss]uâanother name for the constant
2.71828182864
\hâ\n[lss]uâexp()
\hâ\n[lss]uâcompute the exponential function of
its single argument
\hâ\n[lss]uâfrac()
\hâ\n[lss]uâreturn the fractional part of its
numeric argument
\hâ\n[lss]uâint()
\hâ\n[lss]uâreturn the integer part of its
single numeric argument
\hâ\n[lss]uâceil()
\hâ\n[lss]uâreturn the smallest integral number,
that is greater or equal than its
\hâ\n[lss]uâargument
\hâ\n[lss]uâfloor()
\hâ\n[lss]uâreturn the largest integral number,
that is smaller or equal than its
\hâ\n[lss]uâargument
\hâ\n[lss]uâlog()
\hâ\n[lss]uâcompute the natural logarithm
\hâ\n[lss]uâmax()
\hâ\n[lss]uâreturn the larger of its two
arguments
\hâ\n[lss]uâmin()
\hâ\n[lss]uâreturn the smaller of its two
arguments
\hâ\n[lss]uâmod
\hâ\n[lss]uâcompute the remainder of a division
\hâ\n[lss]uâor()
\hâ\n[lss]uâarithmetic or, used for
bit-operations
\hâ\n[lss]uâpi
\hâ\n[lss]uâa constant with the value 3.14159
\hâ\n[lss]uâran()
\hâ\n[lss]uâreturn a random number
\hâ\n[lss]uâsig()
\hâ\n[lss]uâreturn the sign of its argument
\hâ\n[lss]uâsin()
\hâ\n[lss]uâreturn the sine of its single
argument
\hâ\n[lss]uâsqr()
\hâ\n[lss]uâcompute the square of its argument
\hâ\n[lss]uâsqrt()
\hâ\n[lss]uâcompute the square root of its
argument
\hâ\n[lss]uâtan()
\hâ\n[lss]uâreturn the tangent of its argument
\hâ\n[lss]uâxor()
\hâ\n[lss]uâcompute the exclusive or
\hâ\n[lss]uâ** or Ë
\hâ\n[lss]uâraise its first argument to the
power of its second
\hâ\n[lss]uâConditions and control structures
\hâ\n[lss]uâand
\hâ\n[lss]uâlogical and, used in conditions
\hâ\n[lss]uâbreak
\hâ\n[lss]uâbreaks out of a switch statement or
a loop
\hâ\n[lss]uâcase
\hâ\n[lss]uâmark the different cases within a
switch-statement
\hâ\n[lss]uâcontinue
\hâ\n[lss]uâstart the next iteration of a for-,
do-, repeat- or while-loop
\hâ\n[lss]uâdefault
\hâ\n[lss]uâmark the default-branch within a
switch-statement
\hâ\n[lss]uâdo
\hâ\n[lss]uâstart a (conditionless) do-loop
\hâ\n[lss]uâelse
\hâ\n[lss]uâmark an alternative within an
if-statement
\hâ\n[lss]uâelsif
\hâ\n[lss]uâstarts an alternate condition within
an if-statement
\hâ\n[lss]uâend
\hâ\n[lss]uâterminate your program
\hâ\n[lss]uâendif
\hâ\n[lss]uâends an if-statement
\hâ\n[lss]uâfalse
\hâ\n[lss]uâa constant with the value of 0
\hâ\n[lss]uâfi
\hâ\n[lss]uâanother name for endif
\hâ\n[lss]uâfor
\hâ\n[lss]uâstarts a for-loop
\hâ\n[lss]uâgosub
\hâ\n[lss]uâcontinue execution at another point
within your program (and return later)
\hâ\n[lss]uâgoto
\hâ\n[lss]uâcontinue execution at another point
within your program (and never come
\hâ\n[lss]uâback)
\hâ\n[lss]uâif
\hâ\n[lss]uâevaluate a condition and execute
statements or not, depending on the result
\hâ\n[lss]uâlabel
\hâ\n[lss]uâmark a specific location within your
program for goto, gosub or restore
\hâ\n[lss]uâloop
\hâ\n[lss]uâmarks the end of an infinite loop
\hâ\n[lss]uânext
\hâ\n[lss]uâmark the end of a for loop
\hâ\n[lss]uânot
\hâ\n[lss]uânegate an expression; can be written
as !
\hâ\n[lss]uâon gosub
\hâ\n[lss]uâjump to one of multiple
gosub-targets
\hâ\n[lss]uâon goto
\hâ\n[lss]uâjump to one of many goto-targets
\hâ\n[lss]uâon interrupt
\hâ\n[lss]uâchange reaction on keyboard
interrupts
\hâ\n[lss]uâlogical or
\hâ\n[lss]uâlogical or, used in conditions
\hâ\n[lss]uâpause
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uârepeat
\hâ\n[lss]uâstart a repeat-loop
\hâ\n[lss]uâreturn
\hâ\n[lss]uâreturn from a subroutine or a gosub
\hâ\n[lss]uâsleep
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uâswitch
\hâ\n[lss]uâselect one of many alternatives
depending on a value
\hâ\n[lss]uâthen
\hâ\n[lss]uâtell the long from the short form of
the if-statement
\hâ\n[lss]uâtrue
\hâ\n[lss]uâa constant with the value of 1
\hâ\n[lss]uâuntil
\hâ\n[lss]uâend a repeat-loop
\hâ\n[lss]uâwait
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uâwend
\hâ\n[lss]uâend a while-loop
\hâ\n[lss]uâwhile
\hâ\n[lss]uâstart a while-loop
\hâ\n[lss]uâ:
\hâ\n[lss]uâseparate commands from each
other
\hâ\n[lss]uâData keeping and processing
\hâ\n[lss]uâarraydim()
\hâ\n[lss]uâreturns the dimension of the array,
which is passed as an array reference
\hâ\n[lss]uâarraysize()
\hâ\n[lss]uâreturns the size of a dimension of
an array
\hâ\n[lss]uâdata
\hâ\n[lss]uâintroduces a list of data-items
\hâ\n[lss]uâdim
\hâ\n[lss]uâcreate an array prior to its first
use
\hâ\n[lss]uâread
\hâ\n[lss]uâread data from data-statements
\hâ\n[lss]uâredim
\hâ\n[lss]uâcreate an array prior to its first
use. A synonym for dim
\hâ\n[lss]uârestore
\hâ\n[lss]uâreposition the data-pointer
\hâ\n[lss]uâString processing
\hâ\n[lss]uâasc()
\hâ\n[lss]uâaccepts a string and returns the
position of its first character within the
\hâ\n[lss]uâascii charset
\hâ\n[lss]uâchomp$()
\hâ\n[lss]uâChop of the trailing newline of its
string-argument; if the string does not
\hâ\n[lss]uâend in a newline, the string is
returned unchanged
\hâ\n[lss]uâchr$()
\hâ\n[lss]uâaccepts a number and returns the
character at this position within the
\hâ\n[lss]uâascii charset
\hâ\n[lss]uâglob()
\hâ\n[lss]uâcheck if a string matches a simple
pattern
\hâ\n[lss]uâhex$()
\hâ\n[lss]uâconvert a number into hexadecimal
\hâ\n[lss]uâinstr()
\hâ\n[lss]uâsearches its second argument within
the first; returns its position if
\hâ\n[lss]uâfound
\hâ\n[lss]uâleft$()
\hâ\n[lss]uâreturn (or change) left end of a
string
\hâ\n[lss]uâlen()
\hâ\n[lss]uâreturn the length of a string
\hâ\n[lss]uâlower$()
\hâ\n[lss]uâconvert a string to lower case
\hâ\n[lss]uâltrim$()
\hâ\n[lss]uâtrim spaces at the left end of a
string
\hâ\n[lss]uâmid$()
\hâ\n[lss]uâreturn (or change) characters from
within a string
\hâ\n[lss]uâright$()
\hâ\n[lss]uâreturn (or change) the right end of
a string
\hâ\n[lss]uâsplit()
\hâ\n[lss]uâsplit a string into many strings
\hâ\n[lss]uâstr$()
\hâ\n[lss]uâconvert a number into a string
\hâ\n[lss]uâtoken()
\hâ\n[lss]uâsplit a string into multiple strings
\hâ\n[lss]uâtrim$()
\hâ\n[lss]uâremove leading and trailing spaces
from its argument
\hâ\n[lss]uâupper$()
\hâ\n[lss]uâconvert a string to upper case
\hâ\n[lss]uâval()
\hâ\n[lss]uâconverts a string to a number
\hâ\n[lss]uâFile operations and printing
\hâ\n[lss]uâat()
\hâ\n[lss]uâcan be used in the print-command to
place the output at a specified
\hâ\n[lss]uâposition
\hâ\n[lss]uâbeep
\hâ\n[lss]uâring the bell within your computer;
a synonym for bell
\hâ\n[lss]uâbell
\hâ\n[lss]uâring the bell within your computer
(just as beep)
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâerases the text window
\hâ\n[lss]uâclose
\hâ\n[lss]uâclose a file, which has been opened
before
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâstops printing of graphics
\hâ\n[lss]uâprint color
\hâ\n[lss]uâprint with color
\hâ\n[lss]uâprint colour
\hâ\n[lss]uâsee print color
\hâ\n[lss]uâeof
\hâ\n[lss]uâcheck, if an open file contains data
\hâ\n[lss]uâgetscreen$()
\hâ\n[lss]uâreturns a string representing a
rectangular section of the text terminal
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâwait, until a key is pressed
\hâ\n[lss]uâinput
\hâ\n[lss]uâread input from the user (or from a
file) and assign it to a variable
\hâ\n[lss]uâline input
\hâ\n[lss]uâread in a whole line of text and
assign it to a variable
\hâ\n[lss]uâopen
\hâ\n[lss]uâopen a file
\hâ\n[lss]uâopen printer
\hâ\n[lss]uâopen printer for printing graphics
\hâ\n[lss]uâprint
\hâ\n[lss]uâWrite to terminal or file
\hâ\n[lss]uâputscreen
\hâ\n[lss]uâdraw a rectangle of characters into
the text terminal
\hâ\n[lss]uâreverse
\hâ\n[lss]uâprint reverse (background and
foreground colors exchanged)
\hâ\n[lss]uâscreen
\hâ\n[lss]uâas clear screen clears the text
window
\hâ\n[lss]uâseek()
\hâ\n[lss]uâchange the position within an open
file
\hâ\n[lss]uâtell
\hâ\n[lss]uâget the current position within an
open file
\hâ\n[lss]uâusing
\hâ\n[lss]uâSpecify the format for printing a
number
\hâ\n[lss]uâ#
\hâ\n[lss]uâeither a comment or a marker for a
file-number
\hâ\n[lss]uâ@
\hâ\n[lss]uâsynonymous to at
\hâ\n[lss]uâ;
\hâ\n[lss]uâsuppress the implicit newline after
a print-statement
\hâ\n[lss]uâSubroutines and libraries
\hâ\n[lss]uâend
sub
\hâ\n[lss]uâends a subroutine definition
\hâ\n[lss]uâexport
\hâ\n[lss]uâmark a function as globally visible
\hâ\n[lss]uâimport
\hâ\n[lss]uâimport a library
\hâ\n[lss]uâlocal
\hâ\n[lss]uâmark a variable as local to a
subroutine
\hâ\n[lss]uânumparams
\hâ\n[lss]uâreturn the number of parameters,
that have been passed to a subroutine
\hâ\n[lss]uâreturn
\hâ\n[lss]uâreturn from a subroutine or a gosub
\hâ\n[lss]uâstatic
\hâ\n[lss]uâpreserves the value of a variable
between calls to a subroutine
\hâ\n[lss]uâstep
\hâ\n[lss]uâspecifies the increment step in a
for-loop
\hâ\n[lss]uâsub
\hâ\n[lss]uâdeclare a user defined
subroutine
\hâ\n[lss]uâOther commands
\hâ\n[lss]uâbind()
\hâ\n[lss]uâBinds a yabasic-program and the
yabasic-interpreter together into a
\hâ\n[lss]uâstandalone program.
\hâ\n[lss]uâcompile
\hâ\n[lss]uâcompile a string with yabasic-code
on the fly
\hâ\n[lss]uâdate$
\hâ\n[lss]uâreturns a string with various
components of the current date
\hâ\n[lss]uâdoc
\hâ\n[lss]uâspecial comment, which might be
retrieved by the program itself
\hâ\n[lss]uâdocu$
\hâ\n[lss]uâspecial array, containing the
contents of all docu-statement within the
\hâ\n[lss]uâprogram
\hâ\n[lss]uâerror
\hâ\n[lss]uâraise an error and terminate your
program
\hâ\n[lss]uâexecute$()
\hâ\n[lss]uâexecute a user defined subroutine,
which must return a string
\hâ\n[lss]uâexecute()
\hâ\n[lss]uâexecute a user defined subroutine,
which must return a number
\hâ\n[lss]uâexit
\hâ\n[lss]uâterminate your program
\hâ\n[lss]uâpause
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uâpeek
\hâ\n[lss]uâretrieve various internal
information
\hâ\n[lss]uâpeek$
\hâ\n[lss]uâretrieve various internal
string-information
\hâ\n[lss]uâpoke
\hâ\n[lss]uâchange selected internals of yabasic
\hâ\n[lss]uârem
\hâ\n[lss]uâstart a comment
\hâ\n[lss]uâsleep
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uâsystem()
\hâ\n[lss]uâhand a statement over to your
operating system and return its exitcode
\hâ\n[lss]uâsystem$()
\hâ\n[lss]uâhand a statement over to your
operating system and return its output
\hâ\n[lss]uâtime$
\hâ\n[lss]uâreturn a string containing the
current time
\hâ\n[lss]uâto
\hâ\n[lss]uâthis keyword appears as part of
other statements
\hâ\n[lss]uâwait
\hâ\n[lss]uâpause, sleep, wait for the specified
number of seconds
\hâ\n[lss]uâ//
\hâ\n[lss]uâstarts a comment
\hâ\n[lss]uâ:
\hâ\n[lss]uâseparate commands from each
other
\hâ\n[lss]uâGraphics and printing
\hâ\n[lss]uâbackcolor
\hâ\n[lss]uâspecify the colour for subsequent
drawing of the background
\hâ\n[lss]uâbox
\hâ\n[lss]uâdraw a rectangle. A synonym for
rectangle
\hâ\n[lss]uâcircle
\hâ\n[lss]uâdraws a circle in the graphic-window
\hâ\n[lss]uâclear
\hâ\n[lss]uâErase circles, rectangles or
triangless
\hâ\n[lss]uâclear window
\hâ\n[lss]uâclear the graphic window and begin a
new page, if printing is under way
\hâ\n[lss]uâclose curve
\hâ\n[lss]uâclose a curve, that has been drawn
by the line-command
\hâ\n[lss]uâclose window
\hâ\n[lss]uâclose the graphics-window
\hâ\n[lss]uâcolour
\hâ\n[lss]uâspecify the colour for subsequent
drawing
\hâ\n[lss]uâdot
\hâ\n[lss]uâdraw a dot in the graphic-window
\hâ\n[lss]uâfill
\hâ\n[lss]uâdraw a filled circles, rectangles or
triangles
\hâ\n[lss]uâgetbit$()
\hâ\n[lss]uâreturn a string representing the bit
pattern of a rectangle within the
\hâ\n[lss]uâgraphic window
\hâ\n[lss]uâline
\hâ\n[lss]uâdraw a line
\hâ\n[lss]uâmouseb
\hâ\n[lss]uâextract the state of the
mousebuttons from a string returned by inkey$
\hâ\n[lss]uâmousemod
\hâ\n[lss]uâreturn the state of the modifier
keys during a mouseclick
\hâ\n[lss]uâmousex
\hâ\n[lss]uâreturn the x-position of a
mouseclick
\hâ\n[lss]uâmousey
\hâ\n[lss]uâreturn the y-position of a
mouseclick
\hâ\n[lss]uânew curve
\hâ\n[lss]uâstart a new curve, that will be
drawn with the line-command
\hâ\n[lss]uâopen window
\hâ\n[lss]uâopen a graphic window
\hâ\n[lss]uâputbit
\hâ\n[lss]uâdraw a rectangle of pixels into the
graphic window
\hâ\n[lss]uârectangle
\hâ\n[lss]uâdraw a rectangle
\hâ\n[lss]uâtriangle
\hâ\n[lss]uâdraw a triangle
\hâ\n[lss]uâtext
\hâ\n[lss]uâwrite text into your graphic-window
\hâ\n[lss]uâwindow origin
\hâ\n[lss]uâmove the origin of a window
\hâ\n[lss]uâChapter 7. All commands and functions of yabasic grouped alphabetically
\hâ\n[lss]uâA
\hâ\n[lss]uâB
\hâ\n[lss]uâC
\hâ\n[lss]uâD
\hâ\n[lss]uâE
\hâ\n[lss]uâF
\hâ\n[lss]uâG
\hâ\n[lss]uâH
\hâ\n[lss]uâI
\hâ\n[lss]uâL
\hâ\n[lss]uâM
\hâ\n[lss]uâN
\hâ\n[lss]uâO
\hâ\n[lss]uâP
\hâ\n[lss]uâR
\hâ\n[lss]uâS
\hâ\n[lss]uâT
\hâ\n[lss]uâU
\hâ\n[lss]uâV
\hâ\n[lss]uâW
\hâ\n[lss]uâX
\hâ\n[lss]uâSpecial characters
\hâ\n[lss]uâReserved Words
\hâ\n[lss]uâA
\hâ\n[lss]uâabs()
? returns the absolute value of its numeric argument
\hâ\n[lss]uâacos() ? returns the arcus cosine of
its numeric argument
\hâ\n[lss]uâand ? logical and, used in
conditions
\hâ\n[lss]uâand() ? the bitwise arithmetic and
\hâ\n[lss]uâarraydim() ? returns the dimension
of the array, which is passed as an array
\hâ\n[lss]uâreference
\hâ\n[lss]uâarraysize() ? returns the size of a
dimension of an array
\hâ\n[lss]uâasc() ? accepts a string and returns
the position of its first character within
\hâ\n[lss]uâthe ascii charset
\hâ\n[lss]uâasin() ? returns the arcus sine of
its numeric argument
\hâ\n[lss]uâat() ? can be used in the
print-command to place the output at a specified
\hâ\n[lss]uâposition
\hâ\n[lss]uâatan() ? returns the arctangent of
its numeric argument
\hâ\n[lss]uâName
\hâ\n[lss]uâabs() ? returns the absolute value of its numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uây=abs(x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâIf
the argument of the abs-function is positive (e.g. 2) it is
returned
\hâ\n[lss]uâunchanged, if the argument is
negative (e.g. -1) it is returned as a positive
\hâ\n[lss]uâvalue (e.g. 1).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint abs(-2),abs(2)
\hâ\n[lss]uâThis example will print 2 2
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsig
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâacos() ? returns the arcus cosine of its numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=acos(angle)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâacos
is the arcus cosine-function, i.e. the inverse of the
cos-function. Or,
\hâ\n[lss]uâmore elaborate: It Returns the angle
(in radians, not degrees !), which, fed to
\hâ\n[lss]uâthe cosine-function will produce the
argument passed to the acos-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint acos(0.5),acos(cos(pi))
\hâ\n[lss]uâThis example will print 1.0472 3.14159 which are ?/3 and ? respectively.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcos, asin
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâand ? logical and, used in conditions
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(a and b) ?
\hâ\n[lss]uâwhile (a and b) ?
\hâ\n[lss]uâDescription
\hâ\n[lss]uâUsed
in conditions (e.g within if, while or until) to join two
expressions.
\hâ\n[lss]uâReturns true, if and only if its
left and right argument are both true and
\hâ\n[lss]uâfalse otherwise.
\hâ\n[lss]uâNote, that logical shortcuts may take place.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number" a
\hâ\n[lss]uâif (a>=1 and a<=9) print
"your input is between 1 and 9"
\hâ\n[lss]uâSee also
\hâ\n[lss]uâor,not
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâand() ? the bitwise arithmetic and
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=and(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâUsed
to compute the bitwise and of both its argument. Both
arguments are
\hâ\n[lss]uâtreated as binary numbers (i.e. a
series of 0 and 1); a bit of the resulting
\hâ\n[lss]uâvalue will then be 1, if both
arguments have a 1 at this position in their
\hâ\n[lss]uâbinary representation.
\hâ\n[lss]uâNote,
that both arguments are silently converted to integer values
and that
\hâ\n[lss]uânegative numbers have their own
binary representation and may lead to
\hâ\n[lss]uâunexpected results when passed to
and.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint and(6,3)
\hâ\n[lss]uâThis
will print 2. This result is clear, if you note, that the
binary
\hâ\n[lss]uârepresentation of 6 and 3 are 110
and 011 respectively; this will yield 010 in
\hâ\n[lss]uâbinary representation or 2 as
decimal.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâor, eor and not
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâarraydim()
? returns the dimension of the array, which is passed as an
array
\hâ\n[lss]uâreference
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=arraydim(b())
\hâ\n[lss]uâDescription
\hâ\n[lss]uâIf
you apply the arraydim()-function on a one-dimensional array
(i.e. a vector)
\hâ\n[lss]uâit will return 1, on a
two-dimensional array (i.e. a matrix) it will return 2,
\hâ\n[lss]uâand so on.
\hâ\n[lss]uâThis
is mostly used within subroutines, which expect an array
among their
\hâ\n[lss]uâparameters. Such subroutines tend to
use the arraydim-function to check, if the
\hâ\n[lss]uâarray which has been passed, has the
right dimension. E.g. a subroutine to
\hâ\n[lss]uâmultiply two matrices may want to
check, if it really is invoked with two
\hâ\n[lss]uâ2-dimensional arrays.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdim
a(10,10),b(10)
\hâ\n[lss]uâprint
arraydim(a()),arraydim(b())
\hâ\n[lss]uâThis
will print 2 1, which are the dimension of the arrays a()
and b(). You may
\hâ\n[lss]uâcheck out the function arraysize for
a full-fledged example.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâarraysize and dim.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâarraysize() ? returns the size of a dimension of an array
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=arraysize(a(),b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
arraysize-function computes the size of a specified
dimension of a
\hâ\n[lss]uâspecified array. Here, size stands
for the maximum number, that may be used as
\hâ\n[lss]uâan index for this array. The first
argument to this function must be an
\hâ\n[lss]uâreference to an array, the second
one specifies, which of the multiple
\hâ\n[lss]uâdimensions of the array should be
taken to calculate the size.
\hâ\n[lss]uâAn
Example involving subroutines: Letâs say, an array has
been declared as dim
\hâ\n[lss]uâa(10,20) (that is a two-dimensional
array or a matrix). If this array is passed
\hâ\n[lss]uâas an array reference to a
subroutine, this sub will not know, what sort of
\hâ\n[lss]uâarray has been passed. With the
arraydim-function the sub will be able to find
\hâ\n[lss]uâthe dimension of the array, with the
arraysize-function it will be able to find
\hâ\n[lss]uâout the size of this array in its
two dimensions, which will be 10 and 20
\hâ\n[lss]uârespectively.
\hâ\n[lss]uâOur
sample array is two dimensional; if you envision it as a
matrix this matrix
\hâ\n[lss]uâhas 10 lines and 20 columns (see the
dim-statement above. To state it more
\hâ\n[lss]uâformally: The first dimension
(lines) has a size of 10, the second dimension
\hâ\n[lss]uâ(columns) has a size of 20; these
numbers are those returned by arraysize(a
\hâ\n[lss]uâ(),1) and arraysize(a(),2)
respectively. Refer to the example below for a
\hâ\n[lss]uâtypical usage.
\hâ\n[lss]uâExample
\hâ\n[lss]uârem
\hâ\n[lss]uârem This program adds two matrices
elementwise.
\hâ\n[lss]uârem
\hâ\n[lss]uâdim a(10,20),b(10,20),c(10,20)
\hâ\n[lss]uârem
initialization of the arrays a() and b()
\hâ\n[lss]uâfor y=1 to 10:for x=1 to 20
\hâ\n[lss]uâa(y,x)=int(ran(4)):b(y,x)=int(ran(4))
\hâ\n[lss]uânext x:next y
\hâ\n[lss]uâmatadd(a(),b(),c())
\hâ\n[lss]uâprint
"Result:"
\hâ\n[lss]uâfor x=1 to 20
\hâ\n[lss]uâfor y=10 to 1 step -1
\hâ\n[lss]uâprint c(y,x)," ";
\hâ\n[lss]uânext y
\hâ\n[lss]uâprint
\hâ\n[lss]uânext x
\hâ\n[lss]uâsub matadd(m1(),m2(),r())
\hâ\n[lss]uârem
This sub will add the matrices m1() and m2()
\hâ\n[lss]uârem elementwise and store the result
within r()
\hâ\n[lss]uârem This is not very useful but easy
to implement.
\hâ\n[lss]uârem However, this sub excels in
checking its arguments
\hâ\n[lss]uârem with arraydim() and
arraysize()
\hâ\n[lss]uâlocal x:local y
\hâ\n[lss]uâif
(arraydim(m1())<>2 or arraydim(m2())<>2 or
arraydim(r())<>2) then
\hâ\n[lss]uâerror "Need two dimensional
arrays as input"
\hâ\n[lss]uâendif
\hâ\n[lss]uây=arraysize(m1(),1):x=arraysize(m1(),2)
\hâ\n[lss]uâif (arraysize(m2(),1)<>y or
arraysize(m2(),2)<>x) then
\hâ\n[lss]uâerror "The two matrices cannot
be added elementwise"
\hâ\n[lss]uâendif
\hâ\n[lss]uâif
(arraysize(r(),1)<>y or arraysize(r(),2)<>x)
then
\hâ\n[lss]uâerror "The result cannot be
stored in the third argument"
\hâ\n[lss]uâendif
\hâ\n[lss]uâlocal
xx:local yy
\hâ\n[lss]uâfor xx=1 to x
\hâ\n[lss]uâfor yy=1 to y
\hâ\n[lss]uâr(yy,xx)=m1(yy,xx)+m2(yy,xx)
\hâ\n[lss]uânext yy
\hâ\n[lss]uânext xx
\hâ\n[lss]uâend sub
\hâ\n[lss]uâSee also
\hâ\n[lss]uâarraydim and dim.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâasc()
? accepts a string and returns the position of its first
character within
\hâ\n[lss]uâthe ascii charset
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=asc(char$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
asc-function accepts a string, takes its first character and
looks it up
\hâ\n[lss]uâwithin the ascii-charset; this
position will be returned. The asc-function is
\hâ\n[lss]uâthe opposite of the chr$-function.
There are valid uses for asc, however,
\hâ\n[lss]uâcomparing strings (i.e. to bring
them into alphabetical sequence) is not among
\hâ\n[lss]uâthem; in such many cases you might
consider to compare strings directly with <,
\hâ\n[lss]uâ= and > (rather than converting a
string to a number and comparing this
\hâ\n[lss]uânumber).
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a letter between âaâ and
âyâ: " a$
\hâ\n[lss]uâif (a$<"a" or
a$>"y") print a$," is not in the proper
range":end
\hâ\n[lss]uâprint "The letter after
",a$," is ",chr$(asc(a$)+1)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâchr$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâasin() ? returns the arcus sine of its numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâangle=asin(x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâacos
is the arcus sine-function, i.e. the inverse of the
sin-function. Or, more
\hâ\n[lss]uâelaborate: It Returns the angle (in
radians, not degrees !), which, fed to the
\hâ\n[lss]uâsine-function will produce the
argument passed to the asin-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint asin(0.5),asin(sin(pi))
\hâ\n[lss]uâThis will print 0.523599 -2.06823e-13 which is ? and almost 0 respectively.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsin, acos
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâat()
? can be used in the print-command to place the output at a
specified
\hâ\n[lss]uâposition
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâ?
\hâ\n[lss]uâprint at(a,b)
\hâ\n[lss]uâprint @(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
at-clause takes two numeric arguments (e.g. at(2,3)) and can
be inserted
\hâ\n[lss]uâafter the print-keyword. at() can be
used only if clear screen has been
\hâ\n[lss]uâexecuted at least once within the
program (otherwise you will get an error).
\hâ\n[lss]uâThe
two numeric arguments of the at-function may range from 0 to
the width of
\hâ\n[lss]uâyour terminal minus 1, and from 0 to
the height of your terminal minus 1; if
\hâ\n[lss]uâany argument exceeds these values,
it will be truncated accordingly. However,
\hâ\n[lss]uâyabasic has no influence on the size
of your terminal (80x25 is a common, but
\hâ\n[lss]uânot mandatory), the size of your
terminal and the maximum values acceptable
\hâ\n[lss]uâwithin the at-clause may vary. To
get the size of your terminal you may use the
\hâ\n[lss]uâpeek-function:
peek("screenwidth") returns the width of your
terminal and peek
\hâ\n[lss]uâ("screenheight") its
height.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâmaxx=peek("screenwidth")-1:maxy=peek("screenheight")-1
\hâ\n[lss]uâfor x=0 to maxx
\hâ\n[lss]uâprint
at(x,maxy*(0.5+sin(2*pi*x/maxx)/2)) "*"
\hâ\n[lss]uânext x
\hâ\n[lss]uâThis example plots a full period of the sine-function across the screen.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâprint, clear screen, color
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâatan() ? returns the arctangent of its numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâangle=atan(a,b)
\hâ\n[lss]uâangle=atan(a)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâatan
is the arctangent-function, i.e. the inverse of the
tan-function. Or, more
\hâ\n[lss]uâelaborate: It Returns the angle (in
radians, not degrees !), which, fed to the
\hâ\n[lss]uâtan-function will produce the
argument passed to the atan-function.
\hâ\n[lss]uâThe
atan-function has a second form, which accepts two
arguments: atan(a,b)
\hâ\n[lss]uâwhich is (mostly) equivalent to
atan(a/b) except for the fact, that the
\hâ\n[lss]uâtwo-argument-form returns an angle
in the range -? to ?, whereas the
\hâ\n[lss]uâone-argument-form returns an angle
in the range -?/2 to ?/2. To understand this
\hâ\n[lss]uâyou have to be good at math.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint atan(1),atan(tan(pi)),atan(-0,-1),atan(-0,1)
\hâ\n[lss]uâThis
will print 0.463648 2.06823e-13 -3.14159 3.14159 which is
?/4, almost 0,
\hâ\n[lss]uâ-? and ? respectively.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtan, sin
\hâ\n[lss]uâB
\hâ\n[lss]uâbackcolor
? change color for background of graphic window
\hâ\n[lss]uâbackcolour ? see backcolor
\hâ\n[lss]uâbeep ? ring the bell within your
computer; a synonym for bell
\hâ\n[lss]uâbell ? ring the bell within your
computer (just as beep)
\hâ\n[lss]uâbin$() ? converts a number into a
sequence of binary digits
\hâ\n[lss]uâbind() ? Binds a yabasic-program and
the yabasic-interpreter together into a
\hâ\n[lss]uâstandalone program.
\hâ\n[lss]uâbox ? draw a rectangle. A synonym
for rectangle
\hâ\n[lss]uâbreak ? breaks out of one or more
loops or switch statements
\hâ\n[lss]uâName
\hâ\n[lss]uâcolor ? change color for background of graphic window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbackcolour
red,green,blue
\hâ\n[lss]uâbackcolour
"red,green,blue"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâChange
the color, that becomes visible, if any portion of the
window is erased,
\hâ\n[lss]uâe.g. after clear window or clear
line. Note however, that parts of the window,
\hâ\n[lss]uâthat display the old background
color will not change.
\hâ\n[lss]uâAs
with the color-command, the new background color can either
be specified as
\hâ\n[lss]uâa triple of three numbers or as a
single string, that contains those three
\hâ\n[lss]uânumbers separated by commas.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 255,255
\hâ\n[lss]uâfor x=10 to 235 step 10:for y=10 to
235 step 10
\hâ\n[lss]uâbackcolour x,y,0
\hâ\n[lss]uâclear window
\hâ\n[lss]uâsleep 1
\hâ\n[lss]uânext y:next x
\hâ\n[lss]uâThis
changes the background colour of the graphic window
repeatedly and clears
\hâ\n[lss]uâit every time, so that it is filled
with the new background colour.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, color, line, rectangle, triangle, circle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbackcolour ? see backcolor
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbackcolour
red,green,blue
\hâ\n[lss]uâbackcolour
"red,green,blue"
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcolor
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbeep ? ring the bell within your computer; a synonym for bell
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbeep
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
bell-command rings the bell within your computer once. This
command is not
\hâ\n[lss]uâa sound-interface, so you can
neither vary the length or the height of the
\hâ\n[lss]uâsound (technically, it just prints
\a). bell is exactly the same as beep.
\hâ\n[lss]uâExample
\hâ\n[lss]uâbeep:print "This is a problem ..."
\hâ\n[lss]uâSee also
\hâ\n[lss]uâbeep
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbell ? ring the bell within your computer (just as beep)
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbell
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
beep-command rings the bell within your computer once. beep
is a synonym
\hâ\n[lss]uâfor bell.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint "This is a problem ...":beep
\hâ\n[lss]uâSee also
\hâ\n[lss]uâbell
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbin$() ? converts a number into a sequence of binary digits
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâhexadecimal$=bin$(decimal)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
bin$-function takes a single numeric argument an converts it
into a string
\hâ\n[lss]uâof binary digits (i.e. zeroes and
ones). If you pass a negative number to bin$,
\hâ\n[lss]uâthe resulting string will be
preceded by a â-â.
\hâ\n[lss]uâIf
you want to convert the other way around (i.e. from binary
to decimal) you
\hâ\n[lss]uâmay use the dec-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 100
\hâ\n[lss]uâprint bin$(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis example prints the binary representation of all digits between 1 and 100.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâhex$, dec
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbind()
? Binds a yabasic-program and the yabasic-interpreter
together into a
\hâ\n[lss]uâstandalone program.
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbind("foo.exe")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
bind-command combines your own yabasic-program (plus all the
libraries it
\hâ\n[lss]uâdoes import) and the interpreter by
copying them into a new file, whose name is
\hâ\n[lss]uâpassed as an argument. This new
program may then be executed on any computer,
\hâ\n[lss]uâeven if it does not have yabasic
installed.
\hâ\n[lss]uâPlease see the section about creating a standalone-program for details.
\hâ\n[lss]uâExample
\hâ\n[lss]uâif
(!peek("isbound")) then
\hâ\n[lss]uâbind "foo"
\hâ\n[lss]uâprint "Successfully created the
standalone executable âfooâ !"
\hâ\n[lss]uâexit
\hâ\n[lss]uâendif
\hâ\n[lss]uâprint "Hello World !"
\hâ\n[lss]uâThis example creates a standalone program foo from itself.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâThe
section about creating a standalone-program, the
peek-function and the
\hâ\n[lss]uâcommand line options.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbox ? draw a rectangle. A synonym for rectangle
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâSee the rectangle-command.
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
box-command does exactly the same as the rectangle-command;
it is just a
\hâ\n[lss]uâsynonym. Therefore you should refer
to the entry for the rectangle-command for
\hâ\n[lss]uâfurther information.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâbreak ? breaks out of one or more loops or switch statements
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâbreak
\hâ\n[lss]uâbreak 2
\hâ\n[lss]uâDescription
\hâ\n[lss]uâbreak
transfers control immediately outside the enclosing loop or
switch
\hâ\n[lss]uâstatement. This is the preferred way
of leaving a such a statement (rather than
\hâ\n[lss]uâgoto, which is still possible in
most cases). An optional digit allows one to
\hâ\n[lss]uâbreak out of multiple levels, e.g.
to leave a loop from within a switch
\hâ\n[lss]uâstatement. Please note, that only a
literal (e.g. 2) is allowed at this
\hâ\n[lss]uâlocation.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâbreak
\hâ\n[lss]uâprint "Hi"
\hâ\n[lss]uânext a
\hâ\n[lss]uâwhile(1)
\hâ\n[lss]uâbreak
\hâ\n[lss]uâprint "Hi"
\hâ\n[lss]uâwend
\hâ\n[lss]uârepeat
\hâ\n[lss]uâbreak
\hâ\n[lss]uâprint "Hi"
\hâ\n[lss]uâuntil(0)
\hâ\n[lss]uâswitch
1
\hâ\n[lss]uâcase 1:break
\hâ\n[lss]uâcase 2:case 3:print "Hi"
\hâ\n[lss]uâend switch
\hâ\n[lss]uâThis
example prints nothing at all, because each of the loops
(and the
\hâ\n[lss]uâswitch-statement) does an immediate
break (before it could print any "Hi").
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfor, while, repeat and switch.
\hâ\n[lss]uâC
\hâ\n[lss]uâcase
? mark the different cases within a switch-statement
\hâ\n[lss]uâceil() ? compute the ceiling for its
(float) argument.
\hâ\n[lss]uâchomp$() ? Remove a single trailing
newline from its string-argument; if the
\hâ\n[lss]uâstring does not end in a newline,
the string is returned unchanged.
\hâ\n[lss]uâchr$() ? accepts a number and
returns the character at this position within the
\hâ\n[lss]uâascii charset
\hâ\n[lss]uâcircle ? draws a circle in the
graphic-window
\hâ\n[lss]uâclear ? Erase circles, rectangles or
triangles
\hâ\n[lss]uâclear screen ? erases the text
window
\hâ\n[lss]uâclear window ? clear the graphic
window and begin a new page, if printing is
\hâ\n[lss]uâunder way
\hâ\n[lss]uâclose ? close a file, which has been
opened before
\hâ\n[lss]uâclose curve ? close a curve, that
has been drawn by the line-command
\hâ\n[lss]uâclose printer ? stops printing of
graphics
\hâ\n[lss]uâclose window ? close the
graphics-window
\hâ\n[lss]uâcolor ? change color for any
subsequent drawing-command
\hâ\n[lss]uâcolour ? see color
\hâ\n[lss]uâcompile ? compile a string with
yabasic-code on the fly
\hâ\n[lss]uâcontinue ? start the next iteration
of a for-, do-, repeat- or while-loop
\hâ\n[lss]uâcos() ? return the cosine of its
single argument
\hâ\n[lss]uâName
\hâ\n[lss]uâcase ? mark the different cases within a switch-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâswitch
a
\hâ\n[lss]uâcase 1
\hâ\n[lss]uâcase 2
\hâ\n[lss]uâ?
\hâ\n[lss]uâend switch
\hâ\n[lss]uâ?
\hâ\n[lss]uâswitch
a$
\hâ\n[lss]uâcase "a"
\hâ\n[lss]uâcase "b"
\hâ\n[lss]uâ?
\hâ\n[lss]uâend switch
\hâ\n[lss]uâDescription
\hâ\n[lss]uâPlease see the switch-statement.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
a
\hâ\n[lss]uâswitch(a)
\hâ\n[lss]uâcase 1:print "one":break
\hâ\n[lss]uâcase 2:print "two":break
\hâ\n[lss]uâdefault:print "more"
\hâ\n[lss]uâend switch
\hâ\n[lss]uâDepending
on your input (a number is expected) this code will print
one or two
\hâ\n[lss]uâor otherwise more.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâswitch
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâceil() ? compute the ceiling for its (float) argument.
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint ceil(x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
ceil-function returns the smallest integer number, that is
larger or equal
\hâ\n[lss]uâthan its argument.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
ceil(1.5),floor(1.5)
\hâ\n[lss]uâprint ceil(2),floor(2)
\hâ\n[lss]uâComparing
functions ceil and floor, gives a first line of output (1
2), showing
\hâ\n[lss]uâthat ceil is less or equal than
floor; but as the second line of output (2 2)
\hâ\n[lss]uâshows, the two functions give equal
results for integer arguments.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfloor, int, frac
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâchomp$()
? Remove a single trailing newline from its string-argument;
if the
\hâ\n[lss]uâstring does not end in a newline,
the string is returned unchanged.
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint chomp$("Hallo !\n")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
chomp$-function checks, if its string-argument ends in a
newline and
\hâ\n[lss]uâremoves it eventually; for this
purpose chomp$ can replace an if-statement.
\hâ\n[lss]uâThis can be especially useful, when
you deal with input from external sources
\hâ\n[lss]uâlike system$.
\hâ\n[lss]uâYou
may apply chomp$ freely, as it only acts, if there is a
newline to remove;
\hâ\n[lss]uânote however, that user-input, that
comes from the normal input-statement, does
\hâ\n[lss]uânot need such a treatment, because
it already comes without a newline.
\hâ\n[lss]uâExample
\hâ\n[lss]uâThe
following yabasic-program uses the unix-command whoami to
get the username
\hâ\n[lss]uâof the current user in order to
greet him personally. This is done twice: First
\hâ\n[lss]uâwith the chomp$-function and then
again with with an equivalent if-statement:
\hâ\n[lss]uâprint "Hello " + chomp$(system$("whoami")) + " !"
\hâ\n[lss]uâuser$
= system$("whoami")
\hâ\n[lss]uâif (right$(user$,1)="\n")
user$=left$(user$,len(user$)-1)
\hâ\n[lss]uâprint "Hello again " +
user$ + " !"
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsystem$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâchr$()
? accepts a number and returns the character at this
position within the
\hâ\n[lss]uâascii charset
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcharacter$=chr$(ascii)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
chr$-function is the opposite of the asc-function. It looks
up and returns
\hâ\n[lss]uâthe character at the given position
within the ascii-charset. Itâs typical use
\hâ\n[lss]uâis to construct nonprintable
characters which do not occur on your keyboard.
\hâ\n[lss]uâNevertheless
you wonât use chr$ as often as you might think,
because the most
\hâ\n[lss]uâimportant nonprintable characters
can be constructed using escape-sequences
\hâ\n[lss]uâusing the \-character (e.g. you
might use \n instead of chr$(10) wherever you
\hâ\n[lss]uâwant to use the
newline-character).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint "a",chr$(10),"b"
\hâ\n[lss]uâThis
will print the letters âaâ and âbâ
in different lines because of the
\hâ\n[lss]uâintervening newline-character, which
is returned by chr$(10).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâasc
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcircle ? draws a circle in the graphic-window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcircle
x,y,r
\hâ\n[lss]uâclear circle x,y,r
\hâ\n[lss]uâfill circle x,y,r
\hâ\n[lss]uâclear fill circle x,y,r
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
circle-command accepts three parameters: The x- and
y-coordinates of the
\hâ\n[lss]uâcenter and the radius of the
circle.
\hâ\n[lss]uâSome more observations related with the circle-command:
\hâ\n[lss]uâ* The graphic-window must have been opened already.
\hâ\n[lss]uâ* The circle may well extend over the boundaries of the window.
\hâ\n[lss]uâ*
If you have issued open printer before, the circle will
finally appear in
\hâ\n[lss]uâthe printed hard copy of the
window.
\hâ\n[lss]uâ* fill circle will draw a filled (with black ink) circle.
\hâ\n[lss]uâ* clear circle will erase (or clear) the outline of the circle.
\hâ\n[lss]uâ*
clear fill circle or fill clear circle will erase the full
area of the
\hâ\n[lss]uâcircle.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen window 200,200
\hâ\n[lss]uâfor
n=1 to 2000
\hâ\n[lss]uâx=ran(200)
\hâ\n[lss]uây=ran(200)
\hâ\n[lss]uâfill circle x,y,10
\hâ\n[lss]uâclear fill circle x,y,8
\hâ\n[lss]uânext n
\hâ\n[lss]uâThis
code will open a window and draw 2000 overlapping circles
within. Each
\hâ\n[lss]uâcircle is drawn in two steps: First
it is filled with black ink (fill circle
\hâ\n[lss]uâx,y,10), then most of this circle is
erased again (clear fill circle x,y,8). As
\hâ\n[lss]uâa result each circle is drawn with
an opaque white interior and a 2-pixel
\hâ\n[lss]uâoutline (2-pixel, because the radii
differ by two).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, open printer, line, rectangle, triangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclear ? Erase circles, rectangles or triangles
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
rectangle 10,10,90,90
\hâ\n[lss]uâclear fill circle 50,50,20
\hâ\n[lss]uâclear triangle 10,10,20,20,50,30
\hâ\n[lss]uâDescription
\hâ\n[lss]uâMay
be used within the circle, rectangle or triangle command and
causes these
\hâ\n[lss]uâshapes to be erased (i.e. be drawn
in the colour of the background).
\hâ\n[lss]uâfill
can be used in conjunction with and wherever the fill-clause
may appear.
\hâ\n[lss]uâUsed alone, clear will erase the
outline (not the interior) of the shape
\hâ\n[lss]uâ(circle, rectangle or triangle);
together with fill the whole shape (including
\hâ\n[lss]uâits interior) is erased.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâfill circle 100,100,50
\hâ\n[lss]uâclear fill rectangle 10,10,90,90
\hâ\n[lss]uâThis opens a window and draws a pacman-like figure.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclear, circle, rectangle, triangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclear screen ? erases the text window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâDescription
\hâ\n[lss]uâclear
screen erases the text window (the window where the output
of print
\hâ\n[lss]uâappears).
\hâ\n[lss]uâIt
must be issued at least once, before some advanced
screen-commands (e.g.
\hâ\n[lss]uâprint at or inkey$) may be called;
this requirement is due to some limitations
\hâ\n[lss]uâof the curses-library, which is used
by yabasic under Unix for some commands.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâprint "Please press a key :
";
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâThe
clear screen command is essential here; if it would be
omitted, yabasic
\hâ\n[lss]uâwould issue an error ("need to
call âclear screenâ first") while trying to
\hâ\n[lss]uâexecute the inkey$-function.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclear
window ? clear the graphic window and begin a new page, if
printing is
\hâ\n[lss]uâunder way
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear window
\hâ\n[lss]uâDescription
\hâ\n[lss]uâclear
window clears the graphic window. If you have started
printing the
\hâ\n[lss]uâgraphic via open printer, the clear
window-command starts a new page as well.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâopen printer "t.ps"
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâif (a>1) clear window
\hâ\n[lss]uâtext 100,100,"Hallo
"+str$(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâclose
printer
\hâ\n[lss]uâclose window
\hâ\n[lss]uâThis
example prints 10 pages, with the text "Hello 1",
"Hello 2", ? and so on.
\hâ\n[lss]uâThe clear screen-command clears the
graphics window and starts a new page.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, open printer
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclose ? close a file, which has been opened before
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclose
filenum
\hâ\n[lss]uâclose # filenum
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
close-command closes an open file. You should issue this
command as soon as
\hâ\n[lss]uâyou are done with reading from or
writing to a file.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
"my.data" for reading as 1
\hâ\n[lss]uâinput #1 a
\hâ\n[lss]uâprint a
\hâ\n[lss]uâclose 1
\hâ\n[lss]uâThis
program opens the file "my.data", reads a number
from it, prints this
\hâ\n[lss]uânumber and closes the file
again.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclose curve ? close a curve, that has been drawn by the line-command
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uânew
curve
\hâ\n[lss]uâline to x1,y1
\hâ\n[lss]uâ?
\hâ\n[lss]uâclose curve
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
close curve-command closes a sequence of lines, that has
been drawn by
\hâ\n[lss]uârepeated line to-commands.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uânew curve
\hâ\n[lss]uâline to 100,50
\hâ\n[lss]uâline to 150,150
\hâ\n[lss]uâline to 50,150
\hâ\n[lss]uâclose curve
\hâ\n[lss]uâThis
example draws a triangle: The three line to-commands draw
two lines; the
\hâ\n[lss]uâfinal line is however not drawn
explicitly, but drawn by the close
\hâ\n[lss]uâcurve-command.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâline, new curve
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclose printer ? stops printing of graphics
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
close printer-command ends the printing graphics. Between
open printer and
\hâ\n[lss]uâclose printer everything you draw
(e.g. circles, lines ?) is sent to your
\hâ\n[lss]uâprinter. close printer puts an end
to printing and will make your printer eject
\hâ\n[lss]uâthe page.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâopen printer
\hâ\n[lss]uâcircle 100,100,50
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâclose window
\hâ\n[lss]uâAs
soon as close printer is executed, your printer will eject a
page with a
\hâ\n[lss]uâcircle on it.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen printer
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâclose window ? close the graphics-window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclose window
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
close window-command closes the graphics-window, i.e. it
makes it disappear
\hâ\n[lss]uâfrom your screen. It includes an
implicit close printer, if a printer has been
\hâ\n[lss]uâopened previously.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâcircle 100,100,50
\hâ\n[lss]uâclose window
\hâ\n[lss]uâThis
example will open a window, draw a circle and close the
window again; all
\hâ\n[lss]uâthis without any pause or delay, so
the window will be closed before you may
\hâ\n[lss]uâregard the circle..
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcolor ? change color for any subsequent drawing-command
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcolour
red,green,blue
\hâ\n[lss]uâcolour
"red,green,blue"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâChange
the color, in which lines, dots, circles, rectangles or
triangles are
\hâ\n[lss]uâdrawn. The color-command accepts
three numbers in the range 0 ? 255 (as in the
\hâ\n[lss]uâfirst line of the synopsis above).
Those numbers specify the intensity for the
\hâ\n[lss]uâprimary colors red, green and blue
respectively. As an example 255,0,0 is red
\hâ\n[lss]uâand 255,255,0 is yellow.
\hâ\n[lss]uâAlternatively
you may specify the color with a single string (as in the
second
\hâ\n[lss]uâline of the synopsis above); this
string should contain three numbers,
\hâ\n[lss]uâseparated by commas. As an example
"255,0,255" would be violet. Using this
\hâ\n[lss]uâvariant of the colour-command, you
may use symbolic names for colours:
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâyellow$="255,255,0"
\hâ\n[lss]uâcolor yellow$
\hâ\n[lss]uâtext 50,50,"Hallo"
\hâ\n[lss]uâ, which reads much clearer.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 255,255
\hâ\n[lss]uâfor x=10 to 235 step 10:for y=10 to
235 step 10
\hâ\n[lss]uâcolour x,y,0
\hâ\n[lss]uâfill rectangle x,y,x+10,y+10
\hâ\n[lss]uânext y:next x
\hâ\n[lss]uâThis
fills the window with colored rectangles. However, none of
the used
\hâ\n[lss]uâcolours contains any shade of blue,
because the color-command has always 0 as a
\hâ\n[lss]uâthird argument.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, backcolor, line, rectangle, triangle, circle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcolour ? see color
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcolour
red,green,blue
\hâ\n[lss]uâcolour
"red,green,blue"
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcolor
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcompile ? compile a string with yabasic-code on the fly
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcompile(code$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThis
is an advanced command (closely related with the
execute-command). It
\hâ\n[lss]uâallows you to compile a string of
yabasic-code (which is the only argument).
\hâ\n[lss]uâAfterwards the compiled code is a
normal part of your program.
\hâ\n[lss]uâNote, that there is no way to remove the compiled code.
\hâ\n[lss]uâExample
\hâ\n[lss]uâcompile("sub
mysub(a):print a:end sub")
\hâ\n[lss]uâmysub(2)
\hâ\n[lss]uâThis
example creates a function named mysub, which simply prints
its single
\hâ\n[lss]uâargument.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâexecute
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcontinue ? start the next iteration of a for-, do-, repeat- or while-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâcontinue
\hâ\n[lss]uâDescription
\hâ\n[lss]uâYou
may use continue within any loop to start the next iteration
immediately.
\hâ\n[lss]uâDepending on the type of the loop,
the loop-condition will or will not be
\hâ\n[lss]uâchecked. Especially: for- and
while-loops will evaluate their respective
\hâ\n[lss]uâconditions, do- and repeat-loops
will not.
\hâ\n[lss]uâRemark:
Another way to change the flow of execution within a loop,
is the
\hâ\n[lss]uâbreak-command.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 100
\hâ\n[lss]uâif mod(a,2)=0 continue
\hâ\n[lss]uâprint a
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis example will print all odd numbers between 1 and 100.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfor, do, repeat, while, break
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâcos() ? return the cosine of its single argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=cos(angle)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe cos-function expects an angle (in radians) and returns its cosine.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint cos(pi)
\hâ\n[lss]uâThis example will print -1.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâacos, sin
\hâ\n[lss]uâD
\hâ\n[lss]uâdata
? introduces a list of data-items
\hâ\n[lss]uâdate$ ? returns a string with
various components of the current date
\hâ\n[lss]uâdec() ? convert a base 2 or base 16
number into decimal form
\hâ\n[lss]uâdefault ? mark the default-branch
within a switch-statement
\hâ\n[lss]uâdim ? create an array prior to its
first use
\hâ\n[lss]uâdo ? start a (conditionless) do-loop
\hâ\n[lss]uâdoc ? special comment, which might
be retrieved by the program itself
\hâ\n[lss]uâdocu$ ? special array, containing
the contents of all docu-statement within the
\hâ\n[lss]uâprogram
\hâ\n[lss]uâdot ? draw a dot in the
graphic-window
\hâ\n[lss]uâName
\hâ\n[lss]uâdata ? introduces a list of data-items
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdata
9,"world"
\hâ\n[lss]uâ?
\hâ\n[lss]uâread b,a$
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
data-keyword introduces a list of comma-separated list of
strings or
\hâ\n[lss]uânumbers, which may be retrieved with
the read-command.
\hâ\n[lss]uâThe
data-command itself does nothing; it just stores data. A
single
\hâ\n[lss]uâdata-command may precede an
arbitrarily long list of values, in which strings
\hâ\n[lss]uâor numbers may be mixed at will.
\hâ\n[lss]uâyabasic
internally uses a data-pointer to keep track of the current
location
\hâ\n[lss]uâwithin the data-list; this pointer
may be reset with the restore-command.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uârestore
\hâ\n[lss]uâfor a=1 to 4
\hâ\n[lss]uâread num$,num
\hâ\n[lss]uâprint num$,"=",num
\hâ\n[lss]uânext a
\hâ\n[lss]uâloop
\hâ\n[lss]uâdata
"eleven",11,"twelve",12,"thirteen",13,"fourteen",14
\hâ\n[lss]uâThis
example just prints a series of lines eleven=11 up to
fourteen=14 and so
\hâ\n[lss]uâon without end.
\hâ\n[lss]uâThe
restore-command ensures that the list of data-items is read
from the start
\hâ\n[lss]uâwith every iteration.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâread, restore
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdate$ ? returns a string with various components of the current date
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=date$
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
date$-function (which must be called without parentheses;
i.e. date$()
\hâ\n[lss]uâwould be an error) returns a string
containing various components of a date; an
\hâ\n[lss]uâexample would be
4-05-27-2004-Thu-May. This string consists of various fields
\hâ\n[lss]uâseparated by hyphens
("-"):
\hâ\n[lss]uâ*
The day within the week as a number in the range 0 (=Sunday)
to 6 (=
\hâ\n[lss]uâSaturday) (in the example above: 4,
i.e. Thursday).
\hâ\n[lss]uâ*
The month as a number in the range 1 (=January) to 12
(=December) (in the
\hâ\n[lss]uâexample: 5 which stands for
May).
\hâ\n[lss]uâ*
The day within the month as a number in the range 1 to 31
(in the example:
\hâ\n[lss]uâ27).
\hâ\n[lss]uâ*
The full, 4-digit year (in the example: 2004, which reminds
me that I
\hâ\n[lss]uâshould adjust the clock within my
computer ?).
\hâ\n[lss]uâ* The abbreviated name of the day within the week (Mon to Sun).
\hâ\n[lss]uâ* The abbreviated name of the month (Jan to Dec).
\hâ\n[lss]uâTherefore
the whole example above (4-05-27-2004-Thu-May) would read:
day 4 in
\hâ\n[lss]uâthe week (counting from 0), May 27
in the year 2004, which is a Thursday in
\hâ\n[lss]uâMay.
\hâ\n[lss]uâNote,
that all fields within the string returned by date$ have a
fixed with
\hâ\n[lss]uâ(numbers are padded with zeroes);
therefore it is easy to extract the various
\hâ\n[lss]uâfields of a date format with
mid$.
\hâ\n[lss]uâExample
\hâ\n[lss]uârem Two ways to print the same ...
\hâ\n[lss]uâprint mid$(date$,3,10)
\hâ\n[lss]uâdim
fields$(6)
\hâ\n[lss]uâa=split(date$,fields$(),"-")
\hâ\n[lss]uâprint
fields$(2),"-",fields$(3),"-",fields$(4)
\hâ\n[lss]uâThis
example shows two different techniques to extract components
from the
\hâ\n[lss]uâvalue returned by date$. The
mid$-function is the preferred way, but you could
\hâ\n[lss]uâjust as well split the return-value
of date$ at every "-" and store the result
\hâ\n[lss]uâwithin an array of strings.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtime$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdec() ? convert a base 2 or base 16 number into decimal form
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=dec(number$)
\hâ\n[lss]uâa=dec(number$,base)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
dec-function takes the string-representation of a base-2 or
base-16 (which
\hâ\n[lss]uâis the default) number and converts
it into a decimal number. The optional
\hâ\n[lss]uâsecond argument (base) might be used
to specify a base other than 16. However,
\hâ\n[lss]uâcurrently only base 2 or base 16 are
supported. Please note, that for base 16
\hâ\n[lss]uâyou may write literals in the usual
way, by preceding them with 0x, e.g. like
\hâ\n[lss]uâprint 0xff
\hâ\n[lss]uâ; this may save you from applying the dec altogether.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a binary number: " a$
\hâ\n[lss]uâprint a$," is
",dec(a$)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâbin$, hex$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdefault ? mark the default-branch within a switch-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâswitch
a+3
\hâ\n[lss]uâcase 1
\hâ\n[lss]uâ?
\hâ\n[lss]uâcase 2
\hâ\n[lss]uâ?
\hâ\n[lss]uâdefault
\hâ\n[lss]uâ?
\hâ\n[lss]uâend switch
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
default-clause is an optional part of the switch-statement
(see there for
\hâ\n[lss]uâmore information). It introduces a
series of statements, that should be
\hâ\n[lss]uâexecuted, if none of the cases
matches, that have been specified before (each
\hâ\n[lss]uâwith its own case-clause).
\hâ\n[lss]uâSo
default specifies a default to be executed, if none of the
explicitly named
\hâ\n[lss]uâcases matches; hence its name.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Please enter a number between 0 and 6,"
\hâ\n[lss]uâprint "specifying a day in the
week."
\hâ\n[lss]uâinput d
\hâ\n[lss]uâswitch d
\hâ\n[lss]uâcase 0:print
"Monday":break
\hâ\n[lss]uâcase 1:print
"Tuesday":break
\hâ\n[lss]uâcase 2:print
"Wednesday":break
\hâ\n[lss]uâcase 3:print
"Thursday":break
\hâ\n[lss]uâcase 4:print
"Friday":break
\hâ\n[lss]uâcase 5:print
"Saturday":break
\hâ\n[lss]uâcase 6:print
"Sunday":break
\hâ\n[lss]uâdefault:print "Hey you entered
something invalid !"
\hâ\n[lss]uâend switch
\hâ\n[lss]uâThis
program translates a number between 0 and 6 into the name of
a weekday;
\hâ\n[lss]uâthe default-case is used to detect
(and complain about) invalid input.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub, case
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdim ? create an array prior to its first use
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdim
array(x,y)
\hâ\n[lss]uâdim array$(x,y)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
dim-command prepares one or more arrays (of either strings
or numbers) for
\hâ\n[lss]uâlater use. This command can also be
used to enlarges an existing array.
\hâ\n[lss]uâWhen
an array is created with the dim-statement, memory is
allocated and all
\hâ\n[lss]uâelements are initialized with either
0 (for numerical arrays) or "" (for string
\hâ\n[lss]uâarrays).
\hâ\n[lss]uâIf
the array already existed, and the dim-statement specifies a
larger size
\hâ\n[lss]uâthan the current size, the array is
enlarged and any old content is preserved.
\hâ\n[lss]uâNote,
that dim cannot be used to shrink an array: If you specify a
size, that
\hâ\n[lss]uâis smaller than the current size,
the dim-command does nothing.
\hâ\n[lss]uâFinally:
To create an array, that is only known within a single
subroutine, you
\hâ\n[lss]uâshould use the command local, which
creates local variables as well as local
\hâ\n[lss]uâarrays.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdim
a(5,5)
\hâ\n[lss]uâfor x=1 to 5:for y=1 to 5
\hâ\n[lss]uâa(x,y)=int(ran(100))
\hâ\n[lss]uânext y:next x
\hâ\n[lss]uâprintmatrix(a())
\hâ\n[lss]uâdim a(7,7)
\hâ\n[lss]uâprintmatrix(a())
\hâ\n[lss]uâsub
printmatrix(ar())
\hâ\n[lss]uâlocal x,y,p,q
\hâ\n[lss]uâx=arraysize(ar(),1)
\hâ\n[lss]uây=arraysize(ar(),2)
\hâ\n[lss]uâfor q=1 to y
\hâ\n[lss]uâfor p=1 to y
\hâ\n[lss]uâprint ar(p,q),"\t";
\hâ\n[lss]uânext p
\hâ\n[lss]uâprint
\hâ\n[lss]uânext q
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example creates a 2-dimensional array (i.e. a matrix) with
the
\hâ\n[lss]uâdim-statement and fills it with
random numbers. The second dim-statement
\hâ\n[lss]uâenlarges the array, all new elements
are filled with 0.
\hâ\n[lss]uâThe subroutine printmatrix just does, what its name says.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâarraysize, arraydim, local
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdo ? start a (conditionless) do-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdo
\hâ\n[lss]uâ?
\hâ\n[lss]uâloop
\hâ\n[lss]uâDescription
\hâ\n[lss]uâStarts
a loop, which is terminated by loop; everything between do
and loop will
\hâ\n[lss]uâbe repeated forever. This loop has
no condition, so it is an infinite loop;
\hâ\n[lss]uânote however, that a break- or
goto-statement might be used to leave this loop
\hâ\n[lss]uâanytime.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uâa=a+1
\hâ\n[lss]uâprint a
\hâ\n[lss]uâif (a>100) break
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example prints the numbers between 1 and 101. The
break-statement is used
\hâ\n[lss]uâto leave the loop.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâloop, repeat, while, break
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdoc ? special comment, which might be retrieved by the program itself
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdoc
This is a comment
\hâ\n[lss]uâdocu This is another comment
\hâ\n[lss]uâDescription
\hâ\n[lss]uâIntroduces
a comment, which spans up to the end of the line. But other
than the
\hâ\n[lss]uârem-comment, any docu-comment is
collected within the special docu$-array and
\hâ\n[lss]uâmight be retrieved later on.
Moreover you might invoke yabasic -docu foo.yab on
\hâ\n[lss]uâthe command line to retrieve the
embedded documentation within the program
\hâ\n[lss]uâfoo.yab.
\hâ\n[lss]uâInstead of doc you may just as well write docu or even documentation.
\hâ\n[lss]uâExample
\hâ\n[lss]uârem
Hi, this has been written by me
\hâ\n[lss]uârem
\hâ\n[lss]uâdoc This program asks for a number
and
\hâ\n[lss]uâdoc prints this number multiplied
with 2
\hâ\n[lss]uârem
\hâ\n[lss]uârem Print out rhe above message
\hâ\n[lss]uâfor a=1 to arraysize(docu$()):print
docu$(a):next a
\hâ\n[lss]uârem
Read and print the number
\hâ\n[lss]uâinput "Please input a number:
" x
\hâ\n[lss]uâprint x*2
\hâ\n[lss]uâThis
program uses the comments within its code to print out a
help message for
\hâ\n[lss]uâthe user.
\hâ\n[lss]uâThe
contents of the doc-lines are retrieved from the
docu$-array; if you do not
\hâ\n[lss]uâwant a comment to be collected
within this array, use the rem-statement
\hâ\n[lss]uâinstead.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâdocu$, rem
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdocu$
? special array, containing the contents of all
docu-statement within the
\hâ\n[lss]uâprogram
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=docu$(1)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâBefore
your program is executed, yabasic collects the content of
all the
\hâ\n[lss]uâdoc-statements within your program
within this 1-dimensional array (well only
\hâ\n[lss]uâthose within the main-program,
libraries are skipped).
\hâ\n[lss]uâYou may use the arraysize function to find out, how many lines it contains.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdocu
\hâ\n[lss]uâdocu This program reads two numbers
\hâ\n[lss]uâdocu and adds them.
\hâ\n[lss]uâdocu
\hâ\n[lss]uârem
retrieve and print the embedded documentation
\hâ\n[lss]uâfor a=1 to arraysize(docu$(),1)
\hâ\n[lss]uâprint docu$(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâinput
"First number: " b
\hâ\n[lss]uâinput "Second number: "
c
\hâ\n[lss]uâprint "The sum of ",b," and ",c," is ",b+c
\hâ\n[lss]uâThis program uses the embedded documentation to issue a usage-message.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâarraydim, rem
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâdot ? draw a dot in the graphic-window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdot
x,y
\hâ\n[lss]uâclear dot x,y
\hâ\n[lss]uâDescription
\hâ\n[lss]uâDraws
a dot at the specified coordinates within your
graphic-window. If
\hâ\n[lss]uâprinting is in effect, the dot
appears on your printout too.
\hâ\n[lss]uâUse
the functions peek("winheight") or
peek("winwidth") to get the size of your
\hâ\n[lss]uâwindow and hence the boundaries of
the coordinates specified for the
\hâ\n[lss]uâdot-command.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâcircle 100,100,100
\hâ\n[lss]uâdo
\hâ\n[lss]uâx=ran(200):y=ran(200)
\hâ\n[lss]uâdot x,y
\hâ\n[lss]uâtotal=total+1
\hâ\n[lss]uâif
(sqrt((x-100)Ë2+(y-100)Ë2)<100) in=in+1
\hâ\n[lss]uâprint 4*in/total
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis program uses a well known algorithm to compute ?.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâline, open window
\hâ\n[lss]uâE
\hâ\n[lss]uâelse
? mark an alternative within an if-statement
\hâ\n[lss]uâelsif ? starts an alternate
condition within an if-statement
\hâ\n[lss]uâend ? terminate your program
\hâ\n[lss]uâendif ? ends an if-statement
\hâ\n[lss]uâend sub ? ends a subroutine
definition
\hâ\n[lss]uâeof ? check, if an open file
contains data
\hâ\n[lss]uâeor() ? compute the bitwise
exclusive or of its two arguments
\hâ\n[lss]uâerror ? raise an error and terminate
your program
\hâ\n[lss]uâeuler ? another name for the
constant 2.71828182864
\hâ\n[lss]uâexecute$() ? execute a user defined
subroutine, which must return a string
\hâ\n[lss]uâexecute() ? execute a user defined
subroutine, which must return a number
\hâ\n[lss]uâexit ? terminate your program
\hâ\n[lss]uâexp() ? compute the exponential
function of its single argument
\hâ\n[lss]uâexport ? mark a function as globally
visible
\hâ\n[lss]uâName
\hâ\n[lss]uâelse ? mark an alternative within an if-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelse
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
else-statement introduces the alternate branch of an
if-statement. I.e. it
\hâ\n[lss]uâstarts the sequence of statements,
which is executed, if the condition of the
\hâ\n[lss]uâif-statement is not true.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number: " a
\hâ\n[lss]uâif (mod(a,2)=1) then
\hâ\n[lss]uâprint a," is odd."
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint a," is even."
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis program detects, if the number you have entered is even or odd.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâif
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâelsif ? starts an alternate condition within an if-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelseif (?)
\hâ\n[lss]uâ?
\hâ\n[lss]uâelsif (?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelse
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
elsif-statement is used to select a single alternative among
a series of
\hâ\n[lss]uâchoices.
\hâ\n[lss]uâWith
each elsif-statement you may specify a condition, which is
tested, if the
\hâ\n[lss]uâmain condition (specified with the
if-statement) has failed. Note that elsif
\hâ\n[lss]uâmight be just as well written as
elseif.
\hâ\n[lss]uâWithin
the example below, two variables a and b are tested against
a range of
\hâ\n[lss]uâvalues. The variable a is tested
with the elsif-statement. The very same tests
\hâ\n[lss]uâare performed for the variable b
too; but here an involved series of
\hâ\n[lss]uâif-else-statements is employed,
making the tests much more obscure.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number: " a
\hâ\n[lss]uâif (a<0) then
\hâ\n[lss]uâprint "less than 0"
\hâ\n[lss]uâelseif (a<=10) then
\hâ\n[lss]uâprint "between 0 and 10"
\hâ\n[lss]uâelsif (a<=20)
\hâ\n[lss]uâprint "between 11 and 20"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "over 20"
\hâ\n[lss]uâendif
\hâ\n[lss]uâinput
"Please enter another number: " b
\hâ\n[lss]uâif (b<0) then
\hâ\n[lss]uâprint "less than 0"
\hâ\n[lss]uâelse
\hâ\n[lss]uâif (b<=10) then
\hâ\n[lss]uâprint "between 0 and 10"
\hâ\n[lss]uâelse
\hâ\n[lss]uâif (b<=20) then
\hâ\n[lss]uâprint "between 11 and 20"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "over 20"
\hâ\n[lss]uâendif
\hâ\n[lss]uâendif
\hâ\n[lss]uâendif
\hâ\n[lss]uâNote,
that the very same tests are performed for the variables a
and b, but can
\hâ\n[lss]uâbe stated much more clearly with the
elsif-statement.
\hâ\n[lss]uâNote,
that elsif might be written as elseif too, and that the
keyword then is
\hâ\n[lss]uâoptional.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâif, else
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâend ? terminate your program
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâend
\hâ\n[lss]uâDescription
\hâ\n[lss]uâTerminate your program. Much (but not exactly) like the exit command.
\hâ\n[lss]uâNote,
that end may not end your program immediately; if you have
opened a
\hâ\n[lss]uâwindow or called clear screen,
yabasic assumes, that your user wants to study
\hâ\n[lss]uâthe output of your program after it
has ended; therefore it issues the line
\hâ\n[lss]uâ---Program done, press RETURN--- and
waits for a key to be pressed. If you do
\hâ\n[lss]uânot like this behaviour, consider
using exit.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Do you want to continue ?"
\hâ\n[lss]uâinput "Please answer y(es) or
n(o): " a$
\hâ\n[lss]uâif
(lower$(left$(a$,1))="n") then
\hâ\n[lss]uâprint "bye"
\hâ\n[lss]uâend
\hâ\n[lss]uâfi
\hâ\n[lss]uâSee also
\hâ\n[lss]uâexit
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâendif ? ends an if-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe endif-statement closes (or ends) an if-statement.
\hâ\n[lss]uâNote,
that endif may be written in a variety of other ways: end
if, end-if or
\hâ\n[lss]uâeven fi.
\hâ\n[lss]uâThe
endif-statement must be omitted, if the if-statement does
not contain the
\hâ\n[lss]uâkeyword then (see the example
below). Such an if-statement without endif
\hâ\n[lss]uâextends only over a single line.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"A number please: " a
\hâ\n[lss]uâif (a<10) then
\hâ\n[lss]uâprint "Your number is less than
10."
\hâ\n[lss]uâendif
\hâ\n[lss]uâREM and now without endif
\hâ\n[lss]uâinput
"A number please: " a
\hâ\n[lss]uâif (a<10) print "Your number
is less than 10."
\hâ\n[lss]uâSee also
\hâ\n[lss]uâif
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâend sub ? ends a subroutine definition
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâsub
foo(?)
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâMarks
the end of a subroutine-definition (which starts with the
sub-keyword).
\hâ\n[lss]uâThe whole concept of subroutines is
explained within the entry for sub.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint foo(3)
\hâ\n[lss]uâsub
foo(a)
\hâ\n[lss]uâreturn a*2
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
program prints out 6. The subroutine foo simply returns
twice its
\hâ\n[lss]uâargument.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâeof ? check, if an open file contains data
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
1,"foo.bar"
\hâ\n[lss]uâif (eof(1)) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâend if
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
eof-function checks, if there is still data left within an
open file. As an
\hâ\n[lss]uâargument it expects the file-number
as returned by (or used within) the
\hâ\n[lss]uâopen-function (or statement).
\hâ\n[lss]uâExample
\hâ\n[lss]uâa=open("foo.bar")
\hâ\n[lss]uâwhile(not eof(a))
\hâ\n[lss]uâinput #a,a$
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâend while
\hâ\n[lss]uâThis
example will print the contents of the file
"foo.bar". The eof-function
\hâ\n[lss]uâwill terminate the loop, if there is
no more data left within the file.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâeor() ? compute the bitwise exclusive or of its two arguments
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint eor(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
eor-function takes two arguments and computes their bitwise
exclusive or.
\hâ\n[lss]uâSee your favorite introductory text
on informatics for an explanation of this
\hâ\n[lss]uâfunction.
\hâ\n[lss]uâThe
xor-function is the same as the eor function; both are
synonymous; however
\hâ\n[lss]uâthey have each their own
description, so you may check out the entry of xor for
\hâ\n[lss]uâa slightly different view.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=0 to 3
\hâ\n[lss]uâfor b=0 to 3
\hâ\n[lss]uâprint fill$(bin$(a))," eor
",fill$(bin$(b))," = ",fill$(bin$(eor(a,b)))
\hâ\n[lss]uânext b
\hâ\n[lss]uânext a
\hâ\n[lss]uâsub
fill$(a$)
\hâ\n[lss]uâreturn right$("0"+a$,2)
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example prints a table, from which you may figure, how the
eor-function is
\hâ\n[lss]uâcomputed.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâand, or
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâerror ? raise an error and terminate your program
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâerror "Wrong, wrong, wrong !!"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâProduces
the same kind or error messages, that yabasic itself
produces (e.g. in
\hâ\n[lss]uâcase of a syntax-error). The single
argument is issued along with the current
\hâ\n[lss]uâline-number.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number between 1 and 10: " a
\hâ\n[lss]uâif (a<1 or a>10) error
"Oh no ..."
\hâ\n[lss]uâThis
program is very harsh in checking the users input; instead
of just asking
\hâ\n[lss]uâagain, the program terminates with
an error, if the user enters something
\hâ\n[lss]uâwrong.
\hâ\n[lss]uâThe error message would look like this:
\hâ\n[lss]uâ---Error
in t.yab, line 2: Oh no ...
\hâ\n[lss]uâ---Error: Program stopped due to an
error
\hâ\n[lss]uâSee also
\hâ\n[lss]uâWell,
there should be a corresponding called warning;
unfortunately ther is
\hâ\n[lss]uânone yet.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâeuler ? another name for the constant 2.71828182864
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfoo=euler
\hâ\n[lss]uâDescription
\hâ\n[lss]uâeuler
is the well known constant named after Leonard Euler; its
value is
\hâ\n[lss]uâ2.71828182864. euler is not a
function, so parens are not allowed (i.e. euler()
\hâ\n[lss]uâwill produce an error). Finally, you
may not assign to euler; it wouldnât sense
\hâ\n[lss]uâanyway, because it is a
constant.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint euler
\hâ\n[lss]uâSee also
\hâ\n[lss]uâpi
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâexecute$() ? execute a user defined subroutine, which must return a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint execute$("foo$","arg1","arg2")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâexecute$
can be used to execute a user defined subroutine, whose name
may be
\hâ\n[lss]uâspecified as a string
expression.
\hâ\n[lss]uâThis
feature is the only way to execute a subroutine, whose name
is not known
\hâ\n[lss]uâby the time you write your program.
This might happen, if you want to execute a
\hâ\n[lss]uâsubroutine, which is compiled (using
the compile command) during the course of
\hâ\n[lss]uâexecution of your program.
\hâ\n[lss]uâNote
however, that the execute$-function is not the preferred
method to execute
\hâ\n[lss]uâa user defined subroutine; in almost
all cases you should just execute a
\hâ\n[lss]uâsubroutine by writing down its name
within your yabasic program (see the
\hâ\n[lss]uâexample).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
execute$("foo$","Hello","world
!")
\hâ\n[lss]uâsub foo$(a$,b$)
\hâ\n[lss]uâreturn a$+" "+b$
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThe
example simply prints Hello world !, which is the return
value of the user
\hâ\n[lss]uâdefined subroutine foo$. The same
could be achieved by executing:
\hâ\n[lss]uâprint foo$(a$,b$)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcompile, execute
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâexecute() ? execute a user defined subroutine, which must return a number
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint execute("bar","arg1","arg2")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
execute-function is the counterpart of the execute$-function
(please see
\hâ\n[lss]uâthere for some caveats). execute
executes subroutines, which returns a number.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
execute("bar",2,3)
\hâ\n[lss]uâsub bar(a,b)
\hâ\n[lss]uâreturn a+b
\hâ\n[lss]uâend sub
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcompile, execute$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâexit ? terminate your program
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâexit
\hâ\n[lss]uâexit 1
\hâ\n[lss]uâDescription
\hâ\n[lss]uâTerminate
your program and return any given value to the operating
system. exit
\hâ\n[lss]uâis similar to end, but it will
terminate your program immediately, no matter
\hâ\n[lss]uâwhat.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Do you want to continue ?"
\hâ\n[lss]uâinput "Please answer y(es) or
n(o): " a$
\hâ\n[lss]uâif
(lower$(left$(a$,1))="n") exit 1
\hâ\n[lss]uâSee also
\hâ\n[lss]uâend
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâexp() ? compute the exponential function of its single argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfoo=exp(bar)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThis
function computes e to the power of its argument, where e is
the well
\hâ\n[lss]uâknown euler constant
2.71828182864.
\hâ\n[lss]uâThe exp-function is the inverse of the log-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâfor x=0 to 100
\hâ\n[lss]uâdot x,100-100*exp(x/100)/euler
\hâ\n[lss]uânext x
\hâ\n[lss]uâThis
program plots part of the exp-function, however the range is
rather small,
\hâ\n[lss]uâso that you may not recognize the
function from this plot.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâlog
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâexport ? mark a function as globally visible
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâexport
sub foo(bar)
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
export-statement is used within libraries to mark a user
defined subroutine
\hâ\n[lss]uâas visible outside the library
wherein it is defined. Subroutines, which are
\hâ\n[lss]uânot exported, must be qualified with
the name of the library, e.g. foo.baz
\hâ\n[lss]uâ(where foo is the name of the
library and baz the name of the subroutine);
\hâ\n[lss]uâexported subroutines may be used
without specifying the name of the library,
\hâ\n[lss]uâe.g. bar.
\hâ\n[lss]uâTherefore export may only be useful within libraries.
\hâ\n[lss]uâExample
\hâ\n[lss]uâThe
library foo.bar (which is listed below) defines two
functions bar and baz,
\hâ\n[lss]uâhowever only the function bar is
exported and therefore visible even outside
\hâ\n[lss]uâthe library; baz is not exported and
may only be used within the library
\hâ\n[lss]uâfoo.yab:
\hâ\n[lss]uâexport
sub bar()
\hâ\n[lss]uâprint "Hello"
\hâ\n[lss]uâend sub
\hâ\n[lss]uâsub
baz()
\hâ\n[lss]uâprint "World"
\hâ\n[lss]uâend sub
\hâ\n[lss]uâNow
within your main program cux.yab (which imports the library
foo.yab); note
\hâ\n[lss]uâthat this program produces an
error:
\hâ\n[lss]uâimport foo
\hâ\n[lss]uâprint
"Calling subroutine foo.bar (okay) ..."
\hâ\n[lss]uâfoo.bar()
\hâ\n[lss]uâprint "done."
\hâ\n[lss]uâprint
"Calling subroutine bar (okay) ..."
\hâ\n[lss]uâbar()
\hâ\n[lss]uâprint "done."
\hâ\n[lss]uâprint
"Calling subroutine foo.baz (okay) ..."
\hâ\n[lss]uâfoo.baz()
\hâ\n[lss]uâprint "done."
\hâ\n[lss]uâprint
"Calling subroutine baz (NOT okay) ..."
\hâ\n[lss]uâbaz()
\hâ\n[lss]uâprint "done."
\hâ\n[lss]uâThe output when executing yabasic foo.yab is this:
\hâ\n[lss]uâCalling
subroutine foo.bar (okay) ...
\hâ\n[lss]uâHello
\hâ\n[lss]uâdone.
\hâ\n[lss]uâCalling subroutine bar (okay) ...
\hâ\n[lss]uâHello
\hâ\n[lss]uâdone.
\hâ\n[lss]uâCalling subroutine foo.baz (okay)
...
\hâ\n[lss]uâWorld
\hâ\n[lss]uâdone.
\hâ\n[lss]uâCalling subroutine baz (NOT okay)
...
\hâ\n[lss]uâ---Error in main.yab, line 16:
canât find subroutine âbazâ
\hâ\n[lss]uâ---Dump: sub baz() called in
main.yab,16
\hâ\n[lss]uâ---Error: Program stopped due to an
error
\hâ\n[lss]uâAs
the error message above shows, the subroutine baz must be
qualified with the
\hâ\n[lss]uâname of the library, if used outside
the library, wherein it is defined (e.g.
\hâ\n[lss]uâfoo.baz. I.e. outside the library
foo.yab you need to write foo.baz. baz alone
\hâ\n[lss]uâwould be an error.
\hâ\n[lss]uâThe
subroutine bar (without adding the name of the library)
however may (and
\hâ\n[lss]uâprobably should) be used in any
program, which imports the library foo.yab.
\hâ\n[lss]uâNote
\hâ\n[lss]uâIn
some sense the set of exported subroutines constitutes the
interface of a
\hâ\n[lss]uâlibrary.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub, import
\hâ\n[lss]uâF
\hâ\n[lss]uâfalse
? a constant with the value of 0
\hâ\n[lss]uâfi ? another name for endif
\hâ\n[lss]uâfill ? draw a filled circles,
rectangles or triangles
\hâ\n[lss]uâfloor() ? compute the floor for its
(float) argument.
\hâ\n[lss]uâfor ? starts a for-loop
\hâ\n[lss]uâfrac() ? return the fractional part
of its numeric argument
\hâ\n[lss]uâName
\hâ\n[lss]uâfalse ? a constant with the value of 0
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâokay=false
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
constant false can be assigned to variables which later
appear in
\hâ\n[lss]uâconditions (e.g. within an
if-statement.
\hâ\n[lss]uâfalse may also be written as FALSE or even FaLsE.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number between 1 and 10: " a
\hâ\n[lss]uâif (check_input(a)) print
"Okay"
\hâ\n[lss]uâsub
check_input(x)
\hâ\n[lss]uâif (x>10 or x<1) return false
\hâ\n[lss]uâreturn true
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThe
subroutine check_input checks its argument and returns true
or false
\hâ\n[lss]uâaccording to the outcome of the
check..
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtrue
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâfi ? another name for endif
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(?)
\hâ\n[lss]uâ?
\hâ\n[lss]uâfi
\hâ\n[lss]uâDescription
\hâ\n[lss]uâfi
marks the end of an if-statement and is exactly equivalent
to endif, please
\hâ\n[lss]uâsee there for further
information.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"A number please: " a
\hâ\n[lss]uâif (a<10) then
\hâ\n[lss]uâprint "Your number is less than
10."
\hâ\n[lss]uâfi
\hâ\n[lss]uâSee also
\hâ\n[lss]uâendif
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâfill ? draw a filled circles, rectangles or triangles
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfill
rectangle 10,10,90,90
\hâ\n[lss]uâfill circle 50,50,20
\hâ\n[lss]uâfill triangle 10,20,20,10,20,20
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
keyword fill may be used within the circle, rectangle or
triangle command
\hâ\n[lss]uâand causes these shapes to be
filled.
\hâ\n[lss]uâfill
can be used in conjunction with and wherever the
clear-clause may appear.
\hâ\n[lss]uâUsed alone, fill will fill the
interior of the shape (circle, rectangle or
\hâ\n[lss]uâtriangle); together with clear the
whole shape (including its interior) is
\hâ\n[lss]uâerased.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâfill circle 100,100,50
\hâ\n[lss]uâclear fill rectangle 10,10,90,90
\hâ\n[lss]uâThis opens a window and draws a pacman-like figure.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclear, circle, rectangle, triangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâfloor() ? compute the floor for its (float) argument.
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint floor(x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
floor-function returns the largest integer number, that is
smaller or equal
\hâ\n[lss]uâthan its argument. For positive
numbers x, floor(x) is the same as int(x); for
\hâ\n[lss]uânegaive numbers it can be different
(see the example below).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
int(-1.5),floor(-1.5)
\hâ\n[lss]uâprint int(-1),floor(-1)
\hâ\n[lss]uâprint int(1.5),floor(1.5)
\hâ\n[lss]uâThis
example compares the functions int and floor, starting with
-1 -2, then -1
\hâ\n[lss]uâ-1 and ending with 1 1, which shows
the different behaviour of both functions.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâceil, int, frac
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâfor ? starts a for-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfor
a=1 to 100 step 2
\hâ\n[lss]uâ?
\hâ\n[lss]uânext a
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
for-loop lets its numerical variable (a in the synopsis)
assume all values
\hâ\n[lss]uâwithin the given range. The optional
step-clause may specify a value (default:
\hâ\n[lss]uâ1) by which the variable will be
incremented (or decremented, if step is
\hâ\n[lss]uânegative).
\hâ\n[lss]uâAny
for-statement can be replaced by a set of ifs and gotos; as
you may infer
\hâ\n[lss]uâfrom the example below this is
normally not feasible. However if you want to
\hâ\n[lss]uâknow in detail how the for-statement
works, you should study this example,
\hâ\n[lss]uâwhich presents a for-statement and
an exactly equivalent series of ifs and
\hâ\n[lss]uâgotos.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor a=1 to 10 step 2:print a:next
\hâ\n[lss]uâa=1
\hâ\n[lss]uâlabel check
\hâ\n[lss]uâif (a>10) goto done
\hâ\n[lss]uâprint a
\hâ\n[lss]uâa=a+2
\hâ\n[lss]uâgoto check
\hâ\n[lss]uâlabel done
\hâ\n[lss]uâThis
example simply prints the numbers 1, 3, 5, 7 and 9. It does
this twice:
\hâ\n[lss]uâFirst with a simple for-statement
and then with ifs and gotos.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâstep, next
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâfrac() ? return the fractional part of its numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=frac(y)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
frac-function takes its argument, removes all the digits to
the left of the
\hâ\n[lss]uâcomma and just returns the digits
right of the comma, i.e. the fractional part.
\hâ\n[lss]uâRefer
to the example to learn how to rewrite frac by employing the
int-function
\hâ\n[lss]uâ(which is not suggested anyway).
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâprint frac(sqr(a))
\hâ\n[lss]uâprint sqr(a)-int(sqr(a))
\hâ\n[lss]uânext a
\hâ\n[lss]uâThe
example prints the fractional part of the square root of the
numbers
\hâ\n[lss]uâbetween 1 and 10. Each result is
computed (and printed) twice: Once by
\hâ\n[lss]uâemploying the frac-function and once
by employing the int-function.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâint, floor, ceil
\hâ\n[lss]uâG
\hâ\n[lss]uâgetbit$()
? return a string representing the bit pattern of a
rectangle within
\hâ\n[lss]uâthe graphic window
\hâ\n[lss]uâgetscreen$() ? returns a string
representing a rectangular section of the text
\hâ\n[lss]uâterminal
\hâ\n[lss]uâglob() ? check if a string matches a
simple pattern
\hâ\n[lss]uâgosub ? continue execution at
another point within your program (and return
\hâ\n[lss]uâlater)
\hâ\n[lss]uâgoto ? continue execution at another
point within your program (and never come
\hâ\n[lss]uâback)
\hâ\n[lss]uâName
\hâ\n[lss]uâgetbit$()
? return a string representing the bit pattern of a
rectangle within
\hâ\n[lss]uâthe graphic window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=getbit$(10,10,20,20)
\hâ\n[lss]uâa$=getbit$(10,10 to 20,20)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
function getbit returns a string, which contains the encoded
bit-pattern of
\hâ\n[lss]uâa rectangle within graphic window;
the four arguments specify two opposite
\hâ\n[lss]uâcorners of the rectangle. The string
returned might later be fed to the putbit
\hâ\n[lss]uâ-command.
\hâ\n[lss]uâThe
getbit$-function might be used for simple animations (as in
the example
\hâ\n[lss]uâbelow).
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 40,40
\hâ\n[lss]uâfill circle 20,20,18
\hâ\n[lss]uâcircle$=getbit$(0,0,40,40)
\hâ\n[lss]uâclose window
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâfor x=1 to 200
\hâ\n[lss]uâputbit circle$,x,80
\hâ\n[lss]uânext x
\hâ\n[lss]uâThis example features a circle moving from left to right over the window.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâputbit
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâgetscreen$()
? returns a string representing a rectangular section of the
text
\hâ\n[lss]uâterminal
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=getscreen$(2,2,20,20)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
getscreen$ function returns a string representing the area
of the screen as
\hâ\n[lss]uâspecified by its four arguments
(which specify two opposite corners). I.e.
\hâ\n[lss]uâeverything you have printed within
this rectangle will be encoded in the string
\hâ\n[lss]uâreturned (including any
colour-information).
\hâ\n[lss]uâLike
most other commands dealing with advanced text output,
getscreen$
\hâ\n[lss]uârequires, that you have called clear
screen before.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâfor
a=1 to 1000:
\hâ\n[lss]uâprint color("red")
"1";
\hâ\n[lss]uâprint color("green")
"2";
\hâ\n[lss]uâprint color("blue")
"3";
\hâ\n[lss]uânext a
\hâ\n[lss]uâscreen$=getscreen$(10,10,40,10)
\hâ\n[lss]uâprint at(10,10) " Please Press
âyâ or ânâ ! "
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâputscreen screen$,10,10
\hâ\n[lss]uâThis
program fills the screen with colored digits and afterwards
asks the user
\hâ\n[lss]uâfor a choice ( Please press
âyâ or ânâ ! ). Afterwards the area
of the screen,
\hâ\n[lss]uâwhich has been overwritten by the
question will be restored with its previous
\hâ\n[lss]uâcontents, whhch had been saved via
getscreen$.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâputscreen$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâglob() ? check if a string matches a simple pattern
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif (glob(string$,pattern$)) ?
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
glob-function takes two arguments, a string and a (glob-)
pattern, and
\hâ\n[lss]uâchecks if the string matches the
pattern. However glob does not employ the
\hâ\n[lss]uâpowerful rules of regular
expressions; rather it has only two special
\hâ\n[lss]uâcharacters: * (which matches any
number (even zero) of characters) and ? (which
\hâ\n[lss]uâmatches exactly a single
character).
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâread string$,pattern$
\hâ\n[lss]uâif (glob(string$,pattern$)) then
\hâ\n[lss]uâprint string$," matches
",pattern$
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint string$," does not match
",pattern$
\hâ\n[lss]uâendif
\hâ\n[lss]uânext a
\hâ\n[lss]uâdata
"abc","a*"
\hâ\n[lss]uâdata "abc","a?"
\hâ\n[lss]uâdata "abc","a??"
\hâ\n[lss]uâdata "abc","*b*"
\hâ\n[lss]uâdata "abc","*"
\hâ\n[lss]uâdata "abc","???"
\hâ\n[lss]uâdata "abc","?"
\hâ\n[lss]uâdata "abc","*c"
\hâ\n[lss]uâdata "abc","A*"
\hâ\n[lss]uâdata
"abc","????"
\hâ\n[lss]uâThis
program checks the string abc against various patterns and
prints the
\hâ\n[lss]uâresult. The output is:
\hâ\n[lss]uâabc
matches a*
\hâ\n[lss]uâabc does not match a?
\hâ\n[lss]uâabc matches a??
\hâ\n[lss]uâabc matches *b*
\hâ\n[lss]uâabc matches *
\hâ\n[lss]uâabc matches ???
\hâ\n[lss]uâabc does not match ?
\hâ\n[lss]uâabc matches *c
\hâ\n[lss]uâabc does not match A*
\hâ\n[lss]uâabc does not match ????
\hâ\n[lss]uâSee also
\hâ\n[lss]uâThere are no related commands.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâgosub
? continue execution at another point within your program
(and return
\hâ\n[lss]uâlater)
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâgosub foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel
foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn
\hâ\n[lss]uâDescription
\hâ\n[lss]uâgosub
remembers the current position within your program and then
passes the
\hâ\n[lss]uâflow of execution to another point
(which is normally marked with a label).
\hâ\n[lss]uâLater, when a return-statement is
encountered, the execution is resumed at the
\hâ\n[lss]uâprevious location.
\hâ\n[lss]uâgosub
is the traditional command for calling code, which needs to
be executed
\hâ\n[lss]uâfrom various places within your
program. However, with subroutines yabasic
\hâ\n[lss]uâoffers a much more flexible way to
achieve this (and more). Therefore gosub
\hâ\n[lss]uâmust to be considered obsolete.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Do you want to exit ? "
\hâ\n[lss]uâgosub ask
\hâ\n[lss]uâif (r$="y") exit
\hâ\n[lss]uâlabel
ask
\hâ\n[lss]uâinput "Please answer yes or no,
by typing âyâ or ânâ: ",r$
\hâ\n[lss]uâreturn
\hâ\n[lss]uâSee also
\hâ\n[lss]uâreturn, goto, sub, label, on gosub
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâgoto
? continue execution at another point within your program
(and never come
\hâ\n[lss]uâback)
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâgoto foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
goto-statement passes the flow of execution to another point
within your
\hâ\n[lss]uâprogram (which is normally marked
with a label).
\hâ\n[lss]uâgoto
is normally considered obsolete and harmful, however in
yabasic it may be
\hâ\n[lss]uâput to the good use of leaving loops
(e.g. while or for) prematurely. Note
\hâ\n[lss]uâhowever, that subroutines may not be
left with the goto-statement.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Please press any key to continue."
\hâ\n[lss]uâprint "(program will continue
by itself within 10 seconds)"
\hâ\n[lss]uâfor a=1 to 10
\hâ\n[lss]uâif (inkey$(1)<>"")
then goto done
\hâ\n[lss]uânext a
\hâ\n[lss]uâlabel done
\hâ\n[lss]uâprint "Hello World !"
\hâ\n[lss]uâHere the goto-statement is used to leave the for-loop prematurely.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgosub, on goto
\hâ\n[lss]uâH
\hâ\n[lss]uâhex$() ? convert a number into hexadecimal
\hâ\n[lss]uâName
\hâ\n[lss]uâhex$() ? convert a number into hexadecimal
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint hex$(foo)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
hex$-function converts a number into a string with its
hexadecimal
\hâ\n[lss]uârepresentation. hex$ is the inverse
of the dec-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
1,"foo"
\hâ\n[lss]uâwhile(!eof(1))
\hâ\n[lss]uâprint
right$("0"+hex$(peek(1)),2)," ";
\hâ\n[lss]uâi=i+1
\hâ\n[lss]uâif (mod(i,10)=0) print
\hâ\n[lss]uâend while
\hâ\n[lss]uâprint
\hâ\n[lss]uâThis
program reads the file foo and prints its output as a
hex-dump using the
\hâ\n[lss]uâhex-function.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâdecbin
\hâ\n[lss]uâI
\hâ\n[lss]uâif
? evaluate a condition and execute statements or not,
depending on the
\hâ\n[lss]uâresult
\hâ\n[lss]uâimport ? import a library
\hâ\n[lss]uâinkey$ ? wait, until a key is
pressed
\hâ\n[lss]uâinput ? read input from the user (or
from a file) and assign it to a variable
\hâ\n[lss]uâinstr() ? searches its second
argument within the first; returns its position
\hâ\n[lss]uâif found
\hâ\n[lss]uâint() ? return the integer part of
its single numeric argument
\hâ\n[lss]uâName
\hâ\n[lss]uâif
? evaluate a condition and execute statements or not,
depending on the
\hâ\n[lss]uâresult
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâif (?) ?
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelse
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâif
(?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelsif (?)
\hâ\n[lss]uâ?
\hâ\n[lss]uâelsif (?) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâelse
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
if-statement is used to evaluate a conditions and take
actions accordingly.
\hâ\n[lss]uâ(As an aside, please note that there
is no real difference between conditions
\hâ\n[lss]uâand expressions.)
\hâ\n[lss]uâThere are two major forms of the if-statement:
\hâ\n[lss]uâ* The one-line-form without the keyword then:
\hâ\n[lss]uâif (?) ?
\hâ\n[lss]uâThis
form evaluates the condition and if the result is true
executes all
\hâ\n[lss]uâcommands (separated by colons) upt
to the end of the line. There is neither
\hâ\n[lss]uâan endif keyword nor an
else-branch.
\hâ\n[lss]uâ* The multi-line-form with the keyword then:
\hâ\n[lss]uâif (?) then ? elsif (?) ? else ? endif
\hâ\n[lss]uâ(where elsif and else are optional, whereas endif is not.
\hâ\n[lss]uâAccording to the requirements of your program, you may specify:
\hâ\n[lss]uâ+
elsif(?), which specifies a condition, that will be
evaluated only if
\hâ\n[lss]uâthe condition(s) within if or any
preceding elsif did not match.
\hâ\n[lss]uâ+
else, which introduces a sequence of commands, that will be
executed,
\hâ\n[lss]uâif none of the conditions above did
match.
\hâ\n[lss]uâ+ endif is required and ends the if-statement.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number between 1 and 4: " a
\hâ\n[lss]uâif (a<=1 or a>=4) error
"Wrong, wrong !"
\hâ\n[lss]uâif (a=1) then
\hâ\n[lss]uâprint "one"
\hâ\n[lss]uâelsif (a=2)
\hâ\n[lss]uâprint "two"
\hâ\n[lss]uâelsif (a=3)
\hâ\n[lss]uâprint "three"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "four"
\hâ\n[lss]uâendif
\hâ\n[lss]uâThe
input-number between 1 and 4 is simply echoed as text (one,
two, ?). The
\hâ\n[lss]uâexample demonstrates both forms
(short and long) of the if-statement (Note
\hâ\n[lss]uâhowever, that the same thing can be
done, probably somewhat more elegant, with
\hâ\n[lss]uâthe switch-statement).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâelse, elsif, endif, conditions and expressions.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâimport ? import a library
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâimport foo
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
import-statement imports a library. It expects a single
argument, which
\hâ\n[lss]uâmust be the name of a library
(without the trailing .yab). This library will
\hâ\n[lss]uâthen be read and parsed and its
subroutines (and variables) will be made
\hâ\n[lss]uâavailable within the importing
program. Most of the time this will be the main
\hâ\n[lss]uâprogram, but libraries my also
import and use other libraries.
\hâ\n[lss]uâLibraries will first be searched in three locations in order:
\hâ\n[lss]uâ*
The current directory, i.e. the directory from which you
have invoked
\hâ\n[lss]uâyabasic)
\hâ\n[lss]uâ*
The directory, where your main program lives. This can be
different from
\hâ\n[lss]uâthe first directory, if you specify
a path for your main program, e.g. like
\hâ\n[lss]uâyabasic foo/bar.yab.
\hâ\n[lss]uâ*
Finally, libraries are searched within a special directory,
whose exact
\hâ\n[lss]uâlocation depends on your system or
options when invoking yabasic. Typical
\hâ\n[lss]uâvalues would be /usr/lib under Unix
or C:\yabasic\lib under Windows.
\hâ\n[lss]uâInvoking yabasic --help will show
the correct directory. The location of
\hâ\n[lss]uâthis directory may be changed with
the option --librarypath (see options).
\hâ\n[lss]uâExample
\hâ\n[lss]uâLets
say you have a yabasic-program foo.yab, which imports a
library lib.yab.
\hâ\n[lss]uâfoo.yab; this would read:
\hâ\n[lss]uâimport lib
\hâ\n[lss]uârem
This works
\hâ\n[lss]uâlib.x(0)
\hâ\n[lss]uârem
This works too
\hâ\n[lss]uâx(1)
\hâ\n[lss]uârem
And this
\hâ\n[lss]uâlib.y(2)
\hâ\n[lss]uârem
But this not !
\hâ\n[lss]uây(3)
\hâ\n[lss]uâNow the library lib.yab reads:
\hâ\n[lss]uârem
Make the subroutine x easily available outside this library
\hâ\n[lss]uâexport sub x(a)
\hâ\n[lss]uâprint a
\hâ\n[lss]uâreturn
\hâ\n[lss]uâend sub
\hâ\n[lss]uârem
sub y must be referenced by its full name
\hâ\n[lss]uârem outside this library
\hâ\n[lss]uâsub y(a)
\hâ\n[lss]uâprint a
\hâ\n[lss]uâreturn
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis program produces an error:
\hâ\n[lss]uâ0
\hâ\n[lss]uâ1
\hâ\n[lss]uâ2
\hâ\n[lss]uâ---Error in foo.yab, line 13:
canât find subroutine âyâ
\hâ\n[lss]uâ---Dump: sub y() called in
foo.yab,13
\hâ\n[lss]uâ---Error: Program stopped due to an
error
\hâ\n[lss]uâAs
you may see from the error message, yabasic is unable to
find the subroutine
\hâ\n[lss]uây without specifying the name of the
library (i.e. lib.y). The reason for this
\hâ\n[lss]uâis, that y, other than x, is not
exported from the library lib.yab (using the
\hâ\n[lss]uâexport-statement).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâexport, sub
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâinkey$ ? wait, until a key is pressed
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâfoo$=inkey$
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâfoo$=inkey$(bar)
\hâ\n[lss]uâinkey$(bar)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
inkeys$-function waits, until the user presses a key on the
keyboard or a
\hâ\n[lss]uâbutton of his mouse, and returns
this very key. An optional argument specifies
\hâ\n[lss]uâthe number of seconds to wait; if
omitted, inkey$ will wait indefinitely.
\hâ\n[lss]uâinkey$ may only be used, if clear screen has been called at least once.
\hâ\n[lss]uâFor
normal keys, yabasic simply returns the key, e.g. a, 1 or !.
For function
\hâ\n[lss]uâkeys you will get f1, f2 and so on.
Other special keys will return these
\hâ\n[lss]uâstrings respectively: enter,
backspace, del, esc, scrnup (for screen up),
\hâ\n[lss]uâscrndown and tab. Modifier keys
(e.g. ctrl, alt or shift) by themselves can not
\hâ\n[lss]uâbe detected (e.g. if you
simultaneously press shift and âaâ, inkey$ will
return
\hâ\n[lss]uâthe letter âAâ instead
of âaâ of course).
\hâ\n[lss]uâIf
a graphical window has been opened (via open window) any
mouseclick within
\hâ\n[lss]uâthis window will be returned by
inkey$ too. The string returned (e.g.
\hâ\n[lss]uâMB1d+0:0028,0061, MB2u+0:0028,0061
or MB1d+1:0028,0061) is constructed as
\hâ\n[lss]uâfollows:
\hâ\n[lss]uâ*
Every string associated with a mouseclick will start with
the fixed string
\hâ\n[lss]uâMB
\hâ\n[lss]uâ* The next digit (1, 2 or 3) specifies the mousebutton pressed.
\hâ\n[lss]uâ*
A single letter, d or u, specifies, if the mousebutton has
been pressed or
\hâ\n[lss]uâreleased: d stands for down, i.e.
the mousebutton has been pressed; u means
\hâ\n[lss]uâup, i.e. the mousebutton has been
released.
\hâ\n[lss]uâ* The plus-sign (â+â), which follows is always fixed.
\hâ\n[lss]uâ*
The next digit (in the range 0 to 7) encodes the modifier
keys pressed,
\hâ\n[lss]uâwhere 1 stands for shift, 2 stands
for alt and 4 stands for ctrl.
\hâ\n[lss]uâ*
The next four digits (e.g. 0028) contain the x-position,
where the
\hâ\n[lss]uâmousebutton has been pressed.
\hâ\n[lss]uâ* The comma to follow is always fixed.
\hâ\n[lss]uâ*
The last four digits (e.g. 0061) contain the y-position,
where the
\hâ\n[lss]uâmousebutton has been pressed.
\hâ\n[lss]uâAll
those fields are of fixed length, so you may use functions
like mid$ to
\hâ\n[lss]uâextract certain fields. However,
note that with mousex, mousey, mouseb and
\hâ\n[lss]uâmousemod there are specialized
functions to return detailed information about
\hâ\n[lss]uâthe mouseclick. Finally it should be
noted, that inkey$ will only register
\hâ\n[lss]uâmouseclicks within the
graphic-window; mouseclicks in the text-window cannot be
\hâ\n[lss]uâdetected.
\hâ\n[lss]uâinkey$
accepts an optional argument, specifying a timeout in
seconds; if no key
\hâ\n[lss]uâhas been pressed within this span of
time, an empty string is returned. If the
\hâ\n[lss]uâtimeout-argument is omitted, inkey$
will wait for ever.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâopen window 100,100
\hâ\n[lss]uâprint "Press any key or press
âqâ to stop."
\hâ\n[lss]uârepeat
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâuntil(a$="q")
\hâ\n[lss]uâThis
program simply returns the key pressed. You may use it, to
learn, which
\hâ\n[lss]uâstrings are returned for the special
keys on your keyboard (e.g.
\hâ\n[lss]uâfunction-keys).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclear screen,mousex, mousey, mouseb, mousemod
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâinput ? read input from the user (or from a file) and assign it to a variable
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâinput
a
\hâ\n[lss]uâinput a,b,c
\hâ\n[lss]uâinput a$
\hâ\n[lss]uâinput "Hello" a
\hâ\n[lss]uâinput #1 a$
\hâ\n[lss]uâDescription
\hâ\n[lss]uâinput
reads the new contents of one or many (numeric- or string-)
variables,
\hâ\n[lss]uâeither from the keyboard (i.e. from
you) or from a file. An optional first
\hâ\n[lss]uâstring-argument specifies a prompt,
which will be issued before reading any
\hâ\n[lss]uâcontents.
\hâ\n[lss]uâIf
you want to read from an open file, you need to specify a
hash (â#â),
\hâ\n[lss]uâfollowed by the number, under which
the file has been opened.
\hâ\n[lss]uâNote,
that the input is split at spaces, i.e. if you enter a whole
line
\hâ\n[lss]uâconsisting of many space-separated
word, the first input-statement will only
\hâ\n[lss]uâreturn the first word; the other
words will only be returned on subsequent
\hâ\n[lss]uâcalls to input; the same applies, if
a single input reads multiple variables:
\hâ\n[lss]uâThe first variable gets only the
first word, the second one the second word,
\hâ\n[lss]uâand so on. If you donât like
this behaviour, you may use line input, which
\hâ\n[lss]uâreturns a whole line (including
embedded spaces) at once.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter the name of a file to read: " a$
\hâ\n[lss]uâopen 1,a$
\hâ\n[lss]uâwhile(!eof(1))
\hâ\n[lss]uâinput #1 b$
\hâ\n[lss]uâprint b$
\hâ\n[lss]uâwend
\hâ\n[lss]uâIf
this program is stored within a file test.yab and you enter
this name when
\hâ\n[lss]uâprompted for a file to read, you
will see this output:
\hâ\n[lss]uâPlease
enter the name of a file to read: t.yab
\hâ\n[lss]uâinput
\hâ\n[lss]uâ"Please
\hâ\n[lss]uâenter
\hâ\n[lss]uâthe
\hâ\n[lss]uâname
\hâ\n[lss]uâof
\hâ\n[lss]uâa
\hâ\n[lss]uâfile
\hâ\n[lss]uâto
\hâ\n[lss]uâread:
\hâ\n[lss]uâ"
\hâ\n[lss]uâa$
\hâ\n[lss]uâopen
\hâ\n[lss]uâ1,a$
\hâ\n[lss]uâwhile(!eof(1))
\hâ\n[lss]uâinput
\hâ\n[lss]uâ#1
\hâ\n[lss]uâb$
\hâ\n[lss]uâprint
\hâ\n[lss]uâb$
\hâ\n[lss]uâwend
\hâ\n[lss]uâSee also
\hâ\n[lss]uâline input
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâinstr()
? searches its second argument within the first; returns its
position
\hâ\n[lss]uâif found
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
instr(a$,b$)
\hâ\n[lss]uâif (instr(a$,b$)) ?
\hâ\n[lss]uâpos=instr(a$,b$,x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
instr-functions requires two string arguments and searches
the second
\hâ\n[lss]uâargument within the first. If the
second argument can be found within the
\hâ\n[lss]uâfirst, the position is returned
(counting from one). If it can not be found,
\hâ\n[lss]uâthe instr-function returns 0; this
makes this function usable within the
\hâ\n[lss]uâcondition of an if-statement (see
the example below).
\hâ\n[lss]uâIf
you supply a third, numeric argument to the instr-function,
it will be used
\hâ\n[lss]uâas a starting point for the search.
Therefore instr("abcdeabcdeabcde","e",8)
\hâ\n[lss]uâwill return 10, because the search
for an "e" starts at position 8 and finds
\hâ\n[lss]uâthe "e" at position 10
(and not the one at position 5).
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a text containing the string
âcatâ: " a$
\hâ\n[lss]uâif (instr(a$,"cat")) then
\hâ\n[lss]uâprint "Well done !"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "No cat in your input
..."
\hâ\n[lss]uâendif
\hâ\n[lss]uâSee also
\hâ\n[lss]uârinstr
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâint() ? return the integer part of its single numeric argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint int(a)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
int-function returns only the digits before the comma;
int(2.5) returns 2
\hâ\n[lss]uâand int(-2.3) returns -2.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a whole number between 1 and 10: " a
\hâ\n[lss]uâif (a=int(a) and a>=1 and
a<=10) then
\hâ\n[lss]uâprint "Thanx !"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "Never mind ..."
\hâ\n[lss]uâendif
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfrac, floor, ceil
\hâ\n[lss]uâL
\hâ\n[lss]uâlabel
? mark a specific location within your program for goto,
gosub or restore
\hâ\n[lss]uâleft$() ? return (or change) left
end of a string
\hâ\n[lss]uâlen() ? return the length of a
string
\hâ\n[lss]uâline ? draw a line
\hâ\n[lss]uâline input ? read in a whole line of
text and assign it to a variable
\hâ\n[lss]uâlocal ? mark a variable as local to
a subroutine
\hâ\n[lss]uâlog() ? compute the natural
logarithm
\hâ\n[lss]uâloop ? marks the end of an infinite
loop
\hâ\n[lss]uâlower$() ? convert a string to lower
case
\hâ\n[lss]uâltrim$() ? trim spaces at the left
end of a string
\hâ\n[lss]uâName
\hâ\n[lss]uâlabel ? mark a specific location within your program for goto, gosub or restore
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâgoto foo
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
label-command can be used to give a name to a specific
location within your
\hâ\n[lss]uâprogram. Such a position might be
referred from one of three commands: goto,
\hâ\n[lss]uâgosub and restore.
\hâ\n[lss]uâYou
may use labels safely within libraries, because a label
(e.g. foo) does not
\hâ\n[lss]uâcollide with a label with the same
name within the main program or within
\hâ\n[lss]uâanother library; yabasic will not
mix them up.
\hâ\n[lss]uâAs
an aside, please note, that line numbers are a special
(however deprecated)
\hâ\n[lss]uâcase of labels; see the second
example below.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 100
\hâ\n[lss]uâif (ran(10)>5) goto done
\hâ\n[lss]uânext a
\hâ\n[lss]uâlabel done
\hâ\n[lss]uâ10
for a=1 to 100
\hâ\n[lss]uâ20 if (ran(10)>5) goto 40
\hâ\n[lss]uâ30 next a
\hâ\n[lss]uâ40
\hâ\n[lss]uâWithin
this example, the for-loop will probably be left prematurely
with a
\hâ\n[lss]uâgoto-statement. This task is done
twice: First with labels and then again with
\hâ\n[lss]uâline numbers.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgosub, goto.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâleft$() ? return (or change) left end of a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
left$(a$,2)
\hâ\n[lss]uâleft$(b$,3)="foobar"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
left$-function accepts two arguments (a string and a number)
and returns
\hâ\n[lss]uâthe part from the left end of the
string, whose length is specified by its
\hâ\n[lss]uâsecond argument. Loosely spoken, it
simply returns the requested number of
\hâ\n[lss]uâchars from the left end of the given
string.
\hâ\n[lss]uâNote,
that the left$-function can be assigned to, i.e. it may
appear on the
\hâ\n[lss]uâleft hand side of an assignment. In
this way it is possible to change a part of
\hâ\n[lss]uâthe variable used within the
left$-function. Note, that that way the length of
\hâ\n[lss]uâthe string cannot be changed, i.e.
characters might be overwritten, but not
\hâ\n[lss]uâadded. For an example see below.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please answer yes or no: " a$
\hâ\n[lss]uâl=len(a$):a$=lower$(a$):print
"Your answer is ";
\hâ\n[lss]uâif (left$("yes",l)=a$ and
l>=1) then
\hâ\n[lss]uâprint "yes"
\hâ\n[lss]uâelsif (left$("no",l)=a$
and l>=1) then
\hâ\n[lss]uâprint "no"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "?"
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis
example asks a simple yes/no question and goes some way to
accept even
\hâ\n[lss]uâincomplete input, while still being
able to reject invalid input.
\hâ\n[lss]uâThis
second example demonstrates the capability to assign to the
\hâ\n[lss]uâleft$-function.
\hâ\n[lss]uâa$="Heiho
World !"
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâleft$(a$,5)="Hello"
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâSee also
\hâ\n[lss]uâright$, mid$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâlen() ? return the length of a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=len(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe len-function returns the length of its single string argument.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a password: " a$
\hâ\n[lss]uâif (len(a$)<6) error
"Password too short !"
\hâ\n[lss]uâThis example checks the length of the password, that the user has entered.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâleft$, right$ and mid$,
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâline ? draw a line
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâline 0,0,100,100
\hâ\n[lss]uâline 0,0 to 100,100
\hâ\n[lss]uânew curve
\hâ\n[lss]uâline 100,100
\hâ\n[lss]uâline to 100,100
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâclear line 0,0,100,100
\hâ\n[lss]uâclear line 0,0 to 100,100
\hâ\n[lss]uânew curve
\hâ\n[lss]uâclear line 100,100
\hâ\n[lss]uâclear line to 100,100
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
line-command draws a line. Simple as this is, the
line-command has a large
\hâ\n[lss]uâvariety of forms as they are listed
in the synopsis above. Lets look at them a
\hâ\n[lss]uâlittle closer:
\hâ\n[lss]uâ*
A line has a starting and an end point; therefore the
line-command
\hâ\n[lss]uâ(normally) needs four numbers as
arguments, representing these two points.
\hâ\n[lss]uâThis is the first form appearing
within the synopsis.
\hâ\n[lss]uâ*
You may separate the two points with either â,â
or to, which accounts for
\hâ\n[lss]uâthe second form of the
line-command.
\hâ\n[lss]uâ*
The line-command may be used to draw a connected sequence of
lines with a
\hâ\n[lss]uâsequence of commands like line x,y;
Each command will draw a line from the
\hâ\n[lss]uâpoint where the last line-command
left off, to the point specified in the
\hâ\n[lss]uâarguments. Note, that you need to
use the command new curve before you may
\hâ\n[lss]uâissue such a line-command. See the
example below.
\hâ\n[lss]uâ*
You may insert the word to for beauty: line to x,y, which
does exactly the
\hâ\n[lss]uâsame as line x,y
\hâ\n[lss]uâ*
Finally, you may choose not to draw, but to erase the lines;
this can be
\hâ\n[lss]uâdone by prepending the phrase clear.
This account for all the other forms
\hâ\n[lss]uâof the line-command.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâline 10,10 to 10,190
\hâ\n[lss]uâline 10,190 to 190,190
\hâ\n[lss]uânew curve
\hâ\n[lss]uâfor a=0 to 360
\hâ\n[lss]uâline to
10+a*180/360,100+60*sin(a*pi/180)
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis
example draws a sine-curve (with an offset in x- and
y-direction). Note,
\hâ\n[lss]uâthat the first line-command after
new curve does not draw anything. Only the
\hâ\n[lss]uâcoordinates will be stored. The
second iteration of the loop then uses these
\hâ\n[lss]uâcoordinates as a starting point for
the first line.
\hâ\n[lss]uâSee also
\hâ\n[lss]uânew curve, close curve, open window
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâline input ? read in a whole line of text and assign it to a variable
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâline
input a
\hâ\n[lss]uâline input a$
\hâ\n[lss]uâline input "Hello" a
\hâ\n[lss]uâline input #1 a$
\hâ\n[lss]uâDescription
\hâ\n[lss]uâIn
most respects line input is like the input-command: It reads
the new
\hâ\n[lss]uâcontents of a variable, either from
keyboard or from a file. However, line
\hâ\n[lss]uâinput always reads a complete line
and assigns it to its variable. line input
\hâ\n[lss]uâdoes not stop reading at spaces and
is therefore the best way to read in a
\hâ\n[lss]uâstring which might contain
whitespace. Note, that the final newline is stripped
\hâ\n[lss]uâof.
\hâ\n[lss]uâExample
\hâ\n[lss]uâline
input "Please enter your name (e.g. Frodo Beutelin):
" a$
\hâ\n[lss]uâprint "Hello ",a$
\hâ\n[lss]uâNote
that the usage of line input is essential in this example; a
simple
\hâ\n[lss]uâinput-statement would only return
the string up to the first space, e.g. Frodo.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinput
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâlocal ? mark a variable as local to a subroutine
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâsub foo()
\hâ\n[lss]uâlocal a,b,c$,d(10),e$(5,5)
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
local-command can (and should be) used to mark a variable
(or array) as
\hâ\n[lss]uâlocal to the containing subroutine.
This means, that a local variable in your
\hâ\n[lss]uâsubroutine is totally different from
a variable with the same name within your
\hâ\n[lss]uâmain program. Variables which are
known everywhere within your program are
\hâ\n[lss]uâcalled global in contrast.
\hâ\n[lss]uâDeclaring
variables within the subroutine as local helps to avoid hard
to find
\hâ\n[lss]uâbugs; therefore local variables
should be used whenever possible.
\hâ\n[lss]uâNote, that the parameters of your subroutines are always local.
\hâ\n[lss]uâAs
you may see from the example, local arrays may be created
without using the
\hâ\n[lss]uâkeyword dim (which is required only
for global arrays).
\hâ\n[lss]uâExample
\hâ\n[lss]uâa=1
\hâ\n[lss]uâb=1
\hâ\n[lss]uâprint a,b
\hâ\n[lss]uâfoo()
\hâ\n[lss]uâprint a,b
\hâ\n[lss]uâsub
foo()
\hâ\n[lss]uâlocal a
\hâ\n[lss]uâa=2
\hâ\n[lss]uâb=2
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example demonstrates the difference between local and global
variables; it
\hâ\n[lss]uâproduces this output:
\hâ\n[lss]uâ1
1
\hâ\n[lss]uâ1 2
\hâ\n[lss]uâAs
you may see, the content of the global variable a is
unchanged after the
\hâ\n[lss]uâsubroutine foo; this is because the
assignment a=2 within the subroutine
\hâ\n[lss]uâaffects the local variable a only
and not the global one. However, the variable
\hâ\n[lss]uâb is never declared local and
therefore the subroutine changes the global
\hâ\n[lss]uâvariable, which is reflected in the
output of the second print-statement.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub, static, dim
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâlog() ? compute the natural logarithm
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=log(x)
\hâ\n[lss]uâa=log(x,base)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
log-function computes the logarithm of its first argument.
The optional
\hâ\n[lss]uâsecond argument gives the base for
the logarithm; if this second argument is
\hâ\n[lss]uâomitted, the euler-constant 2.71828?
will be taken as the base.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâfor x=10 to 190 step 10:for y=10 to
190 step 10
\hâ\n[lss]uâr=3*log(1+x,1+y)
\hâ\n[lss]uâif (r>10) r=10
\hâ\n[lss]uâif (r<1) r=1
\hâ\n[lss]uâfill circle x,y,r
\hâ\n[lss]uânext y:next x
\hâ\n[lss]uâThis draws another nice plot.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâexp
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâloop ? marks the end of an infinite loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdo
\hâ\n[lss]uâ?
\hâ\n[lss]uâloop
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
loop-command marks the ends of a loop (which is started by
do), wherein all
\hâ\n[lss]uâstatements within the loop are
repeated forever. In this respect the do
\hâ\n[lss]uâloop-loop is infinite, however, you
may leave it anytime via break or goto.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Hello, I will throw dice, until I get a 2 ..."
\hâ\n[lss]uâdo
\hâ\n[lss]uâr=int(ran(6))+1
\hâ\n[lss]uâprint r
\hâ\n[lss]uâif (r=2) break
\hâ\n[lss]uâloop
\hâ\n[lss]uâSee also
\hâ\n[lss]uâdo, for, repeat, while, break
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâlower$() ? convert a string to lower case
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâl$=lower$(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
lower$-function accepts a single string-argument and
converts it to all
\hâ\n[lss]uâlower case.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a password: " a$
\hâ\n[lss]uâif (a$=lower$(a$)) error "Your
password is NOT mixed case !"
\hâ\n[lss]uâThis example prompts for a password and checks, if it is really lower case.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâupper$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâltrim$() ? trim spaces at the left end of a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=ltrim$(b$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
ltrim$-function removes all whitespace from the left end of
a string and
\hâ\n[lss]uâreturns the result.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please answer âyesâ or ânoâ :
" a$
\hâ\n[lss]uâa$=lower$(ltrim$(rtrim$(a$)))
\hâ\n[lss]uâif (len(a$)>0 and
a$=left$("yes",len(a$))) then
\hâ\n[lss]uâprint "Yes ..."
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "No ..."
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis
example prompts for an answer and removes any spaces, which
might precede
\hâ\n[lss]uâthe input; therefore it is even
prepared for the (albeit somewhat pathological
\hâ\n[lss]uâcase, that the user first hits space
before entering his answer.
\hâ\n[lss]uâSee also
\hâ\n[lss]uârtrim$, trim$
\hâ\n[lss]uâM
\hâ\n[lss]uâmax()
? return the larger of its two arguments
\hâ\n[lss]uâmid$() ? return (or change)
characters from within a string
\hâ\n[lss]uâmin() ? return the smaller of its
two arguments
\hâ\n[lss]uâmod ? compute the remainder of a
division
\hâ\n[lss]uâmouseb ? extract the state of the
mousebuttons from a string returned by inkey$
\hâ\n[lss]uâmousemod ? return the state of the
modifier keys during a mouseclick
\hâ\n[lss]uâmousex ? return the x-position of a
mouseclick
\hâ\n[lss]uâmousey ? return the y-position of a
mouseclick
\hâ\n[lss]uâName
\hâ\n[lss]uâmax() ? return the larger of its two arguments
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint max(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâReturn the maximum of its two arguments.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdim
m(10)
\hâ\n[lss]uâfor a=1 to 1000
\hâ\n[lss]uâm=0
\hâ\n[lss]uâFor b=1 to 10
\hâ\n[lss]uâm=max(m,ran(10))
\hâ\n[lss]uânext b
\hâ\n[lss]uâm(m)=m(m)+1
\hâ\n[lss]uânext a
\hâ\n[lss]uâfor
a=1 to 9
\hâ\n[lss]uâprint a,": ",m(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâWithin
the inner for-loop (the one with the loop-variable b), the
example
\hâ\n[lss]uâcomputes the maximum of 10 random
numbers. The outer loop (with the loop
\hâ\n[lss]uâvariable a) now repeats this process
1000 times and counts, how often each
\hâ\n[lss]uâmaximum appears. The last loop
finally reports the result.
\hâ\n[lss]uâNow,
the interesting question would be, which will be approached,
when we
\hâ\n[lss]uâincrease the number of iterations
from thousand to infinity. Well, maybe
\hâ\n[lss]uâsomeone could just tell me :-)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâmin
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmid$() ? return (or change) characters from within a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
mid$(a$,2,1)
\hâ\n[lss]uâprint mid$(a$,2)
\hâ\n[lss]uâmid$(a$,5,3)="foo"
\hâ\n[lss]uâmid$(a$,5)="foo"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mid$-function requires three arguments: a string and two
numbers, where the
\hâ\n[lss]uâfirst number specifies a position
within the string and the second one gives
\hâ\n[lss]uâthe number of characters to be
returned; if you omit the second argument, the
\hâ\n[lss]uâmid$-function returns all characters
up to the end of the string.
\hâ\n[lss]uâNote,
that you may assign to the mid$-function, i.e. mid$ may
appear on the
\hâ\n[lss]uâleft hand side of an assignment. In
this way it is possible to change a part of
\hâ\n[lss]uâthe variable used within the
mid$-function. Note, that that way the length of
\hâ\n[lss]uâthe string cannot be changed, i.e.
characters might be overwritten, but not
\hâ\n[lss]uâadded. For an example see below.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a string: " a$
\hâ\n[lss]uâfor a=1 to len(a$)
\hâ\n[lss]uâif
(instr("aeiou",lower$(mid$(a$,a,1))))
mid$(a$,a,1)="e"
\hâ\n[lss]uânext a
\hâ\n[lss]uâprint "When you turn everything
to lower case and"
\hâ\n[lss]uâprint "replace every vowel with
âeâ, your input reads:"
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâThis
example transforms the input string a bit, using the
mid$-function to
\hâ\n[lss]uâretrieve a character from within the
string as well as to change it.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâleft$ and right$.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmin() ? return the smaller of its two arguments
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint min(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâReturn the minimum of its two argument.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdim
m(10)
\hâ\n[lss]uâfor a=1 to 1000
\hâ\n[lss]uâm=min(ran(10),ran(10))
\hâ\n[lss]uâm(m)=m(m)+1
\hâ\n[lss]uânext a
\hâ\n[lss]uâfor
a=1 to 9
\hâ\n[lss]uâprint a,": ",m(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâFor
each iteration of the loop, the lower of two random number
is recorded. The
\hâ\n[lss]uâresult is printed at the end.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâmax
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmod ? compute the remainder of a division
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint mod(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mod-function divides its two arguments and computes the
remainder. Note,
\hâ\n[lss]uâthat a/b-int(a/b) and mod(a,b) are
always equal.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâprint at(10,10) "Please wait
";
\hâ\n[lss]uâp$="-\|/"
\hâ\n[lss]uâfor a=1 to 100
\hâ\n[lss]uârem ... do something lengthy here,
or simply sleep :-)
\hâ\n[lss]uâpause(1)
\hâ\n[lss]uâprint at(22,10) mid$(p$,1+mod(a,4))
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis
example executes some time consuming action within a loop
(in fact, it
\hâ\n[lss]uâsimply sleeps) and gives the user
some indication of progress by displaying a
\hâ\n[lss]uâturning bar (thatâs where the
mod-function comes into play).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâint, frac
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmouseb ? extract the state of the mousebuttons from a string returned by inkey$
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâprint mouseb()
\hâ\n[lss]uâprint mouseb
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint mouseb(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mouseb-function is a helper function for decoding part of
the (rather
\hâ\n[lss]uâcomplicated) strings, which are
returned by the inkey$-function. If a
\hâ\n[lss]uâmousebutton has been pressed, the
mouseb-function returns the number (1,2 or 3)
\hâ\n[lss]uâof the mousebutton, when it is
pressed and returns its negative (-1,-2 or -3),
\hâ\n[lss]uâwhen it is released.
\hâ\n[lss]uâThe
mouseb-function accepts zero or one arguments. A single
argument should be
\hâ\n[lss]uâa string returned by the
inkey$-function; if mouseb is called without any
\hâ\n[lss]uâarguments, it returns the values
from the last call to inkey$, which are stored
\hâ\n[lss]uâimplicitly and internally by
yabasic.
\hâ\n[lss]uâNote
\hâ\n[lss]uâNote
however, that the value returned by the mouseb-function does
not reflect
\hâ\n[lss]uâthe current state of the
mousebuttons. It rather extracts the information from
\hâ\n[lss]uâthe string passed as an argument (or
from the last call to the inkey$-function,
\hâ\n[lss]uâif no argument is passed). So the
value returned by mouseb reflects the state
\hâ\n[lss]uâof the mousebuttons at the time the
inkey$-function has been called; as opposed
\hâ\n[lss]uâto the time the mouseb-function is
called.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint "Please draw lines; press
(and keep it pressed)"
\hâ\n[lss]uâprint "the left mousebutton for
the starting point,"
\hâ\n[lss]uâprint "release it for the
end-point."
\hâ\n[lss]uâdo
\hâ\n[lss]uâif (mouseb(release$)=1)
press$=release$
\hâ\n[lss]uârelease$=inkey$
\hâ\n[lss]uâif (mouseb(release$)=-1) then
\hâ\n[lss]uâline mousex(press$),mousey(press$)
to mousex(release$),mousey(release$)
\hâ\n[lss]uâendif
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
is a maybe the most simplistic line-drawing program
possible, catching
\hâ\n[lss]uâpresses as well as releases of the
first mousebutton.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinkey$, mousex, mousey and mousemod
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmousemod ? return the state of the modifier keys during a mouseclick
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâprint mousemod()
\hâ\n[lss]uâprint mousemod
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint mousemod(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mousemod-function is a helper function for decoding part of
the (rather
\hâ\n[lss]uâcomplicated) strings, which are
returned by the inkey$-function if a
\hâ\n[lss]uâmousebutton has been pressed. It
returns the state of the keyboard modifiers
\hâ\n[lss]uâ(shift, ctrl or alt): If the
shift-key is pressed, mousemod returns 1, for the
\hâ\n[lss]uâalt-key 2 and for the ctrl-key 4. If
more than one key is pressed, the sum of
\hâ\n[lss]uâthese values is returned, e.g.
mousemod returns 5, if shift and ctrl are
\hâ\n[lss]uâpressed simultaneously.
\hâ\n[lss]uâThe
mousemod-function accepts zero or one arguments. A single
argument should
\hâ\n[lss]uâbe a string returned by the
inkey$-function; if mousemod is called without any
\hâ\n[lss]uâarguments, it returns the values
from the last call to inkey$ (which are stored
\hâ\n[lss]uâimplicitly and internally by
yabasic).
\hâ\n[lss]uâNote
\hâ\n[lss]uâPlease see also the Note within the mouseb-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâdo
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâif (left$(a$,2)="MB") then
\hâ\n[lss]uâx=mousex(a$)
\hâ\n[lss]uây=mousey(a$)
\hâ\n[lss]uâif (mousemod(a$)=0) then
\hâ\n[lss]uâcircle x,y,20
\hâ\n[lss]uâelse
\hâ\n[lss]uâfill circle x,y,20
\hâ\n[lss]uâendif
\hâ\n[lss]uâendif
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
program draws a circle, whenever a mousebutton is pressed;
the circles are
\hâ\n[lss]uâfilled, when any modifier is
pressed, and empty if not.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinkey$, mousex, mousey and mouseb
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmousex ? return the x-position of a mouseclick
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâprint mousex()
\hâ\n[lss]uâprint mousex
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint mousex(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mousex-function is a helper function for decoding part of
the (rather
\hâ\n[lss]uâcomplicated) strings, which are
returned by the inkey$-function; It returns the
\hâ\n[lss]uâx-position of the mouse as encoded
within its argument.
\hâ\n[lss]uâThe
mousex-function accepts zero or one arguments. A single
argument should be
\hâ\n[lss]uâa string returned by the
inkey$-function; if mousex is called without any
\hâ\n[lss]uâarguments, it returns the values
from the last call to inkey$ (which are stored
\hâ\n[lss]uâimplicitly and internally by
yabasic).
\hâ\n[lss]uâNote
\hâ\n[lss]uâPlease see also the Note within the mouseb-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâdo
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâif (left$(a$,2)="MB") then
\hâ\n[lss]uâline mousex,0 to mousex,200
\hâ\n[lss]uâendif
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example draws vertical lines at the position, where the
mousebutton has
\hâ\n[lss]uâbeen pressed.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinkey$, mousemod, mousey and mouseb
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâmousey ? return the y-position of a mouseclick
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâinkey$
\hâ\n[lss]uâprint mousey()
\hâ\n[lss]uâprint mousey
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâprint mousey(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
mousey-function is a helper function for decoding part of
the (rather
\hâ\n[lss]uâcomplicated) strings, which are
returned by the inkey$-function. mousey returns
\hâ\n[lss]uâthe y-position of the mouse as
encoded within its argument.
\hâ\n[lss]uâThe
mousey-function accepts zero or one arguments. A single
argument should be
\hâ\n[lss]uâa string returned by the
inkey$-function; if mousey is called without any
\hâ\n[lss]uâarguments, it returns the values
from the last call to inkey$ (which are stored
\hâ\n[lss]uâimplicitly and internally by
yabasic).
\hâ\n[lss]uâNote
\hâ\n[lss]uâPlease see also the Note within the mouseb-function.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâdo
\hâ\n[lss]uâa$=inkey$
\hâ\n[lss]uâif (left$(a$,2)="MB") then
\hâ\n[lss]uâline 0,mousey to 200,mousey
\hâ\n[lss]uâendif
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example draws horizontal lines at the position, where the
mousebutton has
\hâ\n[lss]uâbeen pressed.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinkey$, mousemod, mousex and mouseb
\hâ\n[lss]uâN
\hâ\n[lss]uânew
curve ? start a new curve, that will be drawn with the
line-command
\hâ\n[lss]uânext ? mark the end of a for loop
\hâ\n[lss]uânot ? negate an expression; can be
written as !
\hâ\n[lss]uânumparams ? return the number of
parameters, that have been passed to a
\hâ\n[lss]uâsubroutine
\hâ\n[lss]uâName
\hâ\n[lss]uânew curve ? start a new curve, that will be drawn with the line-command
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uânew
curve
\hâ\n[lss]uâline to x,y
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
new curve-function starts a new sequence of lines, that will
be drawn by
\hâ\n[lss]uârepeated line to-commands.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâellipse(100,50,30,60)
\hâ\n[lss]uâellipse(150,100,60,30)
\hâ\n[lss]uâsub ellipse(x,y,xr,yr)
\hâ\n[lss]uânew curve
\hâ\n[lss]uâfor a=0 to 2*pi step 0.2
\hâ\n[lss]uâline to x+xr*cos(a),y+yr*sin(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâclose curve
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example defines a subroutine ellipse that draws an ellipse.
Within this
\hâ\n[lss]uâsubroutine, the ellipse is drawn as
a sequence of lines started with the new
\hâ\n[lss]uâcurve command and closed with close
curve.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâline, close curve
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uânext ? mark the end of a for loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uânext a
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
next-keyword marks the end of a for-loop. All statements up
to the
\hâ\n[lss]uânext-keyword will be repeated as
specified with the for-clause. Note, that the
\hâ\n[lss]uâname of the variable is optional; so
instead of next a you may write next.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 300000
\hâ\n[lss]uâfor b=1 to 21+20*sin(pi*a/20)
\hâ\n[lss]uâprint "*";
\hâ\n[lss]uânext b
\hâ\n[lss]uâprint
\hâ\n[lss]uâsleep 0.1
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis example simply plots a sine-curve until you fall asleep.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfor
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uânot ? negate an expression; can be written as !
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(not a<b) then ?
\hâ\n[lss]uâbad=!okay
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
keyword not (or ! for short) is mostly used within
conditions (e.g. within
\hâ\n[lss]uâif- or while-statements). There it
is employed to negate the condition or
\hâ\n[lss]uâexpression (i.e. turn TRUE into
FALSE and vice versa)
\hâ\n[lss]uâHowever
not can be used within arithmetic calculations too., simply
because
\hâ\n[lss]uâthere is no difference between
arithmetic and logical expressions.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter three ascending numbers: " a,b,c
\hâ\n[lss]uâif (not (a<b and b<c)) error
" the numbers you have entered are not ascending
..."
\hâ\n[lss]uâSee also
\hâ\n[lss]uâand,or
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uânumparams
? return the number of parameters, that have been passed to
a
\hâ\n[lss]uâsubroutine
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâsub
foo(a,b,c)
\hâ\n[lss]uâif (numparams=1) ?
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâWithin
a subroutine the local variable numparam or numparams
contains the
\hâ\n[lss]uânumber of parameters, that have been
passed to the subroutine. This information
\hâ\n[lss]uâcan be useful, because the
subroutine may have been called with fewer
\hâ\n[lss]uâparameters than actually declared.
The number of values that actually have been
\hâ\n[lss]uâpassed while calling the subroutine,
can be found in numparams.
\hâ\n[lss]uâNote,
that arguments which are used in the definition of a
subroutine but are
\hâ\n[lss]uâleft out during a call to it
(thereby reducing the value of numparams) receive
\hâ\n[lss]uâa value of 0 or "" (empty
string) respectively.
\hâ\n[lss]uâExample
\hâ\n[lss]uâa$="123456789"
\hâ\n[lss]uâprint part$(a$,4)
\hâ\n[lss]uâprint part$(a$,3,7)
\hâ\n[lss]uâsub
part$(a$,f,t)
\hâ\n[lss]uâif (numparams=2) then
\hâ\n[lss]uâreturn mid$(a$,f)
\hâ\n[lss]uâelse
\hâ\n[lss]uâreturn mid$(a$,f,t-f+1)
\hâ\n[lss]uâend if
\hâ\n[lss]uâend sub
\hâ\n[lss]uâWhen
you run this example, it will print 456789 and 34567. Take a
look at the
\hâ\n[lss]uâsubroutine part$, which returns part
of the string which has been passed as an
\hâ\n[lss]uâargument. If (besides the string)
two numbers are passed, they define the
\hâ\n[lss]uâstarting and end position of the
substring, that will be returned. However, if
\hâ\n[lss]uâonly one number is passed, the rest
of the string, starting from this position
\hâ\n[lss]uâwill be returned. Each of these
cases is recognized with the help of the
\hâ\n[lss]uânumparams variable.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub
\hâ\n[lss]uâO
\hâ\n[lss]uâon
gosub ? jump to one of multiple gosub-targets
\hâ\n[lss]uâon goto ? jump to one of many
goto-targets
\hâ\n[lss]uâon interrupt ? change reaction on
keyboard interrupts
\hâ\n[lss]uâopen ? open a file
\hâ\n[lss]uâopen printer ? open printer for
printing graphics
\hâ\n[lss]uâopen window ? open a graphic window
\hâ\n[lss]uâlogical or ? logical or, used in
conditions
\hâ\n[lss]uâor() ? arithmetic or, used for
bit-operations
\hâ\n[lss]uâName
\hâ\n[lss]uâon goto ? jump to one of multiple gosub-targets
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâon
a gosub foo,bar,baz
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel
bar
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel
baz
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
on gosub statement uses its numeric argument (the one
between on and gosub)
\hâ\n[lss]uâto select an element from the list
of labels, which follows after the
\hâ\n[lss]uâgosub-keyword: If the number is 1,
the program does a gosub to the first label;
\hâ\n[lss]uâif the number is 2, to the second
and, so on. if the number is zero or less,
\hâ\n[lss]uâthe program continues at the
position of the first label; if the number is
\hâ\n[lss]uâlarger than the total count of
labels, the execution continues at the position
\hâ\n[lss]uâof the last label; i.e. the first
and last label in the list constitute some
\hâ\n[lss]uâkind of fallback-slot.
\hâ\n[lss]uâNote,
that the on gosub-command can no longer be considered state
of the art;
\hâ\n[lss]uâpeople (not me !) may even start to
mock you, if you use it.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uâprint "Please enter a number
between 1 and 3: "
\hâ\n[lss]uâprint
\hâ\n[lss]uâinput "Your choice " a
\hâ\n[lss]uâon a gosub bad,one,two,three,bad
\hâ\n[lss]uâloop
\hâ\n[lss]uâlabel
bad
\hâ\n[lss]uâprint "No. Please between 1 and
3"
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel
one
\hâ\n[lss]uâprint "one"
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel
two
\hâ\n[lss]uâprint "two"
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel
three
\hâ\n[lss]uâprint "three"
\hâ\n[lss]uâreturn
\hâ\n[lss]uâNote,
how invalid input (a number less than 1, or larger than 3)
is
\hâ\n[lss]uâautomatically detected.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgoto, on gosub/function>
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâon goto ? jump to one of many goto-targets
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâon
a goto foo,bar,baz
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel bar
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel baz
\hâ\n[lss]uâ?
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
on goto statement uses its numeric argument (the one between
on and goto to
\hâ\n[lss]uâselect an element from the list of
labels, which follows after the
\hâ\n[lss]uâgoto-keyword: If the number is 1,
the execution continues at the first label;
\hâ\n[lss]uâif the number is 2, at the second,
and so on. if the number is zero or less,
\hâ\n[lss]uâthe program continues at the
position of the first label; if the number is
\hâ\n[lss]uâlarger than the total count of
labels, the execution continues at the position
\hâ\n[lss]uâof the last label; i.e. the first
and last label in the list constitute some
\hâ\n[lss]uâkind of fallback-slot.
\hâ\n[lss]uâNote,
that (unlike the goto-command) the on goto-command can no
longer be
\hâ\n[lss]uâconsidered state of the art; people
may (not me !) even start to mock you, if
\hâ\n[lss]uâyou use it.
\hâ\n[lss]uâExample
\hâ\n[lss]uâlabel
over
\hâ\n[lss]uâprint "Please Select one of
these choices: "
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint " 1 -- show time"
\hâ\n[lss]uâprint " 2 -- show date"
\hâ\n[lss]uâprint " 3 -- exit"
\hâ\n[lss]uâprint
\hâ\n[lss]uâinput "Your choice " a
\hâ\n[lss]uâon a goto
over,show_time,show_date,terminate,over
\hâ\n[lss]uâlabel
show_time
\hâ\n[lss]uâprint time$()
\hâ\n[lss]uâgoto over
\hâ\n[lss]uâlabel
show_date
\hâ\n[lss]uâprint date$()
\hâ\n[lss]uâgoto over
\hâ\n[lss]uâlabel
terminate
\hâ\n[lss]uâexit
\hâ\n[lss]uâNote,
how invalid input (a number less than 1, or larger than 3)
is
\hâ\n[lss]uâautomatically detected; in such a
case the question is simply issued again.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgoto, on gosub/function>
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâon interrupt ? change reaction on keyboard interrupts
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâon
interrupt break
\hâ\n[lss]uâ?
\hâ\n[lss]uâon interrupt continue
\hâ\n[lss]uâDescription
\hâ\n[lss]uâWith
the on interrupt-command you may change the way, how yabasic
reacts on a
\hâ\n[lss]uâkeyboard interrupt; it comes in two
variants: on interrupt break and on
\hâ\n[lss]uâinterrupt continue. A keyboard
interrupt is produced, if you press ctrl-C on
\hâ\n[lss]uâyour keyboard; normally (and
certainly after you have called on interrupt
\hâ\n[lss]uâbreak), yabasic will terminate with
an error message. However after the command
\hâ\n[lss]uâon interrupt continue yabasic
ignores any keyboard interrupt. This may be
\hâ\n[lss]uâuseful, if you do not want your
program being interruptible during certain
\hâ\n[lss]uâcritical operations (e.g. updating
of files).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Please stand by while writing a file with random data
..."
\hâ\n[lss]uâon interrupt continue
\hâ\n[lss]uâopen "random.data" for
writing as #1
\hâ\n[lss]uâfor a=1 to 100
\hâ\n[lss]uâprint #1 ran(100)
\hâ\n[lss]uâprint a," percent done."
\hâ\n[lss]uâsleep 1
\hâ\n[lss]uânext a
\hâ\n[lss]uâclose #1
\hâ\n[lss]uâon interrupt continue
\hâ\n[lss]uâThis
program writes a file with 100 random numbers. The on
interrupt continue
\hâ\n[lss]uâcommand insures, that the program
will not be terminated on a keyboard
\hâ\n[lss]uâinterrupt and the file will be
written entirely in any case. The sleep-command
\hâ\n[lss]uâjust stretches the process
artificially to give you a chance to try a ctrl-C.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâThere is no related command.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâopen ? open a file
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
a,"file","r"
\hâ\n[lss]uâopen
#a,"file","w"
\hâ\n[lss]uâopen #a,printer
\hâ\n[lss]uâopen "file" for reading as
a
\hâ\n[lss]uâopen "file" for writing as
#a
\hâ\n[lss]uâa=open("file")
\hâ\n[lss]uâa=open("file","r")
\hâ\n[lss]uâif (open(a,"file")) ?
\hâ\n[lss]uâif
(open(a,"file","w")) ?
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
open-command opens a file for reading or writing or a
printer for printing
\hâ\n[lss]uâtext. open comes in a wide variety
of ways; it requires these arguments:
\hâ\n[lss]uâfilenumber
\hâ\n[lss]uâIn
the synopsis this is a or #a. In yabasic each file is
associated with a
\hâ\n[lss]uânumber between 1 and a maximum
value, which depends on the operating
\hâ\n[lss]uâsystem. For historical reasons the
filenumber can be preceded by a hash (â#
\hâ\n[lss]uââ). Note, that specifying a
filenumber is optional; if it is omitted, the
\hâ\n[lss]uâopen-function will return a
filenumber, which should then be stored in a
\hâ\n[lss]uâvariable for later reference. This
filenumber can be a simple number or an
\hâ\n[lss]uâarbitrary complex arithmetic
expression, in which case braces might be
\hâ\n[lss]uânecessary to save yabasic from
getting confused.
\hâ\n[lss]uâfilename
\hâ\n[lss]uâIn
the synopsis above this is "file". This string
specifies the name of the
\hâ\n[lss]uâfile to open (note the important
caveat on specifying these filenames).
\hâ\n[lss]uâaccessmode
\hâ\n[lss]uâIn
the synopsis this is "r", "w", for
reading or for writing. This string
\hâ\n[lss]uâor clause specifies the mode in
which the file is opened; it may be one of:
\hâ\n[lss]uâ"r"
\hâ\n[lss]uâOpen
the file for reading (may also be written as for reading).
If the
\hâ\n[lss]uâfile does not exist, the command
will fail. This mode is the default,
\hâ\n[lss]uâi.e. if no mode is specified with
the open-command, the file will be
\hâ\n[lss]uâopened with this mode.
\hâ\n[lss]uâ"w"
\hâ\n[lss]uâOpen
the file for writing (may also be written as for writing).
If the
\hâ\n[lss]uâfile does not exist, it will be
created.
\hâ\n[lss]uâ"a"
\hâ\n[lss]uâOpen
the file for appending, i.e. what you write to the file will
be
\hâ\n[lss]uâappended after its initial contents.
If the file does not exist, it
\hâ\n[lss]uâwill be created.
\hâ\n[lss]uâ"b"
\hâ\n[lss]uâThis
letter may not appear alone, but may be combined with the
other
\hâ\n[lss]uâletters (e.g. "rb") to
open a file in binary mode (as opposed to text
\hâ\n[lss]uâmode).
\hâ\n[lss]uâAs
you may see from the synopsis, the open-command may either
be called as a
\hâ\n[lss]uâcommand (without braces) or as a
function (with braces). If called as a
\hâ\n[lss]uâfunction, it will return the
filenumber or zero if the operation fails.
\hâ\n[lss]uâTherefore the open-function may be
used within the condition of an
\hâ\n[lss]uâif-statement.
\hâ\n[lss]uâIf
the open-command fails, you may use peek("error")
to retrieve the exact
\hâ\n[lss]uânature of the error.
\hâ\n[lss]uâFurthermore
note, that there is another, somewhat separate usage of the
\hâ\n[lss]uâopen-command; if you specify the
bareword printer instead of a filename, the
\hâ\n[lss]uâcommand opens a printer for printing
text. Every text (and only text) you print
\hâ\n[lss]uâto this file will appear on your
printer. Note, that this is very different
\hâ\n[lss]uâfrom printing graphics, as can be
done with open printer.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
"foo.bar" for writing as #1
\hâ\n[lss]uâprint #1 "Hallo !"
\hâ\n[lss]uâclose #1
\hâ\n[lss]uâif (not open(1,"foo.bar"))
error "Could not open âfoo.barâ for
reading"
\hâ\n[lss]uâwhile(not eof(1))
\hâ\n[lss]uâline input #1 a$
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâwend
\hâ\n[lss]uâThis
example simply opens the file foo.bar, writes a single line,
reopens it
\hâ\n[lss]uâand reads its contents again.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclose, print, peek, peek("error") and open printer
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâopen printer ? open printer for printing graphics
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
printer
\hâ\n[lss]uâopen printer "file"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
open printer-command opens a printer for printing graphics.
The command
\hâ\n[lss]uârequires, that a graphic window has
been opened before. Everything that is
\hâ\n[lss]uâdrawn into this window will then be
sent to the printer too.
\hâ\n[lss]uâA
new piece of paper may be started with the clear
window-command; the final
\hâ\n[lss]uâ(or only) page will appear after the
close printer-command.
\hâ\n[lss]uâNote,
that you may specify a filename with open printer; in that
case the
\hâ\n[lss]uâprintout will be sent to a filename
instead to a printer. Your program or the
\hâ\n[lss]uâuser will be responsible for sending
this file to the printer afterwards.
\hâ\n[lss]uâIf
you use yabasic under Unix, you will need a postscript
printer (because
\hâ\n[lss]uâyabasic produces postscript output).
Alternatively you may use ghostscript to
\hâ\n[lss]uâtransform the postscript file into a
form suitable for your printer; but that
\hâ\n[lss]uâis beyond the responsibility of
yabasic.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâopen printer
\hâ\n[lss]uâline 0,0 to 200,200
\hâ\n[lss]uâtext 100,100,"Hallo"
\hâ\n[lss]uâclose window
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâThis
example will open a window, draw a line and print some text
within;
\hâ\n[lss]uâeverything will appear on your
printer too.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclose printer
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâopen window ? open a graphic window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window x,y
\hâ\n[lss]uâopen window x,y,"font"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
open window-command opens a window of the specified size.
Only one window
\hâ\n[lss]uâcan be opened at any given moment of
time.
\hâ\n[lss]uâAn
optional third argument specifies a font to be used for any
text within the
\hâ\n[lss]uâwindow. It can however be changed
with any subsequent text-command.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=200 to 400 step 10
\hâ\n[lss]uâopen window a,a
\hâ\n[lss]uâfor b=0 to a
\hâ\n[lss]uâline 0,b to a,b
\hâ\n[lss]uâline b,0 to b,a
\hâ\n[lss]uâsleep 0.1
\hâ\n[lss]uâclose window
\hâ\n[lss]uânext a
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclose window, text
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâor ? logical or, used in conditions
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(a or b) ?
\hâ\n[lss]uâwhile (a or b) ?
\hâ\n[lss]uâDescription
\hâ\n[lss]uâUsed
in conditions (e.g within if or while) to join two
expressions. Returns
\hâ\n[lss]uâtrue, if either its left or its
right or both arguments are true; returns false
\hâ\n[lss]uâotherwise.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a number"
\hâ\n[lss]uâif (a>9 or a<1) print "a
is not between 1 and 9"
\hâ\n[lss]uâSee also
\hâ\n[lss]uâand,not
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâor() ? arithmetic or, used for bit-operations
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=or(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâUsed
to compute the bitwise or of both its argument. Both
arguments are treated
\hâ\n[lss]uâas binary numbers (i.e. a series of
0 and 1); a bit of the resulting value will
\hâ\n[lss]uâthen be 1, if any of its arguments
has 1 at this position in their binary
\hâ\n[lss]uârepresentation.
\hâ\n[lss]uâNote,
that both arguments are silently converted to integer values
and that
\hâ\n[lss]uânegative numbers have their own
binary representation and may lead to
\hâ\n[lss]uâunexpected results when passed to
or.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint or(14,3)
\hâ\n[lss]uâThis
will print 15. This result is clear, if you note, that the
binary
\hâ\n[lss]uârepresentation of 14 and 3 are 1110
and 0011 respectively; this will yield 1111
\hâ\n[lss]uâin binary representation or 15 as
decimal.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâoand, eor and not
\hâ\n[lss]uâP
\hâ\n[lss]uâpause
? pause, sleep, wait for the specified number of seconds
\hâ\n[lss]uâpeek ? retrieve various internal
information
\hâ\n[lss]uâpeek$ ? retrieve various internal
string-information
\hâ\n[lss]uâpi ? a constant with the value
3.14159
\hâ\n[lss]uâpoke ? change selected internals of
yabasic
\hâ\n[lss]uâprint ? Write to terminal or file
\hâ\n[lss]uâprint color ? print with color
\hâ\n[lss]uâprint colour ? see print color
\hâ\n[lss]uâputbit ? draw a rectangle of pixels
encoded within a string into the graphics
\hâ\n[lss]uâwindow
\hâ\n[lss]uâputscreen ? draw a rectangle of
characters into the text terminal
\hâ\n[lss]uâName
\hâ\n[lss]uâpause ? pause, sleep, wait for the specified number of seconds
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâpause 5
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
pause-command has many different names: You may write pause,
sleep or wait
\hâ\n[lss]uâinterchangeably; whatever you write,
yabasic will always do exactly the same.
\hâ\n[lss]uâThe
pause-command will simply wait for the specified number of
seconds. This
\hâ\n[lss]uâmay be a fractional number, so you
may well wait less than a second. However,
\hâ\n[lss]uâif you try to pause for a smaller
and smaller interval (e.g. 0.1 seconds, 0.01
\hâ\n[lss]uâseconds, 0.001 seconds and so on)
you will find that at some point yabasic will
\hâ\n[lss]uânot wait at all. The minimal
interval that can be waited depends on the system
\hâ\n[lss]uâ(Unix, Windows) you are using.
\hâ\n[lss]uâThe
pause-command cannot be interrupted. However, sometimes you
may want the
\hâ\n[lss]uâwait to be interruptible by simply
pressing a key on the keyboard. In such
\hâ\n[lss]uâcases you should consider using the
inkey$-function, with a number of seconds
\hâ\n[lss]uâas an argument).
\hâ\n[lss]uâExample
\hâ\n[lss]uâdeg=0
\hâ\n[lss]uâdo
\hâ\n[lss]uâmaxx=44+40*sin(deg)
\hâ\n[lss]uâfor x=1 to maxx
\hâ\n[lss]uâprint "*";
\hâ\n[lss]uânext x
\hâ\n[lss]uâpause 0.1+(maxx*maxx/(4*84*84))
\hâ\n[lss]uâprint
\hâ\n[lss]uâdeg=deg+0.1
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example draws a sine-curve; due to the pause-statement the
speed of
\hâ\n[lss]uâdrawing varies in the same way as
the speed of a ball might vary, if it would
\hâ\n[lss]uâroll along this curve under the
influence of gravity.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsleep, wait
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâpeek ? retrieve various internal information
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
peek("foo")
\hâ\n[lss]uâa=peek(#1)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
peek-function has many different and mostly unrelated uses.
It is a kind of
\hâ\n[lss]uâgrab-bag for retrieving all kinds of
numerical information, internal to yabasic
\hâ\n[lss]uâ. The meaning of the numbers
returned be the peek-function depends on the
\hâ\n[lss]uâstring or number passed as an
argument.
\hâ\n[lss]uâpeek
always returns a number, however the closely related
peek$-function
\hâ\n[lss]uâexists, which may be used to
retrieve string information from among the
\hâ\n[lss]uâinternals of yabasic. Finally note,
that some of the values which are retrieved
\hâ\n[lss]uâwith peek may even be changed, using
the poke-function.
\hâ\n[lss]uâThere
are two variants of the peek-function: One expects an
integer, positive
\hâ\n[lss]uânumber and is described within the
first entry of the list below. The other
\hâ\n[lss]uâvariant expects one of a well
defined set of strings as described in the second
\hâ\n[lss]uâand all the following entries of the
list below.
\hâ\n[lss]uâpeek(a)
\hâ\n[lss]uâRead a single character from the file a (which must be open of course).
\hâ\n[lss]uâpeek("argument")
\hâ\n[lss]uâReturn
the number of arguments, that have been passed to yabasic at
\hâ\n[lss]uâinvocation time. E.g. if yabasic has
been called like this: yabasic foo.yab
\hâ\n[lss]uâbar baz, then
peek("argument") will return 2. This is because
foo.yab is
\hâ\n[lss]uâtreated as the name of the program
to run, whereas bar and baz are
\hâ\n[lss]uâconsidered arguments to the program,
which are passed on the command line.
\hâ\n[lss]uâNote, that for windows-users, who
tend to click on the icon (as opposed to
\hâ\n[lss]uâstarting yabasic on the command
line), this peekwill mostly return 0.
\hâ\n[lss]uâThe function peek("argument") can be written as peek("arguments") too.
\hâ\n[lss]uâYou
will want to check out the corresponding function
peek$("argument") to
\hâ\n[lss]uâactually retrieve the arguments.
Note, that each call to peek$("argument")
\hâ\n[lss]uâreduces the number returned by
peek("argument").
\hâ\n[lss]uâpeek("error")
\hâ\n[lss]uâReturn
a number specifying the nature of the last error in an open-
or
\hâ\n[lss]uâseek-statement. Normally an error
within an open-statement immediately
\hâ\n[lss]uâterminates your program with an
appropriate error-message, so there is no
\hâ\n[lss]uâchance and no need to learn more
about the nature of the error. However, if
\hâ\n[lss]uâyou use open as a condition (e.g. if
(open(#1,"foo")) ?) the outcome
\hâ\n[lss]uâ(success or failure) of the
open-operation will determine, if the condition
\hâ\n[lss]uâevaluates to true or false. If now
such an operation fails, your program
\hâ\n[lss]uâwill not be terminated and you might
want to learn the reason for failure.
\hâ\n[lss]uâThis reason will be returned by
peek("error") (as a number) or by peek$
\hâ\n[lss]uâ("error") (as a
string)
\hâ\n[lss]uâThe
table below shows the various error codes; the value
returned by peek$
\hâ\n[lss]uâ("error") explains the
nature of the error. Note, that the codes 10,11 and
\hâ\n[lss]uâ12 refer to the seek-command.
\hâ\n[lss]uâTable 7.1. Error codes
\hâ\n[lss]uâ+-------------------------------------------------------------------------+
\hâ\n[lss]uâ| peek |peek$("error")|
Explanation |
\hâ\n[lss]uâ|("error")| | |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| 2 |Stream already|Do not try to
open one and the same filenumber |
\hâ\n[lss]uâ| |in use |twice; rather close it
first. |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| |âxâ is not a |The
optional filemode argument, which may be |
\hâ\n[lss]uâ| 3 |valid filemode|passed to the
open-function, has an invalid |
\hâ\n[lss]uâ| | |value |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| 4 |could not open|The open-call
did not work, no further |
\hâ\n[lss]uâ| |âfooâ |explanation is
available. |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| |reached |You have opened more
files than your operating |
\hâ\n[lss]uâ| 5 |maximum number|system permits.
|
\hâ\n[lss]uâ| |of open files | |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| |cannot open |The commands open
printer and open #1,printer |
\hâ\n[lss]uâ| |printer: |both open a printer
(refer to their description |
\hâ\n[lss]uâ| 6 |already |for the difference).
However, only one can be |
\hâ\n[lss]uâ| |printing |active at a time; if
you try to do both at the |
\hâ\n[lss]uâ| |graphics |same time, you will
receive this error. |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| 7 |could not open|Well, it simply
did not work. |
\hâ\n[lss]uâ| |line printer | |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| 9 |invalid stream|An attempt to
use an invalid (e.g. negative) |
\hâ\n[lss]uâ| |number |stream number; example:
open(-1,"foo") |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| |could not | |
\hâ\n[lss]uâ| 10 |position |seek did not work. |
\hâ\n[lss]uâ| |stream x to | |
\hâ\n[lss]uâ| |byte y | |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| 11 |stream x not |You have tried
to seek within a stream, that has|
\hâ\n[lss]uâ| |open |not been opened yet. |
\hâ\n[lss]uâ|---------+--------------+------------------------------------------------|
\hâ\n[lss]uâ| |seek mode âxâ |The
argument, which has been passed to seek is |
\hâ\n[lss]uâ| 12 |is none of |invalid. |
\hâ\n[lss]uâ| |begin,end,here| |
\hâ\n[lss]uâ+-------------------------------------------------------------------------+
\hâ\n[lss]uâpeek("fontheight")
\hâ\n[lss]uâReturn
the height of the font used within the graphic window. If
none is
\hâ\n[lss]uâopen, this peek will return the
height of the last font used or 10, if no
\hâ\n[lss]uâwindow has been opened yet.
\hâ\n[lss]uâpeek("screenheight")
\hâ\n[lss]uâReturn
the height in characters of the window, wherein yabasic
runs. If you
\hâ\n[lss]uâhave not called clear screen yet,
this peekwill return 0, regardless of the
\hâ\n[lss]uâsize of your terminal.
\hâ\n[lss]uâpeek("screenwidth")
\hâ\n[lss]uâReturn
the width in characters of the window, wherein yabasic runs.
If you
\hâ\n[lss]uâhave not called clear screen yet,
this peekwill return 0, regardless of the
\hâ\n[lss]uâsize of your terminal.
\hâ\n[lss]uâpeek("secondsrunning")
\hâ\n[lss]uâReturn the number of seconds that have passed since the start of yabasic.
\hâ\n[lss]uâpeek("millisrunning")
\hâ\n[lss]uâReturn
the number of milliseconds, that have passed since the start
of
\hâ\n[lss]uâyabasic.
\hâ\n[lss]uâpeek("version")
\hâ\n[lss]uâReturn
the version number of yabasic, e.g. 2.77. See also the
related peek$
\hâ\n[lss]uâ("version"), which returns
nearly the same information (plus the
\hâ\n[lss]uâpatchlevel) as a string, e.g.
"2.77.1".
\hâ\n[lss]uâpeek("winheight")
\hâ\n[lss]uâReturn
the height of the graphic-window in pixels. If none is open,
this
\hâ\n[lss]uâpeek will return the height of the
last window opened or 100, if none has
\hâ\n[lss]uâbeen opened yet.
\hâ\n[lss]uâpeek("winwidth")
\hâ\n[lss]uâReturn
the width of the graphic-window in pixels. If none is open,
this
\hâ\n[lss]uâpeek will return the width of the
last window opened or 100, if none has
\hâ\n[lss]uâbeen opened yet.
\hâ\n[lss]uâpeek("isbound")
\hâ\n[lss]uâReturn
true, if the executing yabasic-program is part of a
standalone
\hâ\n[lss]uâprogram; see the section about
creating a standalone-program for details.
\hâ\n[lss]uâpeek("version")
\hâ\n[lss]uâReturn the version number of yabasic (e.g. 2.72).
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
"foo" for reading as #1
\hâ\n[lss]uâopen "bar" for writing as
#2
\hâ\n[lss]uâwhile(not eof(#1))
\hâ\n[lss]uâpoke #2,chr$(peek(#1));
\hâ\n[lss]uâwend
\hâ\n[lss]uâThis program will copy the file foo byte by byte to bar.
\hâ\n[lss]uâNote,
that each peek does something entirely different, and only
one has been
\hâ\n[lss]uâdemonstrated above. Therefore you
need to make up examples yourself for all the
\hâ\n[lss]uâother peeks.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâpeek$, poke, open
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâpeek$ ? retrieve various internal string-information
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint peek$("foo")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
peek$-function has many different and unrelated uses. It is
a kind of
\hâ\n[lss]uâgrab-bag for retrieving all kinds of
string information, internal to yabasic;
\hâ\n[lss]uâthe exact nature of the strings
returned be the peek$-function depends on the
\hâ\n[lss]uâstring passed as an argument.
\hâ\n[lss]uâpeek$
always returns a string, however the closely related
peek-function
\hâ\n[lss]uâexists, which may be used to
retrieve numerical information from among the
\hâ\n[lss]uâinternals of yabasic. Finally note,
that some of the values which are retrieved
\hâ\n[lss]uâwith peek$ may even be changed,
using the poke-function.
\hâ\n[lss]uâThe following list shows all possible arguments to peek$:
\hâ\n[lss]uâpeek$("infolevel")
\hâ\n[lss]uâReturns
either "debug", "note",
"warning", "error" or "fatal",
depending on
\hâ\n[lss]uâthe current infolevel. This value
can be specified with an option on the
\hâ\n[lss]uâcommand line or changed during the
execution of the program with the
\hâ\n[lss]uâcorresponding poke; however,
normally only the author of yabasic (me !)
\hâ\n[lss]uâwould want to change this from its
default value "warning".
\hâ\n[lss]uâpeek$("textalign")
\hâ\n[lss]uâReturns
one of nine possible strings, specifying the default
alignment of
\hâ\n[lss]uâtext within the graphics-window. The
alignment-string returned by this peek
\hâ\n[lss]uâdescribes, how the text-command
aligns its string-argument with respect to
\hâ\n[lss]uâthe coordinates supplied. However,
this value does not apply, if the
\hâ\n[lss]uâtext-command explicitly specifies an
alignment. Each of these strings is
\hâ\n[lss]uâtwo characters long. The first
character specifies the horizontal alignment
\hâ\n[lss]uâand can be either l, r or c, which
stand for left, right or center. The
\hâ\n[lss]uâsecond character specifies the
vertical alignment and can be one of t, b or
\hâ\n[lss]uâc, which stand for top, bottom or
center respectively.
\hâ\n[lss]uâYou
may change this value with the corresponding command poke
\hâ\n[lss]uâ"textalign",?; the initial
value is lb, which means the top of the left and
\hâ\n[lss]uâthe top edge if the text will be
aligned with the coordinates, that are
\hâ\n[lss]uâspecified within the
text-command.
\hâ\n[lss]uâpeek$("windoworigin")
\hâ\n[lss]uâThis
peek returns a two character string, which specifies the
position of
\hâ\n[lss]uâthe origin of the coordinate system
of the window; this string might be
\hâ\n[lss]uâchanged with the corresponding
command poke "windoworigin",x,y or specified
\hâ\n[lss]uâas the argument of the origin
command; see there for a detailed description
\hâ\n[lss]uâof the string, which might be
returned by this peek.
\hâ\n[lss]uâpeek$("program_name")
\hâ\n[lss]uâReturns
the name of the yabasic-program that is currently executing;
\hâ\n[lss]uâtypically this is the name, that you
have specified on the commandline, but
\hâ\n[lss]uâwithout any path-components. So this
peek$ might return foo.yab. As a
\hâ\n[lss]uâspecial case when yabasic has been
invoked without the name of a program to
\hâ\n[lss]uâbe executed this peek will return
the literal strings standard input or,
\hâ\n[lss]uâwhen also the option -e has been
specified, command line. See also peek$
\hâ\n[lss]uâ("program_file_name") and
peek$("interpreter_path") for related
\hâ\n[lss]uâinformation.
\hâ\n[lss]uâpeek$("program_file_name")
\hâ\n[lss]uâReturns
the full file-name of the yabasic-program that is currently
\hâ\n[lss]uâexecuting; typically this is the
name, that you have specified on the
\hâ\n[lss]uâcommandline, including any
path-components. For the special case, that you
\hâ\n[lss]uâhave bound your yabasic-program with
the interpreter to a single standalone
\hâ\n[lss]uâexecutable, this peek$ will return
its name. See also peek$("program_name")
\hâ\n[lss]uâand
peek$("interpreter_path") for related
information.
\hâ\n[lss]uâpeek$("interpreter_path")
\hâ\n[lss]uâReturn
the full file-name of the yabasic-interpreter that is
currently
\hâ\n[lss]uâexecuting your program; typically
this will end on yabasic or yabasic.exe
\hâ\n[lss]uâdepending on your platform and the
path will be where you installed yabasic
\hâ\n[lss]uâ. For bound programs (see creating a
standalone-program) however, this may
\hâ\n[lss]uâbe different and will include
whatever you specified during the bind
\hâ\n[lss]uâ-command.
\hâ\n[lss]uâSee
also peek$("program_name") and
peek$("program_file_name") for related
\hâ\n[lss]uâinformation. Employing these, it
would be possible for a yabasic-program to
\hâ\n[lss]uâstart itself:
system(peek$("interpreter_path") + " " +
peek$
\hâ\n[lss]uâ("program_file_name")). Of
course, in this simple form this would be a bad
\hâ\n[lss]uâidea, because this would start
concurrent instances of yabasic without end.
\hâ\n[lss]uâpeek$("error")
\hâ\n[lss]uâReturn
a string describing the nature of the last error in an open-
or
\hâ\n[lss]uâseek-statement. See the
corresponding peek("error") for a detailed
\hâ\n[lss]uâdescription.
\hâ\n[lss]uâpeek$("library")
\hâ\n[lss]uâReturn
the name of the library, this statement is contained in. See
the
\hâ\n[lss]uâimport-command for a detailed
description or for more about libraries.
\hâ\n[lss]uâpeek$("version")
\hâ\n[lss]uâVersion
of yabasic as a string; e.g. 2.77.1. See also the related
peek
\hâ\n[lss]uâ("version"), which returns
nearly the same information (minus the
\hâ\n[lss]uâpatchlevel) as a number, e.g.
2.77.
\hâ\n[lss]uâpeek$("os")
\hâ\n[lss]uâThis
peek returns the name of the operating system, where your
program
\hâ\n[lss]uâexecutes. This can be either windows
or unix.
\hâ\n[lss]uâpeek$("font")
\hâ\n[lss]uâReturn
the name of the font, which is used for text within the
graphic
\hâ\n[lss]uâwindow; this value can be specified
as the third argument to the open
\hâ\n[lss]uâwindow-command.
\hâ\n[lss]uâpeek$("env","NAME")
\hâ\n[lss]uâReturn
the environment variable specified by NAME (which may be any
string
\hâ\n[lss]uâexpression). Which kind of
environment variables are available on your
\hâ\n[lss]uâsystem depends, as well as their
meaning, on your system; however typing
\hâ\n[lss]uâenv on the command line will produce
a list (for Windows and Unix alike).
\hâ\n[lss]uâNote, that
peek$("env",...) can be written as
peek$("environment",...) too.
\hâ\n[lss]uâpeek$("argument")
\hâ\n[lss]uâReturn
one of the arguments, that have been passed to yabasic at
invocation
\hâ\n[lss]uâtime (the next call will return the
the second argument, and so on). E.g.
\hâ\n[lss]uâif yabasic has been called like
this: yabasic foo.yab bar baz, then the
\hâ\n[lss]uâfirst call to
peek$("argument") will return bar. This is because
foo.yab is
\hâ\n[lss]uâtreated as the name of the program
to run, whereas bar and baz are
\hâ\n[lss]uâconsidered arguments to this
program, which are passed on the command line.
\hâ\n[lss]uâThe second call to
peek$("argument") will return baz. Note, that for
\hâ\n[lss]uâwindows-users, who tend to click on
the icon (as opposed to starting
\hâ\n[lss]uâyabasic on the command line), this
peekwill mostly return the empty string.
\hâ\n[lss]uâNote, that peek$("argument") can be written as peek$("arguments").
\hâ\n[lss]uâFinally
you will want to check out the corresponding function peek
\hâ\n[lss]uâ("argument").
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"You have supplied these arguments: "
\hâ\n[lss]uâwhile(peek("argument"))
\hâ\n[lss]uâprint
peek("argument"),peek$("argument")
\hâ\n[lss]uâwend
\hâ\n[lss]uâIf
you save this program in a file foo.yab and execute it via
yabasic t.yab a b
\hâ\n[lss]uâc (for windows users: please use the
command line for this), your will get this
\hâ\n[lss]uâoutput:
\hâ\n[lss]uâ3a
\hâ\n[lss]uâ2b
\hâ\n[lss]uâ1c
\hâ\n[lss]uâSee also
\hâ\n[lss]uâpeek, poke, open
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâpi ? a constant with the value 3.14159
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint pi
\hâ\n[lss]uâDescription
\hâ\n[lss]uâpi
is 3.14159265359 (well at least for yabasic); do not try to
assign to pi
\hâ\n[lss]uâ(e.g. pi=22/7) this would not only
be mathematically dubious, but would also
\hâ\n[lss]uâresult in a syntax error.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=0 to 180
\hâ\n[lss]uâprint "The sine of
",a," degrees is ",sin(a*pi/180)
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis program uses pi to transform an angle from degrees into radians.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâeuler
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâpoke ? change selected internals of yabasic
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâpoke
"foo","bar"
\hâ\n[lss]uâpoke "foo",baz
\hâ\n[lss]uâpoke #a,"bar"
\hâ\n[lss]uâpoke #a,baz
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
poke-command may be used to change details of
yabasicâs behaviour. Like the
\hâ\n[lss]uârelated function peek, poke does
many different things, depending on the
\hâ\n[lss]uâarguments supplied.
\hâ\n[lss]uâHere are the different things you can do with poke:
\hâ\n[lss]uâpoke 5,a
\hâ\n[lss]uâWrite
the given byte (a in the example above) to the specified
stream (5#a
\hâ\n[lss]uâin the example).
\hâ\n[lss]uâSee also the related function function peek(1).
\hâ\n[lss]uâpoke "dump","filename.dump"
\hâ\n[lss]uâDump
the internal form of your basic-program to the named file;
this is
\hâ\n[lss]uâonly useful for debugging the
internals of yabasic itself.
\hâ\n[lss]uâThe
second argument ("filename.dump" in the example)
should be the name of
\hâ\n[lss]uâa file, that gets overwritten with
the dump, please be careful.
\hâ\n[lss]uâpoke "fontheight",12
\hâ\n[lss]uâThis
poke changes the default fontheight. This can only have an
effect, if
\hâ\n[lss]uâthe fonts given in the commands text
or open window do not specify a
\hâ\n[lss]uâfontheight on their own.
\hâ\n[lss]uâpoke "font","fontname"
\hâ\n[lss]uâThis
poke specifies the default font. This can only have an
effect, if you
\hâ\n[lss]uâdo not supply a fontname with the
commands text or open window.
\hâ\n[lss]uâpoke "infolevel","debug"
\hâ\n[lss]uâChange
the amount of internal information, that yabasic outputs
during
\hâ\n[lss]uâexecution.
\hâ\n[lss]uâThe
second argument can be either "debug",
"note", "warning", "error" or
\hâ\n[lss]uâ"fatal". However, normally
you will not want to change this from its
\hâ\n[lss]uâdefault value
"warning".
\hâ\n[lss]uâSee also the related peek$("infolevel").
\hâ\n[lss]uâpoke "random_seed",42
\hâ\n[lss]uâSet
the seed for the random number generator; if you do this,
the ran
\hâ\n[lss]uâ-function will return the same
sequence of numbers every time the program
\hâ\n[lss]uâis started.
\hâ\n[lss]uâpoke "stdout","some text"
\hâ\n[lss]uâSend
the given text to standard output. Normally one would use
print for
\hâ\n[lss]uâthis purpose; however, sending e.g.
control characters to your terminal is
\hâ\n[lss]uâeasier with this poke.
\hâ\n[lss]uâpoke "textalign","cc"
\hâ\n[lss]uâThis
poke changes the default alignment of text with respect to
the
\hâ\n[lss]uâcoordinates supplied within the
text-command. However, this value does not
\hâ\n[lss]uâapply, if the text-command
explicitly specifies an alignment. The second
\hâ\n[lss]uâargument ("cc" in the
example) must always be two characters long; the
\hâ\n[lss]uâfirst character can be one of l
(left), r (right) or c (center); the second
\hâ\n[lss]uâcharacter can be either t (top), b
(bottom) or c (center); see the
\hâ\n[lss]uâcorresponding
peek$("textalign") for a detailed description of
this
\hâ\n[lss]uâargument.
\hâ\n[lss]uâpoke "windoworigin","lt"
\hâ\n[lss]uâThis
poke moves the origin of the coordinate system of the window
to the
\hâ\n[lss]uâspecified position. The second
argument ("lt" in the example) must always
\hâ\n[lss]uâbe two characters long; the first
character can be one of l (left), r (
\hâ\n[lss]uâright) or c (center); the second
character can be either t (top), b (bottom
\hâ\n[lss]uâ) or c (center). Together those two
characters specify the new position of
\hâ\n[lss]uâthe coordinate-origin. See the
corresponding peek$("windoworigin") for a
\hâ\n[lss]uâmore in depth description of this
argument.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Hello, now you will see, how much work"
\hâ\n[lss]uâprint "a simple for-loop
involves ..."
\hâ\n[lss]uâinput "Please press return
" a$
\hâ\n[lss]uâpoke
"infolevel","debug"
\hâ\n[lss]uâfor a=1 to 10:next a
\hâ\n[lss]uâThis
example only demonstrates one of the many pokes, which are
described
\hâ\n[lss]uâabove: The program switches the
infolevel to debug, which makes yabasic produce
\hâ\n[lss]uâa lot of debug-messages during the
subsequent for-loop.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâpeek, peek$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâprint ? Write to terminal or file
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
"foo",a$,b
\hâ\n[lss]uâprint "foo",a$,b;
\hâ\n[lss]uâprint #a "foo",a$
\hâ\n[lss]uâprint #a "foo",a$;
\hâ\n[lss]uâprint foo using "##.###"
\hâ\n[lss]uâprint reverse "foo"
\hâ\n[lss]uâprint at(10,10) a$,b
\hâ\n[lss]uâprint @(10,10) a$,b
\hâ\n[lss]uâprint
color("red","blue") a$,b
\hâ\n[lss]uâprint color("magenta")
a$,b
\hâ\n[lss]uâprint
color("green","yellow") at(5,5) a$,b
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
print-statement outputs strings or characters, either to
your terminal
\hâ\n[lss]uâ(also known as console) or to an
open file.
\hâ\n[lss]uâTo
understand all those uses of the print-statement,
letâs go through the
\hâ\n[lss]uâvarious lines in the synopsis
above:
\hâ\n[lss]uâprint "foo",a$,b
\hâ\n[lss]uâPrint
the string foo as well as the contents of the variables a$
and b onto
\hâ\n[lss]uâthe screen, silently adding a
newline.
\hâ\n[lss]uâprint "foo",a$,b;
\hâ\n[lss]uâ(Note
the trailing semicolon !) This statement does the same as
the one
\hâ\n[lss]uâabove; only the implicit newline is
skipped, which means that the next
\hâ\n[lss]uâprint-statement will append
seamlessly.
\hâ\n[lss]uâprint #a "foo",a$
\hâ\n[lss]uâThis
is the way to write to files. The file with the number a
must be open
\hâ\n[lss]uâalready, an implicit newline is
added. Note the file-number #a, which
\hâ\n[lss]uâstarts with a hash (â#â)
amd is separated from the rest of the statement by
\hâ\n[lss]uâa space only. The file-number
(contained in the variable a) must have been
\hâ\n[lss]uâreturned by a previous
open-statement (e.g. a=open("bar")).
\hâ\n[lss]uâprint #a "foo",a$;
\hâ\n[lss]uâThe same as above, but without the implicit newline.
\hâ\n[lss]uâprint foo using "##.###"
\hâ\n[lss]uâPrint
the number foo with as many digits before and after the
decimal dot
\hâ\n[lss]uâas given by the number of
â#â-signs. See the entries for using and str$
for
\hâ\n[lss]uâa detailed description of this
format.
\hâ\n[lss]uâprint reverse "foo"
\hâ\n[lss]uâAs
all the print-variants to follow, this form of the
print-statement can
\hâ\n[lss]uâonly be issued after clear screen
has been called. The strings and numbers
\hâ\n[lss]uâafter the reverse-clause are simply
printed inverse (compared to the normal
\hâ\n[lss]uâprint-statement).
\hâ\n[lss]uâprint at(10,10) a$,b
\hâ\n[lss]uâPrint
at the specified (x,y)-position. This is only allowed after
clear
\hâ\n[lss]uâscreen has been called. You may want
to query peek$("screenwidth") or peek$
\hâ\n[lss]uâ("screenheight") to learn
the actual size of your screen. You may add a
\hâ\n[lss]uâsemicolon to suppress the implicit
newline.
\hâ\n[lss]uâprint @(10,10) a$,b
\hâ\n[lss]uâThis is exactly the same as above, however, at may be written as @.
\hâ\n[lss]uâprint color("red","blue") at(5,5) a$,b
\hâ\n[lss]uâPrint
with the specified fore- ("red") and background
("blue") color (or
\hâ\n[lss]uâcolour). The possible values are
"black", "white", "red",
"blue", "green",
\hâ\n[lss]uâ"yellow", "cyan"
or "magenta". Again, you need to call clear screen
first
\hâ\n[lss]uâand add a semicolon if you want to
suppress the implicit newline.
\hâ\n[lss]uâprint color("magenta") a$,b
\hâ\n[lss]uâYou may specify the foreground color only.
\hâ\n[lss]uâprint color("green","yellow") a$,b
\hâ\n[lss]uâA
color and a position (in this sequence, not the other way
around) may be
\hâ\n[lss]uâspecified at once.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâcolumns=peek("screenwidth")
\hâ\n[lss]uâlines=peek("screenheight")
\hâ\n[lss]uâdim col$(7)
\hâ\n[lss]uâfor a=0 to 7:read col$(a):next a
\hâ\n[lss]uâdata
"black","white","red","blue","green","yellow","cyan","magenta"
\hâ\n[lss]uâfor
a=0 to 2*pi step 0.1
\hâ\n[lss]uâprint colour(col$(mod(i,8)))
at(columns*(0.8*sin(a)+0.9)/2,lines*(0.8*cos(a)+0.9)/2)
"*"
\hâ\n[lss]uâi=i+1
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis example draws a colored ellipse within the text window.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâat, print color, input, clear screen, using, ;
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâprint color ? print with color
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
color(fore$) text$
\hâ\n[lss]uâprint color(fore$,back$) text$
\hâ\n[lss]uâDescription
\hâ\n[lss]uâNot
a separate command, but part of the print-command; may be
included just
\hâ\n[lss]uâafter print and can only be issued
after clear screen has been executed.
\hâ\n[lss]uâcolor()
takes one or two string-arguments, specifying the color of
the text and
\hâ\n[lss]uâ(optionally) the background.
\hâ\n[lss]uâThe
one or two strings passed to color() can be one of these:
"black", "white",
\hâ\n[lss]uâ"red", "blue",
"green", "yellow", "cyan" and
"magenta" (which can be
\hâ\n[lss]uâabbreviated as "bla",
"whi", "red", "blu",
"gre", "yel", "cya" and
"mag"
\hâ\n[lss]uârespectively).
\hâ\n[lss]uâcolor() can only be used, if clear scren has been issued at least once.
\hâ\n[lss]uâNote, that color() can be written as colour() too.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâdim col$(7):for a=0 to 7:read
col$(a):next a
\hâ\n[lss]uâdo
\hâ\n[lss]uâprint
color(col$(ran(7)),col$(ran(7))) " Hallo ";
\hâ\n[lss]uâpause 0.01
\hâ\n[lss]uâloop
\hâ\n[lss]uâdata
"black","white","red","blue"
\hâ\n[lss]uâdata
"green","yellow","cyan","magenta"
\hâ\n[lss]uâThis prints the word " Hallo " in all colors across your screen.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâprint, clear screen, at
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâprint colour ? see print color
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
colour(fore$) text$
\hâ\n[lss]uâprint colour(fore$,back$) text$
\hâ\n[lss]uâSee also
\hâ\n[lss]uâcolor
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâputbit
? draw a rectangle of pixels encoded within a string into
the graphics
\hâ\n[lss]uâwindow
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâ?
\hâ\n[lss]uâa$=getbit(20,20,50,50)
\hâ\n[lss]uâ?
\hâ\n[lss]uâputbit a$,30,30
\hâ\n[lss]uâputbit a$ to 30,30
\hâ\n[lss]uâputbit a$,30,30,"or"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
putbit-command is the counterpart of the getbit$-function.
putbit requires
\hâ\n[lss]uâa string as returned by the
getbit-function. Such a string contains a rectangle
\hâ\n[lss]uâfrom the graphic window; the
putbit-function puts such a rectangular region
\hâ\n[lss]uâback into the graphic-window.
\hâ\n[lss]uâNote,
that the putbit-command currently accepts a fourth argument.
However only
\hâ\n[lss]uâthe string value "or" is
supported here. The effect is, that only those pixel,
\hâ\n[lss]uâwhich are set in the string will be
set in the graphic window. Those pixels,
\hâ\n[lss]uâwhich are not set in the string,
will not change in the window (as opposed to
\hâ\n[lss]uâbeing cleared).
\hâ\n[lss]uâExample
\hâ\n[lss]uâc$="rgb 21,21:0000000000000000000000000000000000000000000000000000000000000032c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c8c8ff000032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
\hâ\n[lss]uâopen window 200,200
\hâ\n[lss]uâdo
\hâ\n[lss]uâx=ran(220)-10
\hâ\n[lss]uây=ran(220)-10
\hâ\n[lss]uâputbit
c$,x,y,"transparent"
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
program uses a precanned string (containing the image of a
blue circle
\hâ\n[lss]uâwith a yellow centre) and draws it
repeatedly into the graphic-window. The mode
\hâ\n[lss]uâ"transparent" ensures,
that no pixels will be cleared.
\hâ\n[lss]uâThere
are two possible values for the third argument of putbit.
Both modes
\hâ\n[lss]uâdiffer in the way, they replace (or
not) any pixels from the window with pixels
\hâ\n[lss]uâfrom the bitmap having the
background colour.
\hâ\n[lss]uâtransparent or t
\hâ\n[lss]uâWith
this mode the pixels from the window will be kept, if the
bitmap
\hâ\n[lss]uâcontains pixels with background
colour at this position; i.e. the bitmap is
\hâ\n[lss]uâtransparent
\hâ\n[lss]uâsolid or s
\hâ\n[lss]uâWith
this mode the pixels from the window will be overpainted
with the
\hâ\n[lss]uâpixels from the bitmap in any case;
i.e. the bitmap is solid
\hâ\n[lss]uâIf you omit this argument, the default transparent applies.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgetbit$, open window
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâputscreen ? draw a rectangle of characters into the text terminal
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâ?
\hâ\n[lss]uâa$=getscreen$(5,5,10,10)
\hâ\n[lss]uâ?
\hâ\n[lss]uâputscreen a$,7,7
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
putscreen-command is the counterpart of the
getscreen$-function. putscreen
\hâ\n[lss]uârequires a string as returned by the
getscreen-function. Such a string contains
\hâ\n[lss]uâa rectangular detail from the
terminal; the putscreen-function puts such a
\hâ\n[lss]uâregion back into the
terminal-window.
\hâ\n[lss]uâNote, that clear screen must have been called before.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâfor a=1 to 200
\hâ\n[lss]uâprint color("red")
"Hallo !";
\hâ\n[lss]uâprint color("blue")
"Welt !";
\hâ\n[lss]uânext a
\hâ\n[lss]uâr$=getscreen$(0,0,20,20)
\hâ\n[lss]uâfor x=0 to 60
\hâ\n[lss]uâputscreen r$,x,0
\hâ\n[lss]uâsleep 0.1
\hâ\n[lss]uânext x
\hâ\n[lss]uâThis
example prints the string "Hallo !Welt !" all over
the screen and then
\hâ\n[lss]uâmoves a rectangle from one side to
the other.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâgetscreen$, clear screen
\hâ\n[lss]uâR
\hâ\n[lss]uâran()
? return a random number
\hâ\n[lss]uâread ? read data from
data-statements
\hâ\n[lss]uârectangle ? draw a rectangle
\hâ\n[lss]uâredim ? create an array prior to its
first use. A synonym for dim
\hâ\n[lss]uârem ? start a comment
\hâ\n[lss]uârepeat ? start a repeat-loop
\hâ\n[lss]uârestore ? reposition the
data-pointer
\hâ\n[lss]uâreturn ? return from a subroutine or
a gosub
\hâ\n[lss]uâreverse ? print reverse (background
and foreground colors exchanged)
\hâ\n[lss]uâright$() ? return (or change) the
right end of a string
\hâ\n[lss]uârinstr() ? find the rightmost
occurrence of one string within the other
\hâ\n[lss]uârtrim$() ? trim spaces at the right
end of a string
\hâ\n[lss]uâName
\hâ\n[lss]uâran() ? return a random number
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
ran()
\hâ\n[lss]uâx=ran(y)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
ran-function returns a random number. If no argument is
given, the number
\hâ\n[lss]uâreturned is in the range from 0 to
1; where only 0 is a possible value; 1 will
\hâ\n[lss]uânever be returned. If an argument is
supplied, the number returned will be in
\hâ\n[lss]uâthe range from 0 up to this
argument, whereas this argument itself is not a
\hâ\n[lss]uâpossible return value. Regardless of
the range, ran is guaranteed to have
\hâ\n[lss]uâexactly 2**30 different return
values.
\hâ\n[lss]uâIf
you call ran multiple times during your program, the
sequence of random
\hâ\n[lss]uânumbers will be different each time
you invoke your program; however, if, e.g.
\hâ\n[lss]uâfor testing you prefer to always
have the same sequence of random numbers you
\hâ\n[lss]uâmay issue poke
"random_seed",123.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâc=peek("screenwidth")-1
\hâ\n[lss]uâl=peek("screenheight")
\hâ\n[lss]uâdim
col$(8)
\hâ\n[lss]uâfor a=0 to 7:read col$(a):next a
\hâ\n[lss]uâdata
"black","white","red","blue","green","yellow","cyan","magenta"
\hâ\n[lss]uâdo
\hâ\n[lss]uâx=ran(c)
\hâ\n[lss]uây=l-ran(l*exp(-32*((x/c-1/2)**2)))
\hâ\n[lss]uâi=i+1
\hâ\n[lss]uâprint color(col$(mod(i,8))) at(x,y)
"*";
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis example will print a colored bell-curve.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâint
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâread ? read data from data-statements
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâread
a$,a
\hâ\n[lss]uâ?
\hâ\n[lss]uâdata "Hello !",7
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
read-statement retrieves literal data, which is stored
within
\hâ\n[lss]uâdata-statements elsewhere in your
program.
\hâ\n[lss]uâExample
\hâ\n[lss]uâread
num
\hâ\n[lss]uâdim col$(num)
\hâ\n[lss]uâfor a=1 to num:read col$(a):next a
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint "These are the colours
known to yabasic:\n"
\hâ\n[lss]uâfor a=1 to num
\hâ\n[lss]uâprint colour(col$(a)) col$(a)
\hâ\n[lss]uânext a
\hâ\n[lss]uâdata
8,"black","white","red","blue"
\hâ\n[lss]uâdata
"green","yellow","cyan","magenta"
\hâ\n[lss]uâThis
program prints the names of the colors known to yabasic in
those very
\hâ\n[lss]uâcolors.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâdata, restore
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârectangle ? draw a rectangle
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uârectangle 10,10 to 90,90
\hâ\n[lss]uârectangle 20,20,80,80
\hâ\n[lss]uârect 20,20,80,80
\hâ\n[lss]uâbox 30,30,70,70
\hâ\n[lss]uâclear rectangle 30,30,70,70
\hâ\n[lss]uâfill rectangle 40,40,60,60
\hâ\n[lss]uâclear fill rectangle 60,60,40,40
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
rectangle-command (also known as box or rect, for short)
draws a rectangle;
\hâ\n[lss]uâit accepts four parameters: The x-
and y-coordinates of two facing corners of
\hâ\n[lss]uâthe rectangle. With the optional
clauses clear and fill (which may appear
\hâ\n[lss]uâtogether and in any sequence) the
rectangle can be cleared and filled
\hâ\n[lss]uârespectively.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâc=1
\hâ\n[lss]uâdo
\hâ\n[lss]uâfor phi=0 to pi step 0.1
\hâ\n[lss]uâif (c) then
\hâ\n[lss]uârectangle
100+100*sin(phi),100+100*cos(phi) to
100-100*sin(phi),100-100*cos(phi)
\hâ\n[lss]uâelse
\hâ\n[lss]uâclear rectangle
100+100*sin(phi),100+100*cos(phi) to
100-100*sin(phi),100-100*cos(phi)
\hâ\n[lss]uâendif
\hâ\n[lss]uâsleep 0.1
\hâ\n[lss]uânext phi
\hâ\n[lss]uâc=not c
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example draws a nice animated pattern; watch it for a couple
of hours, to
\hâ\n[lss]uâsee how it develops.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, open printer, line, circle, triangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâredim ? create an array prior to its first use. A synonym for dim
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâSee the dim-command.
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
redim-command does exactly the same as the dim-command; it
is just a
\hâ\n[lss]uâsynonym. redim has been around in
older versions of basic (not even yabasic)
\hâ\n[lss]uâfor many years; therefore it is
supported in yabasic for compatibility reasons.
\hâ\n[lss]uâPlease refer to the entry for the dim-command for further information.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârem ? start a comment
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uârem
Hey, this is a comment
\hâ\n[lss]uâ# the hash-sign too (at beginning of
line)
\hâ\n[lss]uâ// even the double slash
\hâ\n[lss]uââ and the single quote (at
beginning of line)
\hâ\n[lss]uâprint "Not a comment" #
This is an error !!
\hâ\n[lss]uâprint "Not a comment"://
But this is again a valid comment
\hâ\n[lss]uâprint "Not a comment" //
even this.
\hâ\n[lss]uâprint "Not a comment" rem
and this !
\hâ\n[lss]uâDescription
\hâ\n[lss]uârem
introduces a comment (like # or //), that extends up to the
end of the
\hâ\n[lss]uâline.
\hâ\n[lss]uâThose
comments do not even need a colon (â:â) in front
of them; they (rem, #, â
\hâ\n[lss]uâ(single quite) and //) all behave
alike except for # and â, which may only
\hâ\n[lss]uâappear at the very beginning of a
line; therefore the fourth example in the
\hâ\n[lss]uâsynopsis above (print "Not a
comment" # This is an error !!) is indeed an
\hâ\n[lss]uâerror.
\hâ\n[lss]uâNote,
that rem is an abbreviation for remark. remark however is
not a valid
\hâ\n[lss]uâcommand in yabasic.
\hâ\n[lss]uâFinally
note, that a comment introduced with â#â may
have a special meaning
\hâ\n[lss]uâunder unix; see the entry for # for
details.
\hâ\n[lss]uâExample
\hâ\n[lss]uâ#
\hâ\n[lss]uârem comments on data structures
\hâ\n[lss]uâ# are more useful than
\hâ\n[lss]uâ// comments on algorithms.
\hâ\n[lss]uârem
\hâ\n[lss]uâThis program does nothing, but in a splendid and well commented way.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâ#, //
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârepeat ? start a repeat-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uârepeat
\hâ\n[lss]uâ?
\hâ\n[lss]uâuntil (?)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
repeat-loop executes all the statements up to the final
until-keyword over
\hâ\n[lss]uâand over. The loop is executed as
long as the condition, which is specified
\hâ\n[lss]uâwith the until-clause, becomes true.
By construction, the statements within the
\hâ\n[lss]uâloop are executed at least once.
\hâ\n[lss]uâExample
\hâ\n[lss]uâx=0
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint "This program will print
the numbers from 1 to 10"
\hâ\n[lss]uârepeat
\hâ\n[lss]uâx=x+1
\hâ\n[lss]uâprint x
\hâ\n[lss]uâprint "Press any key for the
next number, or âqâ to quit"
\hâ\n[lss]uâif (inkey$="q") break
\hâ\n[lss]uâuntil(x=10)
\hâ\n[lss]uâThis program is pretty much useless, but self-explanatory.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâuntil, break, while, do
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârestore ? reposition the data-pointer
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâread
a,b,c,d,e,f
\hâ\n[lss]uârestore
\hâ\n[lss]uâread g,h,i
\hâ\n[lss]uârestore foo
\hâ\n[lss]uâdata 1,2,3
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâdata 4,5,6
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
restore-command may be used to reset the reading of
data-statements, so
\hâ\n[lss]uâthat the next read-statement will
read data from the first data-statement.
\hâ\n[lss]uâYou
may specify a label with the restore-command; in that case,
the next
\hâ\n[lss]uâread-statement will read data
starting at the given label. If the label is
\hâ\n[lss]uâomitted, reading data will begin
with the first data-statement within your
\hâ\n[lss]uâprogram.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Which language (german/english) ? " l$
\hâ\n[lss]uâif
(instr("german",l$)>0) then
\hâ\n[lss]uârestore german
\hâ\n[lss]uâelse
\hâ\n[lss]uârestore english
\hâ\n[lss]uâendif
\hâ\n[lss]uâfor
a=1 to 3
\hâ\n[lss]uâread x,x$
\hâ\n[lss]uâprint x,"=",x$
\hâ\n[lss]uânext a
\hâ\n[lss]uâlabel
english
\hâ\n[lss]uâdata
1,"one",2,"two",3,"three"
\hâ\n[lss]uâlabel german
\hâ\n[lss]uâdata
1,"eins",2,"zwei",3,"drei"
\hâ\n[lss]uâThis
program asks to select one of those languages known to me
(i.e. english or
\hâ\n[lss]uâgerman) and then prints the numbers
1,2 and 3 and their textual equivalents in
\hâ\n[lss]uâthe chosen language.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâread, data, label
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâreturn ? return from a subroutine or a gosub
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâgosub
foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâlabel foo
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn
\hâ\n[lss]uâsub
bar(baz)
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn quertz
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
return-statement serves two different (albeit somewhat
related) purposes.
\hâ\n[lss]uâThe probably more important use of
return is to return control from within a
\hâ\n[lss]uâsubroutine to the place in your
program, where the subroutine has been called.
\hâ\n[lss]uâIf the subroutine is declared to
return a value, the return-statement might be
\hâ\n[lss]uâaccompanied by a string or number,
which constitutes the return value of the
\hâ\n[lss]uâsubroutine.
\hâ\n[lss]uâHowever,
even if the subroutine should return a value, the
return-statement
\hâ\n[lss]uâneed not carry a value; in that case
the subroutine will return 0 or the empty
\hâ\n[lss]uâstring (depending on the type of the
subroutine). Moreover, feel free to place
\hâ\n[lss]uâmultiple return-statements within
your subroutine; itâs a nice way of
\hâ\n[lss]uâcontrolling the flow of
execution.
\hâ\n[lss]uâThe
second (but historically first) use of return is to return
to the position,
\hâ\n[lss]uâwhere a prior gosub has left off. In
that case return may not carry a value.
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uâread a$
\hâ\n[lss]uâif (a$="") then
\hâ\n[lss]uâprint
\hâ\n[lss]uâend
\hâ\n[lss]uâendif
\hâ\n[lss]uâprint mark$(a$)," ";
\hâ\n[lss]uâloop
\hâ\n[lss]uâdata
"The","quick","brown","fox","jumped"
\hâ\n[lss]uâdata
"over","the","lazy","dog",""
\hâ\n[lss]uâsub
mark$(a$)
\hâ\n[lss]uâif (instr(lower$(a$),"q"))
return upper$(a$)
\hâ\n[lss]uâreturn a$
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example features a subroutine mark$, that returns its
argument in upper
\hâ\n[lss]uâcase, if it contains the letter
"q", or unchanged otherwise. In the test-text
\hâ\n[lss]uâthe word quick will end up being
marked as QUICK.
\hâ\n[lss]uâThe
example above demonstrates return within subroutines; please
see gosub for
\hâ\n[lss]uâan example of how to use return in
this context.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub, gosub
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâreverse ? print reverse (background and foreground colors exchanged)
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâ?
\hâ\n[lss]uâprint reverse "foo"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâreverse
may be used to print text in reverse. reverse is not a
separate
\hâ\n[lss]uâcommand, but part of the
print-command; it may be included just after the print
\hâ\n[lss]uâand can only be issued once that
clear screen has been issued.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint
"1 ";
\hâ\n[lss]uâc=3
\hâ\n[lss]uâdo
\hâ\n[lss]uâprim=true
\hâ\n[lss]uâfor a=2 to sqrt(c)
\hâ\n[lss]uâif (frac(c/a)=0) then
\hâ\n[lss]uâprim=false
\hâ\n[lss]uâbreak
\hâ\n[lss]uâendif
\hâ\n[lss]uânext a
\hâ\n[lss]uâif (prim) then
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint reverse c;
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint c;
\hâ\n[lss]uâendif
\hâ\n[lss]uâprint " ";
\hâ\n[lss]uâc=c+1
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis program prints numbers from 1 on and marks each prime number in reverse.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâat, print color, print, clear screen
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâright$() ? return (or change) the right end of a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
right$(a$,2)
\hâ\n[lss]uâright$(b$,2)="baz"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
right$-function requires two arguments (a string and a
number) and returns
\hâ\n[lss]uâthe part from the right end of the
string, whose length is specified by its
\hâ\n[lss]uâsecond argument. So, right$ simply
returns the requested number of chars from
\hâ\n[lss]uâthe right end of the given
string.
\hâ\n[lss]uâNote,
that the right$-function can be assigned to, i.e. it may
appear on the
\hâ\n[lss]uâleft hand side of an assignment. In
this way it is possible to change a part of
\hâ\n[lss]uâthe variable used within the
right$-function. Note, that that way the length of
\hâ\n[lss]uâthe string cannot be changed, i.e.
characters might be overwritten, but not
\hâ\n[lss]uâadded. For an example see below.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Please enter a length either in inch or
centimeter"
\hâ\n[lss]uâprint "please add
âinâ or âcmâ to mark the unit."
\hâ\n[lss]uâinput "Length: " a$
\hâ\n[lss]uâif (right$(a$,2)="in")
then
\hâ\n[lss]uâlength=val(a$)*2.56
\hâ\n[lss]uâelsif (right$(a$,2)="cm")
then
\hâ\n[lss]uâlength=val(a$)
\hâ\n[lss]uâelse
\hâ\n[lss]uâerror "Invalid input: "+a$
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis
program allows the user to enter a length qualified with a
unit (either
\hâ\n[lss]uâinch or centimeter).
\hâ\n[lss]uâThis
second example demonstrates the capability to assign to the
\hâ\n[lss]uâright$-function.
\hâ\n[lss]uâa$="Heiho
World !"
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâright$(a$,7)="dwarfs."
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâSee also
\hâ\n[lss]uâright$ and mid$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârinstr() ? find the rightmost occurrence of one string within the other
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâpos=rinstr("Thequickbrownfox","equi")
\hâ\n[lss]uâpos=rinstr(a$,b$,x)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
rinstr-function accepts two string-arguments and tries to
find the second
\hâ\n[lss]uâwithin the first. However, unlike
the instr, the rinstr-function finds the
\hâ\n[lss]uârightmost (or last) occurrence of
the string; whereas the instr-function finds
\hâ\n[lss]uâthe leftmost (or first) occurrence.
In any case however, the position is
\hâ\n[lss]uâcounted from the left.
\hâ\n[lss]uâIf
you supply a third, numeric argument to the rinstr-function,
it will be used
\hâ\n[lss]uâas a starting point for the search.
Therefore
rinstr("abcdeabcdeabcde","e",8)
\hâ\n[lss]uâwill return 5, because the search
for an "e" starts at position 8 and finds the
\hâ\n[lss]uâfirst one at position 5.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint rinstr("foofoofoobar","foo")
\hâ\n[lss]uâThis
simple example will print 7, because it finds the rightmost
among the
\hâ\n[lss]uâthree occurrences of foo within the
string. Note, that
\hâ\n[lss]uâprint instr("foofoofoobar","foo")
\hâ\n[lss]uâwould have printed 1.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinstr
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uârtrim$() ? trim spaces at the right end of a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=rtrim$(b$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
rtrim$-function removes all whitespace from the right end of
a string and
\hâ\n[lss]uâreturns the result.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
1,"foo"
\hâ\n[lss]uâdim lines$(100)
\hâ\n[lss]uâl=1
\hâ\n[lss]uâwhile(not eof(1))
\hâ\n[lss]uâinput #1 a$
\hâ\n[lss]uâa$=rtrim$(a$)
\hâ\n[lss]uâif (right$(line$,1)="\\")
then
\hâ\n[lss]uâline$=line$+" "+a$
\hâ\n[lss]uâelse
\hâ\n[lss]uâlines$(l)=line$
\hâ\n[lss]uâl=l+1
\hâ\n[lss]uâline$=a$
\hâ\n[lss]uâendif
\hâ\n[lss]uâend while
\hâ\n[lss]uâprint "Read ",l,"
lines"
\hâ\n[lss]uâThis
example reads the file foo allowing for continuation lines,
which are
\hâ\n[lss]uâmarked by a \, which appears as the
last character on a line. For convenience
\hâ\n[lss]uâwhitespace at the right end of a
line is trimmed with rtrim.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâltrim$, trim$
\hâ\n[lss]uâS
\hâ\n[lss]uâscreen
? as clear screen clears the text window
\hâ\n[lss]uâseek() ? change the position within
an open file
\hâ\n[lss]uâsig() ? return the sign of its
argument
\hâ\n[lss]uâsin() ? return the sine of its
single argument
\hâ\n[lss]uâsleep ? pause, sleep, wait for the
specified number of seconds
\hâ\n[lss]uâsplit() ? split a string into many
strings
\hâ\n[lss]uâsqr() ? compute the square of its
argument
\hâ\n[lss]uâsqrt() ? compute the square root of
its argument
\hâ\n[lss]uâstatic ? preserves the value of a
variable between calls to a subroutine
\hâ\n[lss]uâstep ? specifies the increment step
in a for-loop
\hâ\n[lss]uâstr$() ? convert a number into a
string
\hâ\n[lss]uâsub ? declare a user defined
subroutine
\hâ\n[lss]uâswitch ? select one of many
alternatives depending on a value
\hâ\n[lss]uâsystem() ? hand a statement over to
your operating system and return its
\hâ\n[lss]uâexitcode
\hâ\n[lss]uâsystem$() ? hand a statement over to
your operating system and return its
\hâ\n[lss]uâoutput
\hâ\n[lss]uâName
\hâ\n[lss]uâscreen ? as clear screen clears the text window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
keyword screen appears only within the sequence clear
screen; please see
\hâ\n[lss]uâthere for a description.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâseek() ? change the position within an open file
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
1,"foo"
\hâ\n[lss]uâseek #1,q
\hâ\n[lss]uâseek #1,x,"begin"
\hâ\n[lss]uâseek #1,y,"end"
\hâ\n[lss]uâseek #1,z,"here"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
seek-command changes the position, where the next input (or
peek) statement
\hâ\n[lss]uâwill read from an open file. Usually
files are read from the beginning to the
\hâ\n[lss]uâend sequentially; however sometimes
you may want to depart from this simple
\hâ\n[lss]uâscheme. This can be done with the
seek-command, allowing you to change the
\hâ\n[lss]uâposition, where the next piece of
data will be read from the file.
\hâ\n[lss]uâseek
accepts two or three arguments: The first one is the number
of an already
\hâ\n[lss]uâopen file. The second one is the
position where the next read from the file
\hâ\n[lss]uâwill start. The third argument is
optional and specifies the the point from
\hâ\n[lss]uâwhere the position (the second
argument) will count. It can be one of:
\hâ\n[lss]uâbegin
\hâ\n[lss]uâCount from the beginning of the file.
\hâ\n[lss]uâend
\hâ\n[lss]uâCount from the end of the file.
\hâ\n[lss]uâhere
\hâ\n[lss]uâCount from the current position within the file.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
#1,"count.dat","w"
\hâ\n[lss]uâfor a=1 to 10
\hâ\n[lss]uâprint #1,"00000000";
\hâ\n[lss]uâif (a<10) print #1,";";
\hâ\n[lss]uânext a
\hâ\n[lss]uâdim
count(10)
\hâ\n[lss]uâdo
\hâ\n[lss]uâx=int(ran(10))
\hâ\n[lss]uâi=i+1
\hâ\n[lss]uâif (mod(i,1000)=0) print
".";
\hâ\n[lss]uâcount(x)=count(x)+1
\hâ\n[lss]uâcurr$=right$("00000000"+str$(count(x)),8)
\hâ\n[lss]uâseek #1,9*x,"begin"
\hâ\n[lss]uâprint #1,curr$;
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example increments randomly one of ten counters (in the
array count());
\hâ\n[lss]uâhowever, the result is always kept
and updated within the file count.dat, so
\hâ\n[lss]uâeven in case of an unexpected
interrupt, the result will not be lost.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtell, open, print, peek
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsig() ? return the sign of its argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=sig(b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâReturn +1, -1 or 0, if the single argument is positive, negative or zero.
\hâ\n[lss]uâExample
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâdim
c$(3):c$(1)="red":c$(2)="white":c$(3)="green"
\hâ\n[lss]uâdo
\hâ\n[lss]uânum=ran(100)-50
\hâ\n[lss]uâprint color(c$(2+sig(num))) num
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
program prints an infinite sequence of random number;
positive numbers are
\hâ\n[lss]uâprinted in green, negative numbers
are printed red (an exact zero would be
\hâ\n[lss]uâprinted white). (With a little extra
work, this program could be easily
\hâ\n[lss]uâextended into a brokerage
system)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâabs, int, frac
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsin() ? return the sine of its single argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uây=sin(angle)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
sin-function expects an angle (in radians, not degrees) and
returns its
\hâ\n[lss]uâsine.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uânew curve
\hâ\n[lss]uâfor phi=0 to 2*pi step 0.1
\hâ\n[lss]uâline to
100+90*sin(phi),100+90*cos(phi)
\hâ\n[lss]uânext phi
\hâ\n[lss]uâclose curve
\hâ\n[lss]uâThis program draws a circle (ignoring the existence of the circle-command).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâasin, cos
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsleep ? pause, sleep, wait for the specified number of seconds
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâsleep 4
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
sleep-command has many different names: You may write pause,
sleep or wait
\hâ\n[lss]uâinterchangeably; whatever you write,
yabasic will always do exactly the same.
\hâ\n[lss]uâTherefore
you should refer to the entry for the pause-function for
further
\hâ\n[lss]uâinformation.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsplit() ? split a string into many strings
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdim
w$(10)
\hâ\n[lss]uâ?
\hâ\n[lss]uânum=split(a$,w$())
\hâ\n[lss]uânum=split(a$,w$(),s$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
split-function requires a string (containing the text to be
split), a
\hâ\n[lss]uâreference to a string-array (which
will receive the resulting strings, i.e. the
\hâ\n[lss]uâtokens) and an optional string (with
a set of characters, at which to split,
\hâ\n[lss]uâi.e. the delimiters).
\hâ\n[lss]uâThe
split-function regards its first argument (a string) as a
list of tokens
\hâ\n[lss]uâseparated by delimiters and it will
store the list of tokens within the
\hâ\n[lss]uâarray-reference you have supplied.
Note, that the array, which is passed as a
\hâ\n[lss]uâreference (w$() in the synopsis),
will be resized accordingly, so that you
\hâ\n[lss]uâdonât have to figure out the
number of tokens in advance. The element at
\hâ\n[lss]uâposition zero (i.e. w$(0)) will not
be used.
\hâ\n[lss]uânormally
(i.e. if you omit the third, which is the
delimiter-argument) the
\hâ\n[lss]uâfunction will regard space or tab as
delimiters for tokens; however by
\hâ\n[lss]uâsupplying a third argument, you may
split at any single of the characters
\hâ\n[lss]uâwithin this string. E.g. if you
supply ":;" as the third argument, then colon
\hâ\n[lss]uâ(:) or semicolon (;) will delimit
tokens.
\hâ\n[lss]uâNote,
that a sequence of separator-characters will produce a
sequence of empty
\hâ\n[lss]uâtokens; that way, the number of
tokens returned will always be one plus the
\hâ\n[lss]uânumber of separator characters
contained within the string. Refer to the
\hâ\n[lss]uâclosely related token-function, if
you do not like this behaviour. In some way,
\hâ\n[lss]uâthe split-function focuses on the
separators (other than the token-function,
\hâ\n[lss]uâwhich focuses on the tokens), hence
its name.
\hâ\n[lss]uâThe
second argument is a reference on a string-array, where the
tokens will be
\hâ\n[lss]uâstored; this array will be expanded
(or shrunk) to have room for all tokens, if
\hâ\n[lss]uânecessary.
\hâ\n[lss]uâThe
first argument finally contains the text, that will be split
into tokens.
\hâ\n[lss]uâThe split-function returns the
number of tokens that have been found.
\hâ\n[lss]uâPlease
see the examples below for some hints on the exact behaviour
of the
\hâ\n[lss]uâsplit-function and how it differs
from the token-function:
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"This program will help you to understand, how
the"
\hâ\n[lss]uâprint "split()-function exactly
works and how it behaves"
\hâ\n[lss]uâprint "in certain special
cases."
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint "Please enter a line
containing tokens separated"
\hâ\n[lss]uâprint "by either
â=â or â-â"
\hâ\n[lss]uâdim t$(10)
\hâ\n[lss]uâdo
\hâ\n[lss]uâprint
\hâ\n[lss]uâinput "Please enter a line:
" l$
\hâ\n[lss]uânum=split(l$,t$(),"=-")
\hâ\n[lss]uâprint num," Tokens: ";
\hâ\n[lss]uâfor a=1 to num
\hâ\n[lss]uâif (t$(a)="") then
\hâ\n[lss]uâprint "(EMPTY)";
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint t$(a);
\hâ\n[lss]uâendif
\hâ\n[lss]uâif (a<num) print ",";
\hâ\n[lss]uânext a
\hâ\n[lss]uâprint
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis program prints the following output:
\hâ\n[lss]uâPlease
enter a line: a
\hâ\n[lss]uâ1 Tokens: a
\hâ\n[lss]uâPlease
enter a line:
\hâ\n[lss]uâ0 Tokens:
\hâ\n[lss]uâPlease
enter a line: ab
\hâ\n[lss]uâ1 Tokens: ab
\hâ\n[lss]uâPlease
enter a line: a=b
\hâ\n[lss]uâ2 Tokens: a,b
\hâ\n[lss]uâPlease
enter a line: a-
\hâ\n[lss]uâ2 Tokens: a,(EMPTY)
\hâ\n[lss]uâPlease
enter a line: a-=
\hâ\n[lss]uâ3 Tokens: a,(EMPTY),(EMPTY)
\hâ\n[lss]uâPlease
enter a line: =a-
\hâ\n[lss]uâ3 Tokens: (EMPTY),a,(EMPTY)
\hâ\n[lss]uâPlease
enter a line: a=-b
\hâ\n[lss]uâ3 Tokens: a,(EMPTY),b
\hâ\n[lss]uâPlease
enter a line: a--b-
\hâ\n[lss]uâ4 Tokens: a,(EMPTY),b,(EMPTY)
\hâ\n[lss]uâPlease
enter a line: -a==b-c==
\hâ\n[lss]uâ7 Tokens:
(EMPTY),a,(EMPTY),b,c,(EMPTY),(EMPTY)
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtoken
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsqr() ? compute the square of its argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa=sqr(b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
sqr-function computes the square of its numerical argument
(i.e. it
\hâ\n[lss]uâmultiplies its argument with
itself).
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâprint a,sqr(a),a**2
\hâ\n[lss]uânext a
\hâ\n[lss]uâAs you may see from the output, sqr can be written as **2 (or Ë2) too.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsqrt, **, Ë
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsqrt() ? compute the square root of its argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâto be written
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe sqrt-function computes the square root of its numerical argument.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 5
\hâ\n[lss]uâprint a,sqrt(a),a**(1/2)
\hâ\n[lss]uânext a
\hâ\n[lss]uâAs you may see from the output, sqrt can be written as **(1/2) (or Ë(1/2)) too.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsqr, **, Ë
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâstatic ? preserves the value of a variable between calls to a subroutine
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâsub foo()
\hâ\n[lss]uâstatic a
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
static keyword can be used within subroutines to mark
variables as static.
\hâ\n[lss]uâThis has two effects: First, the
variable is local to the subroutine, i.e. its
\hâ\n[lss]uâvalue is not know outside the
subroutine (this is the effect of the local
\hâ\n[lss]uâkeyword). Second, the static-keyword
arranges things, so that the variable
\hâ\n[lss]uâkeeps its value between invocations
of the subroutine (this is different from
\hâ\n[lss]uâthe local-keyword).
\hâ\n[lss]uâExample
\hâ\n[lss]uâfoo()
\hâ\n[lss]uâfoo()
\hâ\n[lss]uâfoo()
\hâ\n[lss]uâsub
foo()
\hâ\n[lss]uâstatic a
\hâ\n[lss]uâlocal b
\hâ\n[lss]uâa=a+1
\hâ\n[lss]uâb=b+1
\hâ\n[lss]uâprint a,b
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
program shows the difference between static and local
variables within a
\hâ\n[lss]uâsubroutine; it produces this
output:
\hâ\n[lss]uâ1
1
\hâ\n[lss]uâ2 1
\hâ\n[lss]uâ3 1
\hâ\n[lss]uâThe
output shows, that the static variable a keeps its value
between subroutine
\hâ\n[lss]uâcalls, whereas b is initialized with
the value 0 at every call to the
\hâ\n[lss]uâsubroutine foo.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsub, local
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâstep ? specifies the increment step in a for-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfor
a=1 to 10 step 3
\hâ\n[lss]uâ?
\hâ\n[lss]uânext a
\hâ\n[lss]uâDescription
\hâ\n[lss]uâSpecify,
by which amount the loop-variable of a for-loop will be
incremented at
\hâ\n[lss]uâeach step.
\hâ\n[lss]uâThe
step (as well as the lower and upper bound) are computed
anew in each step;
\hâ\n[lss]uâthis is not common, but possible, as
the example below demonstrates.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
x=1 to 1000 step y
\hâ\n[lss]uây=x+y
\hâ\n[lss]uâprint x," ",y,"
";
\hâ\n[lss]uânext x
\hâ\n[lss]uâprint
\hâ\n[lss]uâThis program computes the fibonacci numbers between 1 and 1000.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfor
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâstr$() ? convert a number into a string
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=str$(a)
\hâ\n[lss]uâb$=str$(x,"##.###")
\hâ\n[lss]uâb$=str$(x,"###,###.##")
\hâ\n[lss]uâb$=str$(x,"###,###.##","_.")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
str$-function accepts a numeric argument and returns it as a
string. This
\hâ\n[lss]uâconversion between number and string
can be controlled with the optional third
\hâ\n[lss]uâargument (the format argument). See
the following table of examples to learn
\hâ\n[lss]uâabout valid values of this argument.
Note, that those examples fall in one of
\hâ\n[lss]uâtwo categories: C-style and
basic-style; the first 4 examples in the table
\hâ\n[lss]uâbelow are C-style, the rest of the
examples are basic-style. For more
\hâ\n[lss]uâinformation on the C-style formats,
you may refer to your favorite
\hâ\n[lss]uâdocumentation on the C programming
language. The basic-style formats are much
\hâ\n[lss]uâsimpler, they just depict the
desired output, marking digits with â#â; groups
\hâ\n[lss]uâof (usually three) digits may be
separated with colons (â,â), the decimal dot
\hâ\n[lss]uâmust be marked by a literal dot
(â.â). Moreover these characters (colons and
\hâ\n[lss]uâdot) may be replaced by other
characters to satisfy the needs of non-english
\hâ\n[lss]uâ(e.g. german) languages; see the
examples below.
\hâ\n[lss]uâNote,
that for clarity, each space in the result has been replaced
by the
\hâ\n[lss]uâletter âxâ, because it
would be hard to figure out, how many spaces are
\hâ\n[lss]uâproduced exactly otherwise.
\hâ\n[lss]uâTable 7.2. Examples for the format argument
\hâ\n[lss]uâ+-----------------------------------------------------------------------------+
\hâ\n[lss]uâ| Example | Result for | |
\hâ\n[lss]uâ| string | converting | Description
|
\hâ\n[lss]uâ| | 1000*pi | |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |The â2â determines
the minimum length of the |
\hâ\n[lss]uâ|%2.5f |3141.59265 |output; but if
needed (as in the example) the |
\hâ\n[lss]uâ| | |output can be longer. The
â5â is the number of |
\hâ\n[lss]uâ| | |digits after the decimal point.
|
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |Two spaces (which appear as
âxâ) are added to pad |
\hâ\n[lss]uâ|%12.5f |xx3141.59265|the output to
the requested length of 12 |
\hâ\n[lss]uâ| | |characters. |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |The âgâ requests,
that the precision (â5â) |
\hâ\n[lss]uâ|%012.5g |0000003141.6|specifies the
overall number of digits (before and|
\hâ\n[lss]uâ| | |after the decimal point). |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |The â-â requests
the output to be left-centered |
\hâ\n[lss]uâ|%-12.5f |3141.59265xx|(therefore
the filling space appears at the |
\hâ\n[lss]uâ| | |right). |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |Each â#â specifies
a digit (either before or after|
\hâ\n[lss]uâ| | |the dot), the â.â
specifies the position of the |
\hâ\n[lss]uâ|#####.## |x3141.59 |dot. As 1000*pi
does not have enough digits, the 5|
\hâ\n[lss]uâ| | |requested digits before the dot
are filled up with|
\hâ\n[lss]uâ| | |a space (which shows up as an
âxâ). |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ|##,###.## |x3,141.59 |Nearly the
same as above, but the colon from the |
\hâ\n[lss]uâ| | |format shows up within the
result. |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ|##,###.## and| | |
\hâ\n[lss]uâ|an additional|x3.141,59 |Similar to
the example above, but colon and dot |
\hâ\n[lss]uâ|argument of | |are replaced with
dot and colon respectively. |
\hâ\n[lss]uâ|".," | | |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ|##,###.## and| |Similar to the
example above, but colon and dot |
\hâ\n[lss]uâ|an additional|x3_141,59 |are
replaced with underscore and colon |
\hâ\n[lss]uâ|argument of | |respectively. |
\hâ\n[lss]uâ|"_," | | |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |The format string does not
contain a dot, and |
\hâ\n[lss]uâ|##### |x3142 |therefore the result
does not have any fractional |
\hâ\n[lss]uâ| | |digits. |
\hâ\n[lss]uâ|-------------+------------+--------------------------------------------------|
\hâ\n[lss]uâ| | |As 1000*pi has 4 digits in
front of the decimal |
\hâ\n[lss]uâ|##.### |##.### |dot and the format
only specifies 2, yabasic does |
\hâ\n[lss]uâ| | |not know what to do; therefore
it chooses just to |
\hâ\n[lss]uâ| | |reproduce the format string. |
\hâ\n[lss]uâ+-----------------------------------------------------------------------------+
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uâinput "Please enter a format
string: " f$
\hâ\n[lss]uâa$=str$(1000*pi,f$)
\hâ\n[lss]uâfor a=1 to len(a$)
\hâ\n[lss]uâif (mid$(a$,a,1)=" ")
mid$(a$,a,1)="x"
\hâ\n[lss]uânext a
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
is the program, that has been used to get the results shown
in the table
\hâ\n[lss]uâabove.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâprint, using
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsub ? declare a user defined subroutine
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfoo(2,"hello")
\hâ\n[lss]uâ?
\hâ\n[lss]uâsub
foo(bar,baz$)
\hâ\n[lss]uâ?
\hâ\n[lss]uâreturn qux
\hâ\n[lss]uâ?
\hâ\n[lss]uâend sub
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
sub-keyword starts the definition of a user defined
subroutine. With user
\hâ\n[lss]uâdefined subroutines you are able to
somewhat extend yabasic with your own
\hâ\n[lss]uâcommands or functions. A subroutine
accepts arguments (numbers or strings) and
\hâ\n[lss]uâreturns a number or a string
(however, you are not required to assign the value
\hâ\n[lss]uâreturned to a variable).
\hâ\n[lss]uâThe
name of the subroutine follows after the keyword sub. If the
name (in the
\hâ\n[lss]uâsynopsis: foo) ends on a
â$â, the subroutine should return a string (with
the
\hâ\n[lss]uâreturn-statement), otherwise a
number.
\hâ\n[lss]uâAfter
the name of the subroutine yabasic requires a pair of
braces; within
\hâ\n[lss]uâthose braces you may specify a list
of parameters, for which values can (but
\hâ\n[lss]uâneed not) be included when calling
the subroutine. If you omit one of those
\hâ\n[lss]uâparameters when calling such a
subroutine, it assumes the value zero (for
\hâ\n[lss]uânumeric parameters) or the empty
string (for string-parameters). However from
\hâ\n[lss]uâthe special variable numparams you
may find out, how many arguments have really
\hâ\n[lss]uâbeen passed when calling the
subroutine.
\hâ\n[lss]uâParameters
of a subroutine are always local variables (see the keyword
local
\hâ\n[lss]uâfor more explanation).
\hâ\n[lss]uâFrom
within the subroutine you may return any time with the
keyword return;
\hâ\n[lss]uâalong with the return-keyword you
may specify the return value. Note that more
\hâ\n[lss]uâthan one return is allowed within a
single subroutine.
\hâ\n[lss]uâFinally,
the keyword end sub ends the subroutine definition. Note,
that the
\hâ\n[lss]uâdefinition of a subroutine need not
appear within the program before the first
\hâ\n[lss]uâcall to this sub.
\hâ\n[lss]uâNote
\hâ\n[lss]uâAs
braces have two uses in yabasic (i.e. for supplying
arguments to a
\hâ\n[lss]uâsubroutine as well as to list the
indices of an array). yabasic can not tell
\hâ\n[lss]uâapart an array from a subroutine
with the same name. Therefore you cannot
\hâ\n[lss]uâdefine a subroutine with the same
name as an array !
\hâ\n[lss]uâExample
\hâ\n[lss]uâp=2
\hâ\n[lss]uâdo
\hâ\n[lss]uâif (is_prime(p)) print p
\hâ\n[lss]uâp=p+1
\hâ\n[lss]uâloop
\hâ\n[lss]uâsub
is_prime(a)
\hâ\n[lss]uâlocal b
\hâ\n[lss]uâfor b=2 to sqrt(a)
\hâ\n[lss]uâif (frac(a/b)=0) return false
\hâ\n[lss]uânext b
\hâ\n[lss]uâreturn true
\hâ\n[lss]uâend sub
\hâ\n[lss]uâThis
example is not the recommended way to compute prime numbers.
However it
\hâ\n[lss]uâgives a nice demonstration of using
a subroutine.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâlocal, static, peek
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâswitch ? select one of many alternatives depending on a value
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâswitch
a
\hâ\n[lss]uâcase 1
\hâ\n[lss]uâcase 2
\hâ\n[lss]uâ?
\hâ\n[lss]uâend switch
\hâ\n[lss]uâ?
\hâ\n[lss]uâswitch
a$
\hâ\n[lss]uâcase "a"
\hâ\n[lss]uâcase "b"
\hâ\n[lss]uâend switch
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
switch-statement selects one of many codepaths depending on
a numerical or
\hâ\n[lss]uâstring expression. I.e. it takes an
expression (either numeric or string) and
\hâ\n[lss]uâcompares it with a series of values,
each wrapped within a case-clause. If the
\hâ\n[lss]uâexpression equals the value given in
a case-clause, the subsequent statements
\hâ\n[lss]uâare executed.
\hâ\n[lss]uâThe
default-clause allows one to specify commands, which should
be executed, if
\hâ\n[lss]uânone of case-clauses matches.
\hâ\n[lss]uâNote,
that many case-clauses might be clustered (e.g. case
"a":case "b":case
\hâ\n[lss]uâ"c"). Or put another way:
You need a break-statement at the end of a
\hâ\n[lss]uâcase-branch, if you do not want to
run into the next case.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a single digit: " n
\hâ\n[lss]uâswitch n
\hâ\n[lss]uâcase 0:print "zero":break
\hâ\n[lss]uâcase 1:print "one":break
\hâ\n[lss]uâcase 2:print "two":break
\hâ\n[lss]uâcase 3:print "three":break
\hâ\n[lss]uâcase 4:print "four":break
\hâ\n[lss]uâcase 5:case 6: case 7:case 8:case 9
\hâ\n[lss]uâprint "Much !":break
\hâ\n[lss]uâdefault:print "Hey ! That was
more than a single digit !"
\hâ\n[lss]uâend switch
\hâ\n[lss]uâThis
example translates a single digit into a string; note, how
the cases 5 to
\hâ\n[lss]uâ7 are clustered.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâswitch, case, break
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsystem()
? hand a statement over to your operating system and return
its
\hâ\n[lss]uâexitcode
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâret=system("foo")
\hâ\n[lss]uâsystem("bar")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
system-command accepts a single string argument, which
specifies a command
\hâ\n[lss]uâto be executed. The function will
return the exitcode of the command; its
\hâ\n[lss]uâoutput (if any) will be lost.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Please enter the name of the file, that should be
deleted."
\hâ\n[lss]uâinput f$
\hâ\n[lss]uâif (system("rm "+f$+"
>/dev/null 2>&1")) then
\hâ\n[lss]uâprint "Error !"
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "okay."
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis program is Unix-specific: It uses the Unix-command rm to remove a file.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsystem$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâsystem$()
? hand a statement over to your operating system and return
its
\hâ\n[lss]uâoutput
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint system$("dir")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
system$-command accepts a single string argument, specifying
a command,
\hâ\n[lss]uâthat can be found and executed by
your operating system. It returns the output
\hâ\n[lss]uâof this command as one big
string.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter the name of a directory: " d$
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint "This is the contents of
the â"+d$+"â:"
\hâ\n[lss]uâprint system$("dir
"+d$)
\hâ\n[lss]uâThis
example lists the contents of a directory, employing the
dir-command
\hâ\n[lss]uâ(which is about the only program,
that is known under Unix as well as Windows).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsystem, chomp
\hâ\n[lss]uâT
\hâ\n[lss]uâtan()
? return the tangent of its argument
\hâ\n[lss]uâtell ? get the current position
within an open file
\hâ\n[lss]uâtext ? write text into your
graphic-window
\hâ\n[lss]uâthen ? tell the long from the short
form of the if-statement
\hâ\n[lss]uâtime$ ? return a string containing
the current time
\hâ\n[lss]uâto ? this keyword appears as part of
other statements
\hâ\n[lss]uâtoken() ? split a string into
multiple strings
\hâ\n[lss]uâtriangle ? draw a triangle
\hâ\n[lss]uâtrim$() ? remove leading and
trailing spaces from its argument
\hâ\n[lss]uâtrue ? a constant with the value of
1
\hâ\n[lss]uâName
\hâ\n[lss]uâtan() ? return the tangent of its argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfoo=tan(bar)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
tan-function computes the tangent of its arguments (which
should be
\hâ\n[lss]uâspecified in radians).
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=0 to 45
\hâ\n[lss]uâprint tan(a*pi/180)
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis example simply prints the tangent of all angles between 0 and 45 degrees.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâatan, sin
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtell ? get the current position within an open file
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
#1,"foo"
\hâ\n[lss]uâ?
\hâ\n[lss]uâposition=tell(#1)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
tell-function requires the number of an open file as an
argument. It
\hâ\n[lss]uâreturns the position (counted in
bytes, starting from the beginning of the
\hâ\n[lss]uâfile) where the next read will
start.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
#1,"foo","w"
\hâ\n[lss]uâprint #1 "Hello World !"
\hâ\n[lss]uâclose #1
\hâ\n[lss]uâopen
#1,"foo"
\hâ\n[lss]uâseek #1,0,"end"
\hâ\n[lss]uâprint tell(#1)
\hâ\n[lss]uâclose 1
\hâ\n[lss]uâThis
example (mis)uses tell to get the size of the file. The seek
positions the
\hâ\n[lss]uâfile pointer at the end of the file,
therefore the call to tell returns the
\hâ\n[lss]uâtotal length of the file.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâtell, open
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtext ? write text into your graphic-window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâtext
x,y,"foo"
\hâ\n[lss]uâtext
x,y,"foo","lb"
\hâ\n[lss]uâtext
x,y,"foo","cc","font"
\hâ\n[lss]uâtext
x,y,"foo","font","rt"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
text-commands displays a text-string (the third argument) at
the given
\hâ\n[lss]uâposition (the first two arguments)
within an already opened window. The font to
\hâ\n[lss]uâbe used can be optionally specified
as either the fourth or fifth argument
\hâ\n[lss]uâ("font" in the example
above). A font specified this way will also be used for
\hâ\n[lss]uâany subsequent text-commands, as
long as they do not specify a font themselves.
\hâ\n[lss]uâThe
fourth or fifth optional argument ("lb" in the
example above) can be used
\hâ\n[lss]uâto specify the alignment of the text
with respect to the specified position.
\hâ\n[lss]uâThis argument is always two
characters long: The first character specifies the
\hâ\n[lss]uâhorizontal alignment and can be
either l, r or c, which stand for left, right
\hâ\n[lss]uâor center. The second character
specifies the vertical alignment and can be one
\hâ\n[lss]uâof t, b or c, which stand for top,
bottom or center respectively. If you omit
\hâ\n[lss]uâthis alignment argument, the default
"lb" applies; however this default may be
\hâ\n[lss]uâchanged with poke
"textalign","xx"
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 500,200
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâdata
"lt","lc","lb","ct","cc","cb","rt","rc","rb"
\hâ\n[lss]uâfor a=1 to 9
\hâ\n[lss]uâread align$
\hâ\n[lss]uâprint "Alignment: ",align$
\hâ\n[lss]uâline 50*a-15,100,50*a+15,100
\hâ\n[lss]uâline 50*a,85,50*a,115
\hâ\n[lss]uâtext
50*a,100,"Test",align$
\hâ\n[lss]uâinkey$
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis
program draws nine crosses and writes the same text at each;
however it
\hâ\n[lss]uâgoes through all possible nine
alignment strings, showing their effect.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, peek, poke
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâthen ? tell the long from the short form of the if-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâif
(a<b) then
\hâ\n[lss]uâ?
\hâ\n[lss]uâendif
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
keyword then is part of the if-statement; please see there
for further
\hâ\n[lss]uâexplanations. However, not every
if-statement requires the keyword then: If the
\hâ\n[lss]uâkeyword then is present, the
if-clause may extend over more than one line, and
\hâ\n[lss]uâthe keyword endif is required to end
it. If the keyword then is not present,
\hâ\n[lss]uâthe if-statement extends up to the
end of the line, and any endif would be an
\hâ\n[lss]uâerror.
\hâ\n[lss]uâExample
\hâ\n[lss]uâif
(1<2) then
\hâ\n[lss]uâprint "Hello ";
\hâ\n[lss]uâendif
\hâ\n[lss]uâif
(2<3) print "world"
\hâ\n[lss]uâif (2<1)
\hâ\n[lss]uâprint "!"
\hâ\n[lss]uâThis
example prints Hello world. Note, that no exclamation mark
(!) is printed,
\hâ\n[lss]uâwhich might come as a surprise and
may be changed in future versions of yabasic
\hâ\n[lss]uâ.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâif
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtime$ ? return a string containing the current time
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
time$
\hâ\n[lss]uâprint time$()
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
time$ function returns the current time in four fields
separated by hyphens
\hâ\n[lss]uââ-â. The fields are:
\hâ\n[lss]uâ*
The current hour in the range from 0 to 23, padded with
zeroes (e.g. 00 or
\hâ\n[lss]uâ04) to a length of two
characters.
\hâ\n[lss]uâ* The number of minutes, padded with zeroes.
\hâ\n[lss]uâ* The number of seconds, padded with zeroes.
\hâ\n[lss]uâ*
The number of seconds, that have elapsed since the program
has been
\hâ\n[lss]uâstarted. This value increases as
long as your program runs and is therefore
\hâ\n[lss]uâunbound and not padded with
zeroes.
\hâ\n[lss]uâAt
the time of writing this documentation, time$ returns
22-58-53-0. Note, that
\hâ\n[lss]uâthe first three of the four fields
returned by time$ have a fixed width;
\hâ\n[lss]uâtherefore it is easy to extract some
fields with the usual string-functions
\hâ\n[lss]uâmid$ (and others).
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"Hello it is ",time$
\hâ\n[lss]uâprint "An empty for-loop with
ten million iterations takes ";
\hâ\n[lss]uâfor a=1 to 10000000:next a
\hâ\n[lss]uâprint "Now it is ",time$
\hâ\n[lss]uâprint
peek("secondsrunning")," seconds have
passed."
\hâ\n[lss]uâThis
program benchmarks the for-loop; however, it does not use
the fourth field
\hâ\n[lss]uâof the string returned by time$,
because that string wraps around every 60
\hâ\n[lss]uâseconds; rather the peek
"secondsrunning" is queried.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâdate
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâto ? this keyword appears as part of other statements
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâfor
a=1 to 100 step 2
\hâ\n[lss]uâ?
\hâ\n[lss]uânext a
\hâ\n[lss]uâline x,y to a,b
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe to-keyword serves two purposes (which are not related at all):
\hâ\n[lss]uâ* within for-statements, to specify the upper bound of the loop.
\hâ\n[lss]uâ*
Within any graphical command (e.g. line), that requires two
points (i.e.
\hâ\n[lss]uâfour numbers) as arguments, a comma
â,â might be replaced with the keyword
\hâ\n[lss]uâto. I.e. instead of 100,100,200,200
you may write 100,100 to 200,200 in
\hâ\n[lss]uâsuch commands.
\hâ\n[lss]uâExample
\hâ\n[lss]uâPlease see the command listed under "See also" for examples.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfor, line, rectangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtoken() ? split a string into multiple strings
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâdim
w$(10)
\hâ\n[lss]uâ?
\hâ\n[lss]uânum=token(a$,w$())
\hâ\n[lss]uânum=token(a$,w$(),s$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
token-function accepts a string (containing the text to be
split), a
\hâ\n[lss]uâreference to a string-array (which
will receive the resulting strings, i.e. the
\hâ\n[lss]uâtokens) and an optional string (with
a set of characters, at which to split,
\hâ\n[lss]uâi.e. the delimiters).
\hâ\n[lss]uâThe
token-function regards its first argument as a list of
tokens separated by
\hâ\n[lss]uâdelimiters and it will store the
list of tokens within the array-reference that
\hâ\n[lss]uâhas been supplied. Note, that the
array, which is passed as a reference (w$()
\hâ\n[lss]uâin the synopsis), will be resized
accordingly, so that you donât have to figure
\hâ\n[lss]uâout the number of tokens in advance.
The element at position zero (i.e. w$(0))
\hâ\n[lss]uâwill not be used.
\hâ\n[lss]uâNormally
(i.e. if you omit the third, the delimiter-argument) the
function will
\hâ\n[lss]uâregard space or tab as delimiters
for tokens; however by supplying a third
\hâ\n[lss]uâargument, you may split at any
single of the characters within this string.
\hâ\n[lss]uâE.g. if you supply ":;" as
the third argument, then colon (:) or semicolon (;)
\hâ\n[lss]uâwill delimit tokens.
\hâ\n[lss]uâNote,
that token will never produce empty tokens, even if two or
more
\hâ\n[lss]uâseparators follow in sequence. Refer
to the closely related split-function, if
\hâ\n[lss]uâyou do not like this behaviour. In
some way, the token-function focuses on the
\hâ\n[lss]uâtokens and not on the separators
(other than the split-function, which focuses
\hâ\n[lss]uâon the separators).
\hâ\n[lss]uâThe
second argument is a reference on a string-array, where the
tokens will be
\hâ\n[lss]uâstored; this array will be expanded
(or shrunk) as necessary to have room for
\hâ\n[lss]uâall tokens.
\hâ\n[lss]uâThe
first argument finally contains the text, that will be split
into tokens.
\hâ\n[lss]uâThe token-function returns the
number of tokens, that have been found.
\hâ\n[lss]uâPlease
see the examples below for some hints on the exact behaviour
of the
\hâ\n[lss]uâtoken-function and how it differs
from the split-function:
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint
"This program will help you to understand, how
the"
\hâ\n[lss]uâprint "token()-function exactly
works and how it behaves"
\hâ\n[lss]uâprint "in certain special
cases."
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint "Please enter a line
containing tokens separated"
\hâ\n[lss]uâprint "by either
â=â or â-â"
\hâ\n[lss]uâdim t$(10)
\hâ\n[lss]uâdo
\hâ\n[lss]uâprint
\hâ\n[lss]uâinput "Please enter a line:
" l$
\hâ\n[lss]uânum=token(l$,t$(),"=-")
\hâ\n[lss]uâprint num," Tokens: ";
\hâ\n[lss]uâfor a=1 to num
\hâ\n[lss]uâif (t$(a)="") then
\hâ\n[lss]uâprint "(EMPTY)";
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint t$(a);
\hâ\n[lss]uâendif
\hâ\n[lss]uâif (a<num) print ",";
\hâ\n[lss]uânext a
\hâ\n[lss]uâprint
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis program prints the following output:
\hâ\n[lss]uâPlease
enter a line: a
\hâ\n[lss]uâ1 Tokens: a
\hâ\n[lss]uâPlease
enter a line:
\hâ\n[lss]uâ0 Tokens:
\hâ\n[lss]uâPlease
enter a line: ab
\hâ\n[lss]uâ1 Tokens: ab
\hâ\n[lss]uâPlease
enter a line: a=b
\hâ\n[lss]uâ2 Tokens: a,b
\hâ\n[lss]uâPlease
enter a line: a-
\hâ\n[lss]uâ1 Tokens: a
\hâ\n[lss]uâPlease
enter a line: a-=
\hâ\n[lss]uâ1 Tokens: a
\hâ\n[lss]uâPlease
enter a line: =a-
\hâ\n[lss]uâ1 Tokens: a
\hâ\n[lss]uâPlease
enter a line: a=-b
\hâ\n[lss]uâ2 Tokens: a,b
\hâ\n[lss]uâPlease
enter a line: a--b-
\hâ\n[lss]uâ2 Tokens: a,b
\hâ\n[lss]uâPlease
enter a line: -a==b-c==
\hâ\n[lss]uâ3 Tokens: a,b,c
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsplit
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtriangle ? draw a triangle
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window 100,100
\hâ\n[lss]uâtriangle 100,100,50,50,100,50
\hâ\n[lss]uâfill triangle 50,100,100,50,200,200
\hâ\n[lss]uâclear fill triangle
20,20,10,10,200,200
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
triangle-command draws a triangle; it requires 6 parameters:
The x- and
\hâ\n[lss]uây-coordinates of the three points
making up the triangle. With the optional
\hâ\n[lss]uâkeywords clear and fill (which may
appear both and in any sequence) the
\hâ\n[lss]uâtriangle can be cleared and filled
respectively.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâdo
\hâ\n[lss]uâphi=phi+0.2
\hâ\n[lss]uâi=i+2
\hâ\n[lss]uâcolor
mod(i,255),mod(85+2*i,255),mod(170+3*i,255)
\hâ\n[lss]uâdx=100*sin(phi):dy=20*cos(phi)
\hâ\n[lss]uâfill triangle
100+20*sin(phi),100+20*cos(phi),100-20*sin(phi),100-20*cos(phi),100-80*cos(phi),100+80*sin(phi)
\hâ\n[lss]uâsleep 0.1
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis example draws a colored triangles until you get exhausted.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window, open printer, line, circle, rectangle
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtrim$() ? remove leading and trailing spaces from its argument
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâa$=trim$(b$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
trim$-function removes all whitespace from the left and from
the right end
\hâ\n[lss]uâof a string and returns the result.
Calling trim$ is equivalent to calling
\hâ\n[lss]uârtrim$(ltrim$()).
\hâ\n[lss]uâExample
\hâ\n[lss]uâdo
\hâ\n[lss]uâinput "Continue ? Please answer
yes or no: " a$
\hâ\n[lss]uâa$=lower$(trim$(a$))
\hâ\n[lss]uâif (len(a$)>0 and
a$=left$("no",len(a$)) exit
\hâ\n[lss]uâloop
\hâ\n[lss]uâThis
example asks for an answer (yes or no) and removes spaces
with trim$ to
\hâ\n[lss]uâmake the comparison with the string
"no" more bulletproof.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâltrim$, rtrim$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâtrue ? a constant with the value of 1
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâokay=true
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
constant true can be assigned to variables which will later
appear in
\hâ\n[lss]uâconditions (e.g. an
if-statement.
\hâ\n[lss]uâtrue may also be written as TRUE or even TrUe.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a string of all upper letters: " a$
\hâ\n[lss]uâif (is_upper(a$)) print
"Okay"
\hâ\n[lss]uâsub
is_upper(a$)
\hâ\n[lss]uâif (a$=upper$(a$)) return true
\hâ\n[lss]uâreturn false
\hâ\n[lss]uâend sub
\hâ\n[lss]uâSee also
\hâ\n[lss]uâfalse
\hâ\n[lss]uâU
\hâ\n[lss]uâuntil
? end a repeat-loop
\hâ\n[lss]uâupper$() ? convert a string to upper
case
\hâ\n[lss]uâusing ? Specify the format for
printing a number
\hâ\n[lss]uâName
\hâ\n[lss]uâuntil ? end a repeat-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uârepeat
\hâ\n[lss]uâ?
\hâ\n[lss]uâuntil (?)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
until-keyword ends a loop, which has been introduced by the
repeat-keyword.
\hâ\n[lss]uâuntil requires a condition in braces
(or an expression, see here for details)
\hâ\n[lss]uâas an argument; the loop will
continue until this condition evaluates to true.
\hâ\n[lss]uâExample
\hâ\n[lss]uâc=1
\hâ\n[lss]uâs=1
\hâ\n[lss]uârepeat
\hâ\n[lss]uâl=c
\hâ\n[lss]uâs=-(s+sig(s))
\hâ\n[lss]uâc=c+1/s
\hâ\n[lss]uâprint c
\hâ\n[lss]uâuntil(abs(l-c)<0.000001)
\hâ\n[lss]uâThis
program calculates the sequence
1/1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+ ? ;
\hâ\n[lss]uâplease let me know, if you know
against which value this converges.
\hâ\n[lss]uâSee also
\hâ\n[lss]uârepeat
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâupper$() ? convert a string to upper case
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâu$=upper$(a$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
upper$-function accepts a single string argument and
converts it to all
\hâ\n[lss]uâupper case.
\hâ\n[lss]uâExample
\hâ\n[lss]uâline
input "Please enter a sentence without the letter
âeâ: " l$
\hâ\n[lss]uâp=instr(upper$(l$),"E")
\hâ\n[lss]uâif (p) then
\hâ\n[lss]uâl$=lower$(l$)
\hâ\n[lss]uâmid$(l$,p,1)="E"
\hâ\n[lss]uâprint "Hey, you are wrong, see
here!"
\hâ\n[lss]uâprint l$
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint "Thanks."
\hâ\n[lss]uâendif
\hâ\n[lss]uâThis
program asks for a sentence and marks the first (if any)
occurrence of the
\hâ\n[lss]uâletter âeâ by converting
it to upper case (in contrast to the rest of the
\hâ\n[lss]uâsentence, which is converted to
lower case).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâlower$
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâusing ? Specify the format for printing a number
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
a using "##.###"
\hâ\n[lss]uâprint a
using("##.###",",.")
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
using-keyword may appear as part of the print-statement and
specifies the
\hâ\n[lss]uâformat (e.g. the number of digits
before and after the decimal dot), which
\hâ\n[lss]uâshould be used to print the
number.
\hâ\n[lss]uâThe
possible values for the format argument ("##.###"
in the synopsis above)
\hâ\n[lss]uâare described within the entry for
the str$-function; especially the second
\hâ\n[lss]uâline in the synopsis (print a
using("##.###",",.")) will become clear
after
\hâ\n[lss]uâreferring to str$. In fact the using
clause is closely related to the
\hâ\n[lss]uâstr$-function; the former can always
be rewritten using the latter; i.e. print
\hâ\n[lss]uâfoo using bar$ is always equivalent
to print str$(foo,bar$). Therefore you
\hâ\n[lss]uâshould check out str$ to learn
more.
\hâ\n[lss]uâExample
\hâ\n[lss]uâfor
a=1 to 10
\hâ\n[lss]uâprint sqrt(ran(10000*a)) using
"#########.#####"
\hâ\n[lss]uânext a
\hâ\n[lss]uâThis
example prints a column of square roots of random number,
nicely aligned
\hâ\n[lss]uâat the decimal dot.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâprint, str$
\hâ\n[lss]uâV
\hâ\n[lss]uâval() ? converts a string to a number
\hâ\n[lss]uâName
\hâ\n[lss]uâval() ? converts a string to a number
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=val(x$)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
val-function checks, if the start of its string argument
forms a floating
\hâ\n[lss]uâpoint number and then returns this
number. The string therefore has to start
\hâ\n[lss]uâwith digits (only whitespace in
front is allowed), otherwise the val-function
\hâ\n[lss]uâreturns zero.
\hâ\n[lss]uâExample
\hâ\n[lss]uâinput
"Please enter a length, either in inches (in) or
centimeters (cm) " l$
\hâ\n[lss]uâif (right$(l$,2)="in")
then
\hâ\n[lss]uâl=val(l$)*2.51
\hâ\n[lss]uâelse
\hâ\n[lss]uâl=val(l$)
\hâ\n[lss]uâprint "You have entered
",l,"cm."
\hâ\n[lss]uâThis
example queries for a length and checks, if it has been
specified in
\hâ\n[lss]uâinches or centimeters. The length is
then converted to centimeters.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâstr$
\hâ\n[lss]uâW
\hâ\n[lss]uâwait
? pause, sleep, wait for the specified number of seconds
\hâ\n[lss]uâwend ? end a while-loop
\hâ\n[lss]uâwhile ? start a while-loop
\hâ\n[lss]uâwindow origin ? move the origin of a
window
\hâ\n[lss]uâName
\hâ\n[lss]uâwait ? pause, sleep, wait for the specified number of seconds
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâwait 4
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
wait-command has many different names: You may write pause,
sleep or wait
\hâ\n[lss]uâinterchangeably; whatever you write,
yabasic will always do exactly the same.
\hâ\n[lss]uâTherefore
you should refer to the entry for the pause-function for
further
\hâ\n[lss]uâinformation.
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâwend ? end a while-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâwhile(a<b)
\hâ\n[lss]uâ?
\hâ\n[lss]uâwend
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
wend-keyword marks the end of a while-loop. Please see the
while-keyword
\hâ\n[lss]uâfor more details.
\hâ\n[lss]uâwend can be written as end while or even end-while.
\hâ\n[lss]uâExample
\hâ\n[lss]uâline
input "Please enter a sentence: " a$
\hâ\n[lss]uâp=instr(a$,"e")
\hâ\n[lss]uâwhile(p)
\hâ\n[lss]uâmid$(a$,p,1)="E"
\hâ\n[lss]uâp=instr(a$,"e")
\hâ\n[lss]uâwend
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâThis
example reads a sentence and converts every occurrence of
the letter e
\hâ\n[lss]uâinto uppercase (E).
\hâ\n[lss]uâSee also
\hâ\n[lss]uâwhile (which is just the following entry).
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâwhile ? start a while-loop
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâwhile(?)
\hâ\n[lss]uâ?
\hâ\n[lss]uâwend
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
while-keyword starts a while-loop, i.e. a loop that is
executed as long as
\hâ\n[lss]uâthe condition (which is specified in
braces after the keyword while) evaluates
\hâ\n[lss]uâto true.
\hâ\n[lss]uâNote,
that the body of such a while-loop will not be executed at
all, if the
\hâ\n[lss]uâcondition following the
while-keyword is not true initially.
\hâ\n[lss]uâIf you want to leave the loop prematurely, you may use the break-statement.
\hâ\n[lss]uâExample
\hâ\n[lss]uâopen
#1,"foo"
\hâ\n[lss]uâwhile(!eof(1))
\hâ\n[lss]uâline input #1 a$
\hâ\n[lss]uâprint a$
\hâ\n[lss]uâwend
\hâ\n[lss]uâThis program reads the file foo and prints it line by line.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâuntil, break, wend, do
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâorigin ? move the origin of a window
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâorigin "cc"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
origin-command applies to graphic windows and moves the
origin of the
\hâ\n[lss]uâcoordinate system to one of nine
point within the window. The normal position
\hâ\n[lss]uâof the origin is in the upper left
corner of the window; however in some cases
\hâ\n[lss]uâthis is inconvenient and moving the
origin may save you from subtracting a
\hâ\n[lss]uâconstant offset from all of your
coordinates.
\hâ\n[lss]uâHowever,
you may not move the origin to an arbitrary position; in
horizontal
\hâ\n[lss]uâposition there are only three
positions: left, center and right, which are
\hâ\n[lss]uâdecoded by the letters l, c and r.
In vertical position the allowed positions
\hâ\n[lss]uâare top, center and bottom; encoded
by the letters t, c and b. Taking the
\hâ\n[lss]uâletters together, you arrive at a
string, which might be passed as an argument
\hâ\n[lss]uâto the command; e.g. "cc"
or "rt".
\hâ\n[lss]uâExample
\hâ\n[lss]uâ100,100
\hâ\n[lss]uâopen
window 200,200
\hâ\n[lss]uâwindow origin "cc"
\hâ\n[lss]uâcircle 0,0,60
\hâ\n[lss]uâThis example draws a circle, centered at the center of the window.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâopen window
\hâ\n[lss]uâX
\hâ\n[lss]uâxor() ? compute the exclusive or
\hâ\n[lss]uâName
\hâ\n[lss]uâxor() ? compute the exclusive or
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâx=xor(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
xor computes the bitwise exclusive or of its two numeric
arguments. To
\hâ\n[lss]uâunderstand the result, both
arguments should be viewed as binary numbers (i.e.
\hâ\n[lss]uâa series of 0 and 1); a bit of the
result will then be 1, if exactly one
\hâ\n[lss]uâargument has a 1 and the other has a
0 at this position in their binary
\hâ\n[lss]uârepresentation.
\hâ\n[lss]uâNote,
that both arguments are silently converted to integer values
and that
\hâ\n[lss]uânegative numbers have their own
binary representation and may lead to
\hâ\n[lss]uâunexpected results when passed to
and.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint xor(7,4)
\hâ\n[lss]uâThis
will print 3. This result is obvious, if you note, that the
binary
\hâ\n[lss]uârepresentation of 7 and 4 are 111
and 100 respectively; this will yield 011 in
\hâ\n[lss]uâbinary representation or 2 as
decimal.
\hâ\n[lss]uâThe
eor-function is the same as the xor function; both are
synonymous; however
\hâ\n[lss]uâthey have each their own
description, so you may check out the entry of eor for
\hâ\n[lss]uâa slightly different view.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâand, or, eor, not
\hâ\n[lss]uâSpecial characters
\hâ\n[lss]uâ#
? either a comment or a marker for a file-number
\hâ\n[lss]uâ// ? starts a comment
\hâ\n[lss]uâ@ ? synonymous to at
\hâ\n[lss]uâ: ? separate commands from each
other
\hâ\n[lss]uâ; ? suppress the implicit newline
after a print-statement
\hâ\n[lss]uâ** or Ë ? raise its first
argument to the power of its second
\hâ\n[lss]uâName
\hâ\n[lss]uâ# ? either a comment or a marker for a file-number
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâ#
This is a comment, but the line below not !
\hâ\n[lss]uâopen #1,"foo"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe hash (â#â) has two totally unrelated uses:
\hâ\n[lss]uâ*
A hash might appear in commands related with file-io.
yabasic uses simple
\hâ\n[lss]uânumbers to refer to open files
(within input, print, peek or eof). In those
\hâ\n[lss]uâcommands the hash may precede the
number, which species the file. Please
\hâ\n[lss]uâsee those commands for further
information and examples; the rest of this
\hâ\n[lss]uâentry is about the second use (as a
comment).
\hâ\n[lss]uâ*
As the very first character within a line, a hash introduces
comments
\hâ\n[lss]uâ(similar to rem).
\hâ\n[lss]uââ#â
as a comment is common in most scripting languages and has a
special use
\hâ\n[lss]uâunder Unix: If the very first line
of any Unix-program begins with the
\hâ\n[lss]uâcharacter sequence â#!â
("she-bang", no spaces allowed), the rest of the
line
\hâ\n[lss]uâis taken as the program that should
be used to execute the script. I.e. if your
\hâ\n[lss]uâyabasic-program starts with
â#!/usr/local/bin/yabasicâ, the program
/usr/local/
\hâ\n[lss]uâbin/yabasic will be invoked to
execute the rest of the program. As a remark for
\hâ\n[lss]uâwindows-users: This mechanism
ensures, that yabasic will be invoked to execute
\hâ\n[lss]uâyour program; the ending of the file
(e.g. .yab) will be ignored by Unix.
\hâ\n[lss]uâExample
\hâ\n[lss]uâ#
This line is a valid comment
\hâ\n[lss]uâprint "Hello " : # But
this is a syntax error, because
\hâ\n[lss]uâprint "World!" : # the
hash is not the first character !
\hâ\n[lss]uâNote,
that this example will produce a syntax error and is not a
valid program
\hâ\n[lss]uâ!
\hâ\n[lss]uâSee also
\hâ\n[lss]uâinput, print, peek or eof, //, rem
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâ// ? starts a comment
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâ// This is a comment !
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
double-slash (â//â) is (besides REM and
â#â) the third way to start a
\hâ\n[lss]uâcomment. â//â is the
latest and greatest in the field of commenting and allows
\hâ\n[lss]uâyabasic to catch up with such cool
languages like C++ and Java.
\hâ\n[lss]uâExample
\hâ\n[lss]uâ//
Another comment.
\hâ\n[lss]uâprint "Hello world !" //
Another comment
\hâ\n[lss]uâUnlike
the example given for â#â this example is
syntactically correct and will
\hâ\n[lss]uânot produce an error.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâ#, rem
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâ@ ? synonymous to at
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâclear
screen
\hâ\n[lss]uâ?
\hâ\n[lss]uâprint @(a,b)
\hâ\n[lss]uâDescription
\hâ\n[lss]uâAs â@â is simply a synonym for at, please see at for further information.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâat
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâ: ? separate commands from each other
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint "Hello ":print "World"
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe colon (â:â) separates multiple commands on a single line.
\hâ\n[lss]uâThe
colon and the newline-character have mostly the same effect,
only that the
\hâ\n[lss]uâlatter, well, starts a new line too.
The only other difference is their effect
\hâ\n[lss]uâwithin the (so-called) short if,
which is an if-statement without the keyword
\hâ\n[lss]uâthen. Please see the entry for if
for more details.
\hâ\n[lss]uâExample
\hâ\n[lss]uâif (a<10) print "Hello ":print "World !"
\hâ\n[lss]uâThis
example demonstrates the difference between colon and
newline as described
\hâ\n[lss]uâabove.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâif
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâ; ? suppress the implicit newline after a print-statement
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint "foo",bar;
\hâ\n[lss]uâDescription
\hâ\n[lss]uâThe
semicolon (â;â) may only appear at the last
position within a print
\hâ\n[lss]uâ-statement. It suppresses the
implicit newline, which yabasic normally adds
\hâ\n[lss]uâafter each print-statement.
\hâ\n[lss]uâPut
another way: Normally the output of each print-statement
appears on a line
\hâ\n[lss]uâby itself. If you rather want the
output of many print-statements to appear on
\hâ\n[lss]uâa single line, you should end the
print-statement with a semicolon.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint "Hello ";:print "World !"
\hâ\n[lss]uâThis example prints Hello World ! in a single line.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâprint
\hâ\n[lss]uâ-------------------------------------------------------------------------------
\hâ\n[lss]uâName
\hâ\n[lss]uâ** or Ë ? raise its first argument to the power of its second
\hâ\n[lss]uâSynopsis
\hâ\n[lss]uâprint
2**b
\hâ\n[lss]uâprint 3Ë4
\hâ\n[lss]uâDescription
\hâ\n[lss]uâ**
(or Ë, which is an exact synonym), is the arithmetic
operator of
\hâ\n[lss]uâexponentiation; it requires one
number to its left and a second one to its
\hâ\n[lss]uâright; ** then raises the first
argument to the power of the second and returns
\hâ\n[lss]uâthe result. The result will only be
computed if it yields a real number (as
\hâ\n[lss]uâopposed to a complex number); this
means, that the power can not be computed,
\hâ\n[lss]uâif the first argument is negative
and the second one is fractional. On the
\hâ\n[lss]uâother hand, the second argument can
be fractional, if the first one ist
\hâ\n[lss]uâpositive; this means, that ** may be
used to compute arbitrary roots: e.g.
\hâ\n[lss]uâx**0.5 computes the square root of
x.
\hâ\n[lss]uâExample
\hâ\n[lss]uâprint 2**0.5
\hâ\n[lss]uâSee also
\hâ\n[lss]uâsqrt
\hâ\n[lss]uâReserved Words
\hâ\n[lss]uâHere
is a list of all reserved words in yabasic. Please make
sure, that you do
\hâ\n[lss]uânot try to use one of them as the
name of a variable or subroutine. Or, the
\hâ\n[lss]uâother way around: If you get some
mysterious error from yabasic and you just
\hâ\n[lss]uâcanât figure out why, then you
might be using one of the reserved words below,
\hâ\n[lss]uâwithout knowing.
\hâ\n[lss]uâAnyway, here is the list:
\hâ\n[lss]uâABS
ACOS AND ARRAYDIM ARRAYDIMENSION
\hâ\n[lss]uâARRAYSIZE AS ASC ASIN AT
\hâ\n[lss]uâATAN BEEP BELL BIN$ BIND
\hâ\n[lss]uâBITBLIT BITBLIT$ BITBLT BITBLT$ BOX
\hâ\n[lss]uâBREAK CASE CHR$ CIRCLE CLEAR
\hâ\n[lss]uâCLOSE COLOR COLOUR COMPILE CONTINUE
\hâ\n[lss]uâCOS CURVE DATA DATE$ DEC
\hâ\n[lss]uâDEFAULT DIM DO DOT ELSE
\hâ\n[lss]uâELSEIF ELSIF END ENDIF EOF
\hâ\n[lss]uâEOR ERROR EXECUTE EXECUTE$ EXIT
\hâ\n[lss]uâEXP EXPORT FI FILL FILLED
\hâ\n[lss]uâFOR FRAC GETBIT$ GETSCREEN$ GLOB
\hâ\n[lss]uâGOSUB GOTO HEX$ IF INKEY$
\hâ\n[lss]uâINPUT INSTR INT INTERRUPT LABEL
\hâ\n[lss]uâLEFT$ LEN LET LINE LOCAL
\hâ\n[lss]uâLOG LOOP LOWER$ LTRIM$ MAX
\hâ\n[lss]uâMID$ MIN MOD MOUSEB MOUSEBUTTON
\hâ\n[lss]uâMOUSEMOD MOUSEMODIFIER MOUSEX MOUSEY
NEW
\hâ\n[lss]uâNEXT NOT NUMPARAM ON OPEN
\hâ\n[lss]uâOR ORIGIN PAUSE PEEK PEEK$
\hâ\n[lss]uâPOKE PRINT PRINTER PUTBIT PUTSCREEN
\hâ\n[lss]uâRAN READ READING RECT RECTANGLE
\hâ\n[lss]uâREDIM REPEAT RESTORE RETURN REVERSE
\hâ\n[lss]uâRIGHT$ RINSTR RTRIM$ SCREEN SEEK
\hâ\n[lss]uâSIG SIN SLEEP SPLIT SPLIT$
\hâ\n[lss]uâSQR SQRT STATIC STEP STR$
\hâ\n[lss]uâSUB SUBROUTINE SWITCH SYSTEM SYSTEM$
\hâ\n[lss]uâTAN TELL TEXT THEN TIME$
\hâ\n[lss]uâTO TOKEN TOKEN$ TRIANGLE TRIM$
\hâ\n[lss]uâUNTIL UPPER$ USING VAL WAIT
\hâ\n[lss]uâWEND WHILE WINDOW WRITING XOR
\hâ\n[lss]uâPlease see here for explanations on how to use these words in yabasic.
\hâ\n[lss]uâChapter 8. Some general concepts and terms
\hâ\n[lss]uâLogical
shortcuts
\hâ\n[lss]uâConditions and expressions
\hâ\n[lss]uâReferences on arrays
\hâ\n[lss]uâSpecifying Filenames under Windows
\hâ\n[lss]uâEscape-sequences
\hâ\n[lss]uâCreating a standalone program from
your yabasic-program
\hâ\n[lss]uâThis
chapter presents some general concepts and terms, which
deserve a
\hâ\n[lss]uâdescription on their own, but are
not associated with a single command or
\hâ\n[lss]uâfunction in yabasic. Most of these
topics do not lend themselves to be read
\hâ\n[lss]uâalone, rather they might be read (or
skimmed) as background material if an
\hâ\n[lss]uâentry from the alphabetical list of
commands refers to them.
\hâ\n[lss]uâLogical shortcuts
\hâ\n[lss]uâLogical
shortcuts are no special language construct and there is no
keyword for
\hâ\n[lss]uâthem; they are just a way to
evaluate logical expressions. Logical expressions
\hâ\n[lss]uâ(i.e. a series of conditions or
comparisons joined by and or or) are only
\hâ\n[lss]uâevaluated until the final result of
the expression can be determined. An
\hâ\n[lss]uâexample:
\hâ\n[lss]uâif (a<>0 and b/a>2) print "b is at least twice as big as a"
\hâ\n[lss]uâThe
logical expression a<>0 and b/a>2 consists of two
comparisons, both of
\hâ\n[lss]uâwhich must be true, if the print
statement should be executed. Now, if the
\hâ\n[lss]uâfirst comparison (a<>0) is
false, the whole logical expression can never be
\hâ\n[lss]uâtrue and the second comparison
(b/a>2) need not be evaluated.
\hâ\n[lss]uâThis
is exactly, how yabasic behaves: The evaluation of a
composed logical
\hâ\n[lss]uâexpressions is terminated
immediately, as soon as the final result can be
\hâ\n[lss]uâdeduced from the already evaluated
parts.
\hâ\n[lss]uâIn practice, this has the following consequences:
\hâ\n[lss]uâ*
If two or more comparisons are joined with and and one
comparison results
\hâ\n[lss]uâin false, the logical expression is
evaluated no further and the overall
\hâ\n[lss]uâresult is false.
\hâ\n[lss]uâ*
If two or more comparisons are joined with or and one
comparison results in
\hâ\n[lss]uâtrue, the logical expression is
evaluated no further and the result is
\hâ\n[lss]uâtrue.
\hâ\n[lss]uâ?Nice,
but whats this good for ??, I hear you say. Well, just have
another look
\hâ\n[lss]uâat the example, especially the
second comparison (b/a>2); dividing b by a is
\hâ\n[lss]uâpotentially hazardous: If a equals
zero, the expression will cause an error and
\hâ\n[lss]uâyour program will terminate. To
avoid this, the first part of the comparison (a
\hâ\n[lss]uâ<>0) checks, if the second one
can be evaluated without risk. This pre-checking
\hâ\n[lss]uâis the most common usage and primary
motivation for logical shortcuts (and the
\hâ\n[lss]uâreason why most programming
languages implement them).
\hâ\n[lss]uâConditions and expressions
\hâ\n[lss]uâWell,
bottomline there is no difference or distinction between
conditions and
\hâ\n[lss]uâexpressions, at least as yabasic is
concerned. So you may assign the result of
\hâ\n[lss]uâcomparisons to variables or use an
arithmetic expression or a simple variable
\hâ\n[lss]uâwithin a condition (e.g. within an
if-statement). So the constructs shown in
\hâ\n[lss]uâthe example below are all totally
valid:
\hâ\n[lss]uâinput "Please enter a number between 1 and 10: " a
\hâ\n[lss]uârem
Assigning the result of a comparison to a variable
\hâ\n[lss]uâokay=a>=1 and a<=10
\hâ\n[lss]uârem
Use a variable within an if-statement
\hâ\n[lss]uâif (not okay) error "Wrong,
wrong !"
\hâ\n[lss]uâSo
conditions and expressions are really the same thing (at
least as long as
\hâ\n[lss]uâyabasic is concerned). Therefore the
terms conditions and expression can really
\hâ\n[lss]uâbe used interchangeably, at least in
theory. In reality the term condition is
\hâ\n[lss]uâused in connection with if or while
whereas the term expression tends to be
\hâ\n[lss]uâused more often within arithmetic
context.
\hâ\n[lss]uâReferences on arrays
\hâ\n[lss]uâReferences
on arrays are the only way to refer to an array as a whole
and to
\hâ\n[lss]uâpass it to subroutines or functions
like arraydim or arraysize. Whereas (for
\hâ\n[lss]uâexample) a(2) designates the second
element of the array a, a() (with empty
\hâ\n[lss]uâbraces) refers to the array a
itself. a() is called an array reference.
\hâ\n[lss]uâIf
you pass an array reference to one of your own subroutines,
you need to be
\hâ\n[lss]uâaware, that the subroutine will be
able to modify the array you have passed in.
\hâ\n[lss]uâSo passing an array reference does
not create a copy of the array; this has
\hâ\n[lss]uâsome interesting consequences:
\hâ\n[lss]uâ*
Speed and space: Creating a copy of an array would be a time
(and resource)
\hâ\n[lss]uâconsuming operation; passing just a
reference is cheap and fast.
\hâ\n[lss]uâ*
Returning many values: A subroutine, that wants to give back
more than one
\hâ\n[lss]uâvalue, may require an array
reference among its arguments and then store
\hâ\n[lss]uâits many return values within this
array. This is the only way to return
\hâ\n[lss]uâmore than one value from a
subroutine.
\hâ\n[lss]uâSpecifying Filenames under Windows
\hâ\n[lss]uâAs
you probably know, windows uses the character
â\â to separate the
\hâ\n[lss]uâdirectories within a pathname; an
example would be C:\yabasic\yabasic.exe (the
\hâ\n[lss]uâusual location of the yabasic
executable). However, the very same character
â\â
\hâ\n[lss]uâis used to construct escape
sequences, not only in yabasic but in most other
\hâ\n[lss]uâprogramming languages.
\hâ\n[lss]uâTherefore
the string "C:\t.dat" does not specify the file
t.dat within the
\hâ\n[lss]uâdirectory C:; this is because the
sequence â\tâ is translated into the
\hâ\n[lss]uâtab-character. To specify this
filename, you need to use the string "C:\\t.dat"
\hâ\n[lss]uâ(note the double slash
â\\â).
\hâ\n[lss]uâEscape-sequences
\hâ\n[lss]uâEscape-sequences
are the preferred way of specifying âspecialâ
characters. They
\hâ\n[lss]uâare introduced by the
â\â-character and followed by one of a few
regular
\hâ\n[lss]uâletters, e.g. â\nâ or
â\râ (see the table below).
\hâ\n[lss]uâEscape-sequences
may occur within any string at any position; they are
replaced
\hâ\n[lss]uâat parsetime (opposed to runtime),
i.e. as soon as yabasic discovers the
\hâ\n[lss]uâstring, with their corresponding
special character. As a consequence of this
\hâ\n[lss]uâlen("\a") returns 1,
because yabasic replaces "\a" with the matching
special
\hâ\n[lss]uâcharacter just before the program
executes.
\hâ\n[lss]uâTable 8.1. Escape sequences
\hâ\n[lss]uâ+--------------------------------------------+
\hâ\n[lss]uâ|Escape Sequence| Matching special
character |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\n |newline |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\t |tabulator |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\v |vertical tabulator |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\b |backspace |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\r |carriage return |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\f |formfeed |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\a |alert (i.e. a beeping sound)|
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\\ |backslash |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\â |single quote |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\" |double quote |
\hâ\n[lss]uâ|---------------+----------------------------|
\hâ\n[lss]uâ|\xHEX |chr$(HEX) (see below) |
\hâ\n[lss]uâ+--------------------------------------------+
\hâ\n[lss]uâNote,
that an escape sequences of the form \xHEX allows one to
encode arbitrary
\hâ\n[lss]uâcharacters as long as you know their
position (as a hex-number) within the
\hâ\n[lss]uâascii-charset: For example \x012 is
transformed into the character chr$(18) (or
\hâ\n[lss]uâchr$(dec("12",16)). Note
that \x requires a hexa-decimal number (and the
\hâ\n[lss]uâhexa-decimal string "12"
corresponds to the decimal number 18).
\hâ\n[lss]uâCreating a standalone program from your yabasic-program
\hâ\n[lss]uâCreating
a standalone-program from the command line
\hâ\n[lss]uâCreating a standalone-program from
within your program
\hâ\n[lss]uâDownsides of creating a standalone
program
\hâ\n[lss]uâSee also
\hâ\n[lss]uâNote
\hâ\n[lss]uâThe
bind-feature, which is described below, is at an
experimental stage right
\hâ\n[lss]uânow. It works (at least for me !)
under Windows and Linux, but I cannot even
\hâ\n[lss]uâpromise it for other variants of
Unix. However, if it does not work for your
\hâ\n[lss]uâUnix, I will at least try to make it
work, if you give me sufficient
\hâ\n[lss]uâinformation of your system.
\hâ\n[lss]uâSometimes
you may want to give one of your yabasic-programs to other
people.
\hâ\n[lss]uâHowever, what if those other people
do not have yabasic installed ? In that
\hâ\n[lss]uâcase you may create a
standalone-program from your yabasic-program, i.e. an
\hâ\n[lss]uâexecutable, that may be executed on
its own, standalone, even (and especially
\hâ\n[lss]uâ!) on computers, that do not have
yabasic installed. Having created a
\hâ\n[lss]uâstandalone program, you may pass it
around like any other program (e.g. one
\hâ\n[lss]uâwritten in C) and you can be sure
that your program will execute right away.
\hâ\n[lss]uâSuch
a standalone-program is simply created by copying the full
yabasic
\hâ\n[lss]uâ-interpreter and your
yabasic-program (plus all the libraries it does import)
\hâ\n[lss]uâtogether into a single, new program,
whose name might be chosen at will (under
\hâ\n[lss]uâwindows of course it should have the
ending .exe). If you decide to create a
\hâ\n[lss]uâstandalone-program, there are three
bits in yabasic, that you may use:
\hâ\n[lss]uâ*
The bind-command, which does the actual job of creating the
standalone
\hâ\n[lss]uâprogram from the yabasic-interpreter
and your program.
\hâ\n[lss]uâ*
The command-line Option --bind (see options), which does the
same from the
\hâ\n[lss]uâcommand-line.
\hâ\n[lss]uâ*
The special peek("isbound"), which may be used to
check, if the yabasic
\hâ\n[lss]uâ-program containing this peek is
bound to the interpreter as part of a
\hâ\n[lss]uâstandalone program.
\hâ\n[lss]uâWith
these bits you know enough to create a standalone-program.
Actually there
\hâ\n[lss]uâare two ways to do this: on the
command line and from within your program.
\hâ\n[lss]uâCreating a standalone-program from the command line
\hâ\n[lss]uâLetâs say you have the following very simple program within the file foo.yab:
\hâ\n[lss]uâprint "Hello World !"
\hâ\n[lss]uâNormally
you would start this yabasic-program by typing yabasic
foo.yab and as
\hâ\n[lss]uâa result the string Hello World !
would appear on your screen. However, to
\hâ\n[lss]uâcreate a standalone-program from
foo.yab you would type:
\hâ\n[lss]uâyabasic -bind foo.exe foo.yab
\hâ\n[lss]uâThis
command does not execute your program foo.yab but rather
create a
\hâ\n[lss]uâstandalone-program foo.exe. Note:
under Unix you would probably name the
\hâ\n[lss]uâstandalone program foo or such,
omitting the windows-specific ending .exe.
\hâ\n[lss]uâYabasic
will confirm by printing something like: ---Info:
Successfully bound
\hâ\n[lss]uââyabasicâ and
âfoo.yabâ into âfoo.exeâ.
\hâ\n[lss]uâAfter
that you will find a program foo.exe (which must be made
executable with
\hâ\n[lss]uâthe chmod-command under Unix first).
Now, executing this program foo.exe (or
\hâ\n[lss]uâfoo under Unix) will produce the
output Hello World !.
\hâ\n[lss]uâThis
newly created program foo.exe might be passed around to
anyone, even if he
\hâ\n[lss]uâdoes not have yabasic installed.
\hâ\n[lss]uâCreating a standalone-program from within your program
\hâ\n[lss]uâIt
is possible to write a yabasic-program, that binds itself to
the yabasic
\hâ\n[lss]uâ-interpreter. Here is an
example:
\hâ\n[lss]uâif
(!peek("isbound")) then
\hâ\n[lss]uâbind "foo"
\hâ\n[lss]uâprint "Successfully created the
standalone executable âfooâ !"
\hâ\n[lss]uâexit
\hâ\n[lss]uâendif
\hâ\n[lss]uâprint "Hello World !"
\hâ\n[lss]uâIf
you run this program (which may be saved in the file
foo.yab) via yabasic
\hâ\n[lss]uâfoo.yab, the
peek("isbound") in the first line will check, if
the program is
\hâ\n[lss]uâalready part of a
standalone-program. If not (i.e. if the yabasic-interpreter
\hâ\n[lss]uâand the yabasic-program are separate
files) the bind-command will create a
\hâ\n[lss]uâstandalone program foo containing
both. As a result you would see the output
\hâ\n[lss]uâSuccessfully created the standalone
executable âfooâ !. Note: Under Windows you
\hâ\n[lss]uâwould probably choose the filename
foo.exe.
\hâ\n[lss]uâNow,
if you run this standalone executable foo (or foo.exe), the
very same
\hâ\n[lss]uâyabasic-program that is shown above
will be executed again. However, this time
\hâ\n[lss]uâthe peek("isbound") will
return TRUE and therefore the condition of the
\hâ\n[lss]uâif-statement is false and the three
lines after then are not executed. Rather
\hâ\n[lss]uâthe last print-statement will run,
and you will see the output Hello World !.
\hâ\n[lss]uâThat way a yabasic-program may turn itself into a standalone-program.
\hâ\n[lss]uâDownsides of creating a standalone program
\hâ\n[lss]uâNow,
before you go out and turn all your yabasic-programs into
standalone
\hâ\n[lss]uâprograms, please take a second to
consider the downsides of doing so:
\hâ\n[lss]uâ*
The new standalone program will be at least as big as the
interpreter
\hâ\n[lss]uâitself, so you need to pass a few
hundred kilobytes around, just to save
\hâ\n[lss]uâpeople from having to install
yabasic themselves.
\hâ\n[lss]uâ*
There is no easy way to extract your yabasic-program from
within the
\hâ\n[lss]uâstandalone program: If you ever want
to change it, you need to have it
\hâ\n[lss]uâaround separately.
\hâ\n[lss]uâ*
If a new version of yabasic becomes available, again you
need to recreate
\hâ\n[lss]uâall of your standalone programs to
take advantage of bugfixes and
\hâ\n[lss]uâimprovements.
\hâ\n[lss]uâSo,
being able to create a standalone program is certainly a
good thing, but
\hâ\n[lss]uâcertainly not a silver bullet.
\hâ\n[lss]uâSee also
\hâ\n[lss]uâThe bind-command, the peek-function and the command line options.
\hâ\n[lss]uâChapter 9. A few example programs
\hâ\n[lss]uâA
very simple program
\hâ\n[lss]uâThe demo of yabasic
\hâ\n[lss]uâA very simple program
\hâ\n[lss]uâThe program below is a very simple program:
\hâ\n[lss]uârepeat
\hâ\n[lss]uâinput "Please enter the first
number, to add " a
\hâ\n[lss]uâinput "Please enter the second
number, to add " b
\hâ\n[lss]uâprint a+b
\hâ\n[lss]uâuntil(a=0 and b=0)
\hâ\n[lss]uâThis
program requests two numbers, which it than adds. The
process is repeated
\hâ\n[lss]uâuntil you enter zero (or nothing)
twice.
\hâ\n[lss]uâThe demo of yabasic
\hâ\n[lss]uâThe
listing below is the demo of yabasic. Note, that parts of
this demo have
\hâ\n[lss]uâbeen written before some of the more
advanced features (e.g subroutines) of
\hâ\n[lss]uâyabasic have been implemented. So
please do not take this as a particular good
\hâ\n[lss]uâexample of yabasic-code.
\hâ\n[lss]uâ//
\hâ\n[lss]uâ// This program demos yabasic
\hâ\n[lss]uâ//
\hâ\n[lss]uâ//
Check, if screen is large enough
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâsw=peek("screenwidth"):sh=peek("screenheight")
\hâ\n[lss]uâif (sw<78 or sh<24) then
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint " Sorry, but your screen
is to small to run this demo !"
\hâ\n[lss]uâprint
\hâ\n[lss]uâend
\hâ\n[lss]uâendif
\hâ\n[lss]uâsw=78:sh=24
\hâ\n[lss]uâ//
Initialize everything
\hâ\n[lss]uârestore mmdata
\hâ\n[lss]uâread mmnum:dim mmtext$(mmnum)
\hâ\n[lss]uâfor a=1 to mmnum:read
mmtext$(a):next a
\hâ\n[lss]uâ//
Main loop selection of demo
\hâ\n[lss]uâysel=1
\hâ\n[lss]uâlabel mainloop
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint
colour("cyan","magenta") at(7,2)
"################################"
\hâ\n[lss]uâprint
colour("cyan","magenta") at(7,3)
"################################"
\hâ\n[lss]uâprint
colour("cyan","magenta") at(7,4)
"################################"
\hâ\n[lss]uâprint
colour("yellow","blue") at(8,3) "
This is the demo for yabasic "
\hâ\n[lss]uâyoff=7
\hâ\n[lss]uâfor a=1 to mmnum
\hâ\n[lss]uâif (a=mmnum) then ydisp=1:else
ydisp=0:fi
\hâ\n[lss]uâif (a=ysel) then
\hâ\n[lss]uâprint
colour("blue","green")
at(5,yoff+ydisp+a) mmtext$(a);
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint at(5,yoff+ydisp+a) mmtext$(a);
\hâ\n[lss]uâendif
\hâ\n[lss]uânext a
\hâ\n[lss]uâprint at(3,sh-3) "Move
selection with CURSOR KEYS (or u and d),"
\hâ\n[lss]uâprint at(3,sh-2) "Press RETURN
or SPACE to choose, ESC to quit."
\hâ\n[lss]uâdo
// loop for keys pressed
\hâ\n[lss]uârev=1
\hâ\n[lss]uâdo // loop for blinking
\hâ\n[lss]uâk$=inkey$(0.4)
\hâ\n[lss]uâif (k$="") then
\hâ\n[lss]uâif (ysel=mmnum) then
\hâ\n[lss]uâif (rev=1) then
\hâ\n[lss]uâprint
colour("blue","green")
at(5,yoff+mmnum+1) mmtext$(mmnum);
\hâ\n[lss]uârev=0
\hâ\n[lss]uâelse
\hâ\n[lss]uâprint
colour("yellow","red")
at(5,yoff+mmnum+1) mmtext$(mmnum);
\hâ\n[lss]uârev=1
\hâ\n[lss]uâendif
\hâ\n[lss]uâendif
\hâ\n[lss]uâelse // key has been pressed, leave
loop
\hâ\n[lss]uâbreak
\hâ\n[lss]uâendif
\hâ\n[lss]uâloop // loop for blinking
\hâ\n[lss]uâyalt=ysel
\hâ\n[lss]uâif (k$="up" or
k$="u") then
\hâ\n[lss]uâif (ysel=1) then ysel=mmnum else
ysel=ysel-1 fi
\hâ\n[lss]uâredraw():heal():continue
\hâ\n[lss]uâfi
\hâ\n[lss]uâif (k$="down" or
k$="d") then
\hâ\n[lss]uâif (ysel=mmnum) then ysel=1 else
ysel=ysel+1 fi
\hâ\n[lss]uâredraw():heal():continue
\hâ\n[lss]uâfi
\hâ\n[lss]uâif (k$=" " or
k$="enter" or k$="right") then
\hâ\n[lss]uâon ysel gosub
overview,bitmap,tetraeder,endit
\hâ\n[lss]uâgoto mainloop
\hâ\n[lss]uâfi
\hâ\n[lss]uâif (k$="esc") then
\hâ\n[lss]uâendit()
\hâ\n[lss]uâfi
\hâ\n[lss]uâbeep
\hâ\n[lss]uâprint at(3,sh-5) "Invalid key:
",k$," "
\hâ\n[lss]uâloop // loop for keys pressed
\hâ\n[lss]uâ//
redraw line
\hâ\n[lss]uâsub redraw()
\hâ\n[lss]uâif (yalt=mmnum) then ydisp=1:else
ydisp=0:fi
\hâ\n[lss]uâprint at(5,yoff+yalt+ydisp)
mmtext$(yalt);
\hâ\n[lss]uâif (ysel=mmnum) then ydisp=1:else
ydisp=0:fi
\hâ\n[lss]uâprint
colour("blue","green")
at(5,yoff+ysel+ydisp) mmtext$(ysel);
\hâ\n[lss]uâreturn
\hâ\n[lss]uâend sub
\hâ\n[lss]uâ//
erase a line
\hâ\n[lss]uâsub heal()
\hâ\n[lss]uâprint at(3,sh-5) " "
\hâ\n[lss]uâreturn
\hâ\n[lss]uâend sub
\hâ\n[lss]uâ//
Go here to exit
\hâ\n[lss]uâlabel endit
\hâ\n[lss]uâprint at(3,sh-8) "Hope you
liked it ...\n ";
\hâ\n[lss]uâexit
\hâ\n[lss]uâreturn
\hâ\n[lss]uâ//
Present a short overview
\hâ\n[lss]uâlabel overview
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint " Yabasic is a quite
traditional basic: It comes with"
\hâ\n[lss]uâprint " print, input,
for-next-loops, goto, gosub, while and"
\hâ\n[lss]uâprint " repeat. It has user
defined procedures and libraries,"
\hâ\n[lss]uâprint " however, it is not
object oriented.\n"
\hâ\n[lss]uâprint " Yabasic makes it easy
to open a window, draw lines"
\hâ\n[lss]uâprint " and print the resulting
picture.\n"
\hâ\n[lss]uâprint " Yabasic programs are
interpreted and run under Unix"
\hâ\n[lss]uâprint " and Windows. The
Yabasic interpreter (around 200K)"
\hâ\n[lss]uâprint " and any Yabasic program
can be glued together to"
\hâ\n[lss]uâprint " form a standalone
executable.\n"
\hâ\n[lss]uâprint " Yabasic is free
software, i.e. subject to the"
\hâ\n[lss]uâprint " MIT License.\n"
\hâ\n[lss]uâprint "\n\n\n While you read
this, I am calculating prime numbers,\n"
\hâ\n[lss]uâprint " Press any key to return
to main menu ..."
\hâ\n[lss]uâcan=1
\hâ\n[lss]uâprint at(6,17) "This is a prime
number: "
\hâ\n[lss]uâlabel nextcan
\hâ\n[lss]uâcan=can+2
\hâ\n[lss]uâfor i=2 to sqrt(can):if
(frac(can/i)=0) then goto notprime:fi:next i
\hâ\n[lss]uâprint at(32,17) can;
\hâ\n[lss]uâlabel notprime
\hâ\n[lss]uâif
(lower$(inkey$(0))<>"") then
\hâ\n[lss]uâprint at(10,sh) "Wrapping
around once ...";
\hâ\n[lss]uâfor x=1 to sw
\hâ\n[lss]uâa$=getscreen$(0,0,1,sh-2)
\hâ\n[lss]uâb$=getscreen$(1,0,sw-1,sh-2)
\hâ\n[lss]uâputscreen b$,0,0
\hâ\n[lss]uâputscreen a$,sw-1,0
\hâ\n[lss]uânext x
\hâ\n[lss]uâsleep 2
\hâ\n[lss]uâreturn
\hâ\n[lss]uâfi
\hâ\n[lss]uâgoto nextcan
\hâ\n[lss]uâ//
Show some animated bitmaps
\hâ\n[lss]uâlabel bitmap
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint
\hâ\n[lss]uâprint "Yabasic offers some
commands for drawing simple graphics."
\hâ\n[lss]uâprint reverse at(5,12) " Press
any key to return to main menu ... "
\hâ\n[lss]uân=20
\hâ\n[lss]uâopen window 400,400
\hâ\n[lss]uâfor
b=20 to 0 step -1
\hâ\n[lss]uâcolor 255-b*12,0,b*12
\hâ\n[lss]uâfill circle 200,200,b
\hâ\n[lss]uânext b
\hâ\n[lss]uâc$=getbit$(179,179,221,221)
\hâ\n[lss]uâfor a=1 to 2000
\hâ\n[lss]uâcolor ran(255),ran(255),ran(255)
\hâ\n[lss]uâx=ran(500)-100:y=ran(500)-100
\hâ\n[lss]uâfill rectangle
ran(500)-100,ran(500)-100,ran(500)-100,ran(500)-100
\hâ\n[lss]uânext a
\hâ\n[lss]uâx=200:y=200:phi=ran(2*pi):dx=2*sin(phi):dy=2*cos(phi)
\hâ\n[lss]uâo$=""
\hâ\n[lss]uâcount=0
\hâ\n[lss]uâlabel pong
\hâ\n[lss]uâcount=count+1
\hâ\n[lss]uâif (o$<>"") putbit
o$,xo-2,yo-2
\hâ\n[lss]uâif (count>1000) then
\hâ\n[lss]uâphi=ran(2*pi):dx=2*sin(phi):dy=2*cos(phi)
\hâ\n[lss]uâsleep 2
\hâ\n[lss]uâcount=0
\hâ\n[lss]uâendif
\hâ\n[lss]uâxo=x:yo=y
\hâ\n[lss]uâx=x+dx:y=y+dy
\hâ\n[lss]uâo$=getbit$(x-2,y-2,x+46,y+46)
\hâ\n[lss]uâputbit c$,x,y,"t"
\hâ\n[lss]uâif (x<0 or x>360) dx=-dx
\hâ\n[lss]uâif (y<0 or y>360) dy=-dy
\hâ\n[lss]uâif (inkey$(0)<>"")
then
\hâ\n[lss]uâclose window
\hâ\n[lss]uâreturn
\hâ\n[lss]uâendif
\hâ\n[lss]uâgoto pong
\hâ\n[lss]uâreturn
\hâ\n[lss]uâlabel tetraeder
\hâ\n[lss]uâopen
window 400,400
\hâ\n[lss]uâclear window
\hâ\n[lss]uâclear screen
\hâ\n[lss]uâprint reverse at(5,12) " Press
any key to return to main menu ... "
\hâ\n[lss]uâdim
opoints(4,3)
\hâ\n[lss]uârestore points
\hâ\n[lss]uâfor n=1 to 4:for p=1 to 3:read
opoints(n,p):next p:next n
\hâ\n[lss]uâdim
triangles(4,3)
\hâ\n[lss]uârestore triangles
\hâ\n[lss]uâfor n=1 to 4:for p=1 to 3:read
triangles(n,p):next p:next n
\hâ\n[lss]uâphi=0:dphi=0.1:psi=0:dpsi=0.05
\hâ\n[lss]uâdim points(4,3)
\hâ\n[lss]uâr=60:g=20
\hâ\n[lss]uâdr=0.5:dg=1.2:db=3
\hâ\n[lss]uâlabel main
\hâ\n[lss]uâphi=phi+dphi
\hâ\n[lss]uâpsi=psi+dpsi
\hâ\n[lss]uâfor n=1 to 4
\hâ\n[lss]uâpoints(n,1)=opoints(n,1)*cos(phi)-opoints(n,2)*sin(phi)
\hâ\n[lss]uâpoints(n,2)=opoints(n,2)*cos(phi)+opoints(n,1)*sin(phi)
\hâ\n[lss]uâp2=
points(n,2)*cos(psi)-opoints(n,3)*sin(psi)
\hâ\n[lss]uâpoints(n,3)=opoints(n,3)*cos(psi)+
points(n,2)*sin(psi)
\hâ\n[lss]uâpoints(n,2)=p2
\hâ\n[lss]uânext n
\hâ\n[lss]uâr=r+dr:if
(r<0 or r>60) dr=-dr
\hâ\n[lss]uâg=g+dg:if (g<0 or g>60) dg=-dg
\hâ\n[lss]uâb=b+db:if (b<0 or b>60) db=-db
\hâ\n[lss]uâdm=dm+0.01
\hâ\n[lss]uâm=120-80*sin(dm)
\hâ\n[lss]uâfor n=1 to 4
\hâ\n[lss]uâp1=triangles(n,1)
\hâ\n[lss]uâp2=triangles(n,2)
\hâ\n[lss]uâp3=triangles(n,3)
\hâ\n[lss]uân1=points(p1,1)+points(p2,1)+points(p3,1)
\hâ\n[lss]uân2=points(p1,2)+points(p2,2)+points(p3,2)
\hâ\n[lss]uân3=points(p1,3)+points(p2,3)+points(p3,3)
\hâ\n[lss]uâif (n3>0) then
\hâ\n[lss]uâsp=n1*0.5-n2*0.7-n3*0.6
\hâ\n[lss]uâcolor
60+r+30*sp,60+g+30*sp,60+b+30*sp
\hâ\n[lss]uâfill triangle
200+m*points(p1,1),200+m*points(p1,2),200+m*points(p2,1),200+m*points(p2,2),200+m*points(p3,1),200+m*points(p3,2)
\hâ\n[lss]uâendif
\hâ\n[lss]uânext n
\hâ\n[lss]uâif (inkey$(0.1)<>"")
close window:return
\hâ\n[lss]uâclear window
\hâ\n[lss]uâgoto main
\hâ\n[lss]uâlabel
points
\hâ\n[lss]uâdata -1,-1,+1, +1,-1,-1, +1,+1,+1,
-1,+1,-1
\hâ\n[lss]uâlabel triangles
\hâ\n[lss]uâdata 1,2,4, 2,3,4, 1,3,4, 1,2,3
\hâ\n[lss]uâ//
Data section ...
\hâ\n[lss]uâlabel mmdata
\hâ\n[lss]uâ// Data for main menu: Number and
text of entries in main menu
\hâ\n[lss]uâdata 4
\hâ\n[lss]uâdata " Yabasic in a nutshell
"
\hâ\n[lss]uâdata " Some graphics "
\hâ\n[lss]uâdata " A rotating Tetraeder
"
\hâ\n[lss]uâdata " Exit this demo
"
\hâ\n[lss]uâChapter 10. The Copyright of yabasic
\hâ\n[lss]uâyabasic
may be copied under the terms of the MIT License, which is
distributed
\hâ\n[lss]uâwith yabasic in the file
LICENSE.
\hâ\n[lss]uâThe
MIT License grants extensive rights as long as you keep the
copyright
\hâ\n[lss]uânotice present in most files
untouched. Here is a list of things that are
\hâ\n[lss]uâpossible under the terms of the MIT
License:
\hâ\n[lss]uâ*
Put yabasic on your own homepage or CD and even charge for
the service of
\hâ\n[lss]uâdistributing yabasic.
\hâ\n[lss]uâ*
Write your own yabasic-programs, pack your program and
yabasic into a
\hâ\n[lss]uâpackage and sell the whole
thing.
\hâ\n[lss]uâ*
Modify yabasic and add or remove features, sell the modified
version
\hâ\n[lss]uâwithout adding the sources.
AUTHOR
Marc Ihm, with the input and suggestions from many others.
SEE ALSO
yabasic.htm - for the hyperlinked version of the text that is presented above.
www.yabasic.de - for further information on yabasic.
BUGS
Still some.