yabasic(1)
๐ yabasic(1) ๐
General Commands Manual
Hey bestie! โจ Welcome to the yabasic man page. This is the General Commands Manual entry for yabasic(1). Let's get into it! ๐ No cap, this is gonna be iconic. ๐
โจ NAME โจ
yabasic โ yet another Basic (but like, the iconic kind ๐ )
๐ 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. ๐๐ It's giving โจaccessibleโจ and we're obsessed.
This man-page is derived from yabasic.htm, which too should be installed on your system; per default in
The same information can also be found on `www.yabasic.de` ๐
Here is its content:
---
## ๐ Table of Contents ๐
- 1. Introduction
- About this document
- About yabasic
- 2. The yabasic-program under Windows
- Starting yabasic
- Options
- The context Menu
- 3. The yabasic-program under Unix
- Starting yabasic
- Options
- Setting defaults
- 4. Command line options of yabasic
- 5. Some features of yabasic, explained by topic
- print, input and others
- Control statements: loops, if and switch
- Drawing and painting
- Reading from and writing to files
- Subroutines and Libraries
- String processing
- Arithmetic and numbers
- Data and such
- Other interesting commands.
- 6. All commands and functions of yabasic listed by topic
- Number processing and conversion
- Conditions and control structures
- Data keeping and processing
- String processing
- File operations and printing
- Subroutines and libraries
- Other commands
- Graphics and printing
- 7. All commands and functions of yabasic grouped alphabetically
- A
- B
- C
- D
- E
- F
- G
- H
- I
- L
- M
- N
- O
- P
- R
- S
- T
- U
- V
- W
- X
- Special characters
- Reserved Words
- 8. Some general concepts and terms
- Logical shortcuts
- Conditions and expressions
- References on arrays
- Specifying Filenames under Windows
- Escape-sequences
- Creating a standalone program from your yabasic-program
- 9. A few example programs
- A very simple program
- The demo of yabasic
- 10. The Copyright of yabasic
---
## Chapter 1. Introduction
### About this document
### About yabasic
### About this document
This document describes <pink>yabasic</pink>. You will find information about the yabasic interpreter (the program `yabasic` under Unix or `yabasic.exe` under Windows) as well as the language (which is, of course, a sort of basic) itself.
This document applies to version <hotpink>2.82</hotpink> of yabasic
However, this document does not contain the latest news about yabasic or a FAQ. As such information tends to change rapidly, it is presented online only at `www.yabasic.de`.
Although basic has its reputation as a language for beginning programmers, this is not an introduction to programming at large. Rather this text assumes, that the reader has some (moderate) experience with writing and starting computer programs.
### About yabasic
yabasic is a traditional basic interpreter. It understands most of the typical basic-constructs, like `goto`, `gosub`, line numbers, `read`, `data` or string-variables with a trailing `$`. But on the other hand, yabasic implements some more advanced programming-constructs like subroutines or libraries (but not objects). yabasic works much the same under Unix and Windows.
yabasic puts emphasis on giving results quickly and easily; therefore simple commands are provided to open a graphic window, print the graphics or control the console screen and get keyboard or mouse information. The example below opens a window, draws a circle and prints the graphic:
open window 100,100 open printer circle 50,50,40 text 10,50,"Press any key to get a printout" clear screen inkey$ close printer close window
This example has fewer lines, than it would have in many other programming languages. In the end however yabasic lacks behind more advanced and modern programming languages like C++ or Java. But as far as it goes it tends to give you results more quickly and easily.
---
## Chapter 2. The yabasic-program under Windows
### Starting yabasic
### Options
### The context Menu
### Starting yabasic
Once, yabasic has been set up correctly, there are three ways to start it:
1. Right click on your desktop: The desktop menu appears with a submenu named `new`. From this submenu choose `yabasic`. This will create a new icon on your desktop. If you right click on this icon, its context menu will appear; choose `Execute` to execute the program.
2. As a variant of the way described above, you may simply create a file with the ending `.yab` (e.g. with your favorite editor). Everything else then works as described above.
3. From the start-menu: Choose `yabasic` from your start-menu. A console-window will open and you will be asked to type in your program. Once you are finished, you need to type return twice, and yabasic will parse and execute your program.
> **Note**
>
> This is not the preferred way of starting yabasic ! Simply because the program, that you have typed, can not be saved and will be lost inevitably ! There is no such thing as a save-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs.
### Options
Under Windows yabasic will mostly be invoked by double-clicking on an appropriate icon; this way you do not have a chance to specify any of the command line options below. However, advanced users may change the `librarypath` in the registry, which has the same effect as specifying it as an option on the command line.
See the chapter on options for a complete list of all options, either on Unix or Windows.
### The context Menu
Like every other icon under Windows, the icon of every yabasic-program has a context menu offering the most frequent operations, that may be applied to a yabasic-program.
#### Execute
This will invoke yabasic to execute your program. The same happens, if you double click on the icon.
#### Edit
`notepad` will be invoked, allowing you to edit your program.
#### View docu
This will present the embedded documentation of your program. Embedded documentation is created with the special comment `doc`.
---
## Chapter 3. The yabasic-program under Unix
### Starting yabasic
### Options
### Setting defaults
### Starting yabasic
If your system administrator (vulgo `root`) has installed yabasic correctly, there are three ways to start it:
1. You may use your favorite editor (`emacs`, `vi` ?) to put your program into a file (e.g. `foo`). Make sure that the very first line starts with the characters `#!` followed by the full pathname of yabasic (e.g. `#!/usr/local/bin/yabasic`). This she-bang-line ensures, that your Unix will invoke yabasic to execute your program (see also the entry for the hash-character). Moreover, you will need to change the permissions of your yabasic-program `foo`, e.g. `chmod u+x foo`. After that you may invoke yabasic to invoke your program by simply typing `foo` (without even mentioning yabasic). However, if your `PATH`-variable does not contain a single dot (`.`) you will have to type the full pathname of your program: e.g. `/home/ihm/foo` (or at least `./foo`).
2. Save your program into a file (e.g. `foo`) and type `yabasic foo`. This assumes, that the directory, where yabasic resides, is contained within your `PATH`-variable.
3. Finally your may simply type `yabasic` (maybe it will be necessary to include its full pathname). This will make yabasic come up and you will be asked to type in your program. Once you are finished, you need to type return twice, and yabasic will parse and execute your program.
> **Note**
>
> This is not the preferred way of starting yabasic ! Simply because the program, that you have typed, can not be saved and will be lost inevitably ! There is no such thing as a save-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs, i.e. for using yabasic as some sort of fancy desktop calculator.
### Options
yabasic accepts a number of options on the command line.
See chapter on options for a complete list of all options, either on Unix or Windows.
### Setting defaults
If you want to set some options once for all, you may put them into your X-Windows resource file. This is usually the file `.Xresources` or some such within your home directory (type `man X` for details).
Here is a sample section, which may appear within this file:
yabasic*foreground: blue yabasic*background: gold yabasic*geometry: +10+10 yabasic*font: 9x15
<pink>okay so</pink> that lil' block right there? It sets the foreground color of the graphic-window to <blue>blue</blue> and the background color to <yellow>gold</yellow>. The window will show up at position `10,10` and the text font will be `9x15`. <pink>cute, right? ๐</pink>
---
# โจ Chapter 4: Command line options of yabasic โจ
<lavender>Here are the options that yabasic accepts on the command line โ and bestie, this goes for **both** Unix and Windows, so no one's left out. ๐ซถ</lavender>
<purple>All the options below may be abbreviated (and one hyphen may be dropped)</purple>, as long as the abbreviation does not become ambiguous. For example, you may write `-e` instead of `--execute`. <cyan>short queen energy โจ</cyan>
- **`--help`** or **`-?`** โ Prints a short help message, which itself describes two further help-options. <yellow>helpception fr fr</yellow>
- **`--version`** โ Prints the version of yabasic. <mint>know ur era ๐
</mint>
- **`--infolevel`** *INFOLEVEL* โ Change the infolevel of yabasic, where *INFOLEVEL* can be one of `debug`, `note`, `warning`, `error`, `fatal` and `bison` (the default is `warning`). This option changes the amount of debugging-information yabasic produces. <pink>However, normally only the author of yabasic (me !) would want to change this.</pink> <rainbow>iconic self-insert tbh ๐</rainbow>
- **`--execute`** *A-PROGRAM-AS-A-SINGLE-STRING* โ With this option you may specify some yabasic-code to be executed right away. This is useful for very short programs, which you do not want to save to a file. If this option is given, yabasic will not read any code from a file. E.g.
yabasic -e 'for a=1 to 10:print a*a:next a'
prints the square numbers from `1` to `10`. <cyan>one-liner baddie ๐ฆ</cyan>
- **`--bind`** *NAME-OF-STANDALONE-PROGRAM* โ Create a standalone program (whose name is specified by *NAME-OF-STANDALONE-PROGRAM*) from the yabasic-program, that is specified on the command line. See the section about creating a standalone-program for details. <purple>ur fave is getting its own whole executable, periodt โจ</purple>
- **`--geometry`** *+X-POSITION+Y-POSITION* โ Sets the position of the graphic window, that is opened by `open window` (the size of this window, of course, is specified within the `open window`-command). An example would be `-geometry +20+10`, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. <red>This value cannot be changed, once yabasic has been started.</red>
- **`-fg`** *FOREGROUND-COLOR* or **`--foreground`** *FOREGROUND-COLOR* โ <hotpink>Unix only.</hotpink> Define the foreground color for the graphics-window (that will be opened with `open window`). The usual X11 color names, like `red`, `green`, ? are accepted. <red>This value cannot be changed, once yabasic has been started.</red>
- **`-bg`** *BACKGROUND-COLOR* or **`--background`** *BACKGROUND-COLOR* โ <hotpink>Unix only.</hotpink> Define the background color for the graphics-window. The usual X11 color names are accepted. <red>This value cannot be changed, once yabasic has been started.</red>
- **`--display`** *X11-DISPLAY-SPECIFICATION* โ <hotpink>Unix only.</hotpink> Specify the display, where the graphics window of yabasic should appear. Normally this value will be already present within the environment variable `DISPLAY`. <mint>she knows where she belongs ๐
</mint>
- **`--font`** *NAME-OF-FONT* โ <hotpink>Under Unix.</hotpink> Name of the font, which will be used for text within the graphics window.
- **`--font`** *NAME-OF-FONT* โ <blue>Under Windows.</blue> Name of the font, which will be used for graphic-text; can be any of `decorative`, `dontcare`, `modern`, `roman`, `script`, `swiss`. You may append a fontsize (measured in pixels) to any of those fontnames; for example `-font swiss30` chooses a swiss-type font with a size of `30` pixels. <pink>swiss30 ate and left no crumbs ๐งโจ</pink>
- **`--docu`** *NAME-OF-A-PROGRAM* โ Print the embedded documentation of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword `doc`. This documentation can also be seen by choosing the corresponding entry from the context-menu of any yabasic-program. <lavender>self-documenting slay ๐</lavender>
- **`--check`** โ Check for possible compatibility problems within your yabasic-program. E.g. this option reports, if you are using a function, that has recently changed. <yellow>vibe check ur code bestie ๐</yellow>
- **`--librarypath`** *DIRECTORY-WITH-LIBRARIES* โ Change the directory, wherein libraries will be searched and imported (with the `import`-command). See also `import` for more information about the way, libraries are searched. <purple>ur imports need a home too ๐ </purple>
- **`--`** โ Do not try to parse any further options; rather pass the subsequent words from the commandline to yabasic. <cyan>everything after this is yabasic's business, not the shell's ๐
</cyan>
---
# ๐ธ Chapter 5: Some features of yabasic, explained by topic ๐ธ
- `print`, `input` and others
- Control statements: loops, `if` and `switch`
- Drawing and painting
- Reading from and writing to files
- Subroutines and Libraries
- String processing
- Arithmetic and numbers
- Data and such
- Other interesting commands.
<pink>This chapter has sections for some of the major features of yabasic and names a few commands related with each area.</pink> So, depending on your interest, you find the most important commands of this area named; the other commands from this area may then be discovered through the links in the see also-section. <rainbow>choose ur own adventure bestie โจ๐ฆ</rainbow>
## ๐ฌ `print`, `input` and others
The `print`-command is used to put text on the text screen. Here, the term <purple>text screen</purple> stands for your terminal (under Unix) or the console window (under Windows). <cyan>same vibe, different OS ๐
</cyan>
At the bottom line, `print` simply outputs its argument to the text window. However, once you have called `clear screen` you may use advanced features like printing colors or copying areas of text with `getscreen$` or `putscreen`. <pink>glow up unlocked ๐ฅ</pink>
You may ask the user for input with the `input`-command; use `inkey$` to get each key as soon as it is pressed. <yellow>instant gratification fr fr</yellow>
## ๐ Control statements: loops, `if` and `switch`
<pink>Of course, yabasic has the `goto`- and `gosub`-statements;</pink> you may go to a label or a line number (which is just a special kind of label). `goto`, despite its bad reputation ([goto considered harmful]), has still its good uses; <lavender>however in many cases you are probably better off with loops like `repeat`-`until`, `while`-`wend` or `do`-`loop`;</lavender> you may leave any of these loops with the `break`-statement or start the next iteration immediately with `continue`. <cyan>no more spaghetti code bestie ๐๐</cyan>
Decisions can be made with the `if`-statement, which comes either in a short and a long form. The short form has no `then`-keyword and extends up to the end of the line. The long form extends up to the final `endif` and may use some of the keywords `then` (which introduces the long form), `else` or `elsif`. <purple>short if is giving minimalist, long if is giving commitment ๐
</purple>
If you want to test the result of an expression against many different values, you should probably use the `switch`-statement. <yellow>the way that she matches casesโฆ ๐</yellow>
## ๐จ Drawing and painting
You need to call `open window` before you may draw anything with either `line`, `circle`, `rectangle` or `triangle`; all of these statements may be decorated with `clear` or `fill`. If you want to change the colour for drawing, use `colour`. <red>Note however, that there can only be a single window open at any given moment in time.</red> <pink>monogamy but make it graphics ๐</pink>
Everything you have drawn can be send to your printer too, if you use the `open printer` command. <mint>art goes physical, obsessed ๐จ๏ธโจ</mint>
To allow for some (very) limited version of animated graphics, yabasic offers the commands `getbit$` and `putbit`, which retrieve rectangular regions from the graphics-window into a string or vice versa. <cyan>pixel flipbook energy ๐ฆ</cyan>
If you want to sense mouse-clicks, you may use the `inkey$`-function. <pink>she's listening ๐๐</pink>
## ๐ Reading from and writing to files
Before you may read or write a file, you need to `open` it; once you are done, you should `close` it. Each open file is designated by a simple number, which might be stored within a variable and must be supplied if you want to access the file. This is simply done by putting a hash (`'#'`) followed by the number of the file after the keyword `input` (for reading from) or `print` (for writing to a file) respectively. <lavender>file handle but make it cute ๐
</lavender>
If you need more control, you may consider reading and writing one byte at a time, using the multi-purpose commands `peek` and `poke`. <yellow>one byte at a time, she's thorough fr fr</yellow>
## ๐งฉ Subroutines and Libraries
The best way to break any yabasic-program into smaller, more manageable chunks are subroutines and libraries. They are yabasic's most advanced means of structuring a program. <rainbow>architect era ๐โจ</rainbow>
Subroutines are created with the command `sub`. they accept parameters and may return a value. Subroutines can be called much like any builtin function of yabasic; therefore they allow one to extend the language itself. <pink>not her literally changing the language, main character energy ๐
</pink>
Once you have created a set of related subroutines and you feel that they could be useful in other programs too, you may collect them into a library. Such a library is contained within a separate file and may be included in any of your programs, using the keyword `import`, which see. <cyan>sharing is caring bestie ๐ซถ</cyan>
## ๐ค String processing
yabasic has a set of functions to extract parts from a string: `left$`, `mid$` and `right$`. Note, that all of them can be assigned to, i.e. they may change part of a string. <purple>they mutate, ur honor ๐
</purple>
If you want to split a string into tokens you should use the functions `token` or `split`. <yellow>tokenizing is so giving โจ</yellow>
Some functions are handy for normalizing a string: `upper$` and `lower$` convert a string to all upper or lower case respectively, whereas `chomp$` cuts of any trailing newline character, but only if present. <mint>only if present, she's polite like that ๐</mint>
`chr$` and `str$` convert a string into a number, both in different ways. <pink>two paths, one destiny ๐ฆ</pink>
To analyze a string use `instr` (finding one string within the other) or `glob` (testing a string against a simple pattern). <cyan>detective mode activated ๐</cyan>
To concatenate strings use the operator `+` like in `a$ + b$`. <lavender>gluing strings together, iconic ๐ซถ</lavender>
You may also see the complete list of a string processing functions. <purple>go explore bestie, iykyk ๐
</purple>
## โ Arithmetic and numbers
okay so <pink>numbers</pink> and <pink>arithmetic</pink>, bestie ๐ yabasic handles all of it. You may calculate trigonometric functions like `sin` or `atan`, or logarithms (with `log`). Bitwise operations, like `and` or `or` are available as well, plus `min` or `max` (calculate the minimum or maximum of its argument), or `mod` or `int` (the remainder of a division, or the integer part of a number). No cap โจ
Conversion between numerical bases can be done with `hex$` and `dec`. And you may write hexadecimal constants in the usual way, e.g.
print 0xff
All calculations in yabasic are done with <purple>double precision</purple>, so likeโฆ precision girlies stay winning ๐
---
## ๐ Data and such
You may store data within your program within data-statements; during execution you will probably want to read it into arrays, which must have been <hotpink>dimed</hotpink> before. Like, dim first, bestie, or it's not happening ๐
## โจ Other interesting commands.
- Yabasic programs may start other programs with the commands `system` and `system$`. ๐
- `peek` and `poke` allow one to get and set internal information; either for the operating system (i.e. Unix or Windows) or yabasic itself. ๐
- The current time or date can be retrieved with (guess what !) `time$` and `date$`. โฐ
---
# ๐ Chapter 6. All commands and functions of yabasic listed by topic
- Number processing and conversion
- Conditions and control structures
- Data keeping and processing
- String processing
- File operations and printing
- Subroutines and libraries
- Other commands
- Graphics and printing
---
## ๐ข Number processing and conversion
- **`abs()`** โ returns the absolute value of its numeric argument
- **`acos()`** โ returns the arcus cosine of its numeric argument
- **`and()`** โ the bitwise arithmetic and
- **`asin()`** โ returns the arcus sine of its numeric argument
- **`atan()`** โ returns the arctangent of its numeric argument
- **`bin$()`** โ converts a number into a sequence of binary digits
- **`cos()`** โ return the cosine of its single argument
- **`dec()`** โ convert a base 2 or base 16 number into decimal form
- **`eor()`** โ compute the bitwise exclusive or of its two arguments
- **`euler`** โ another name for the constant `2.71828182864`
- **`exp()`** โ compute the exponential function of its single argument
- **`frac()`** โ return the fractional part of its numeric argument
- **`int()`** โ return the integer part of its single numeric argument
- **`ceil()`** โ return the smallest integral number, that is greater or equal than its argument
- **`floor()`** โ return the largest integral number, that is smaller or equal than its argument
- **`log()`** โ compute the natural logarithm
- **`max()`** โ return the larger of its two arguments
- **`min()`** โ return the smaller of its two arguments
- **`mod`** โ compute the remainder of a division
- **`or()`** โ arithmetic or, used for bit-operations
- **`pi`** โ a constant with the value `3.14159`
- **`ran()`** โ return a random number
- **`sig()`** โ return the sign of its argument
- **`sin()`** โ return the sine of its single argument
- **`sqr()`** โ compute the square of its argument
- **`sqrt()`** โ compute the square root of its argument
- **`tan()`** โ return the tangent of its argument
- **`xor()`** โ compute the exclusive or
- **`**` or `^`** โ raise its first argument to the power of its second
---
## ๐ฆ Conditions and control structures
- **`and`** โ logical and, used in conditions
- **`break`** โ breaks out of a switch statement or a loop
- **`case`** โ mark the different cases within a switch-statement
- **`continue`** โ start the next iteration of a for-, do-, repeat- or while-loop
- **`default`** โ mark the default-branch within a switch-statement
- **`do`** โ start a (conditionless) do-loop
- **`else`** โ mark an alternative within an if-statement
- **`elsif`** โ starts an alternate condition within an if-statement
- **`end`** โ terminate your program
- **`endif`** โ ends an if-statement
- **`false`** โ a constant with the value of `0`
- **`fi`** โ another name for endif
- **`for`** โ starts a for-loop
- **`gosub`** โ continue execution at another point within your program (and return later)
- **`goto`** โ continue execution at another point within your program (and never come back)
- **`if`** โ evaluate a condition and execute statements or not, depending on the result
- **`label`** โ mark a specific location within your program for goto, gosub or restore
- **`loop`** โ marks the end of an infinite loop
- **`next`** โ mark the end of a for loop
- **`not`** โ negate an expression; can be written as `!`
- **`on gosub`** โ jump to one of multiple gosub-targets
- **`on goto`** โ jump to one of many goto-targets
- **`on interrupt`** โ change reaction on keyboard interrupts
- **logical `or`** โ logical or, used in conditions
- **`pause`** โ pause, sleep, wait for the specified number of seconds
- **`repeat`** โ start a repeat-loop
- **`return`** โ return from a subroutine or a gosub
- **`sleep`** โ pause, sleep, wait for the specified number of seconds
- **`switch`** โ select one of many alternatives depending on a value
- **`then`** โ tell the long from the short form of the if-statement
- **`true`** โ a constant with the value of `1`
- **`until`** โ end a repeat-loop
- **`wait`** โ pause, sleep, wait for the specified number of seconds
- **`wend`** โ end a while-loop
- **`while`** โ start a while-loop
- **`:`** โ separate commands from each other
---
## ๐ Data keeping and processing
- **`arraydim()`** โ returns the dimension of the array, which is passed as an array reference
- **`arraysize()`** โ returns the size of a dimension of an array
- **`data`** โ introduces a list of data-items
- **`dim`** โ create an array prior to its first use
- **`read`** โ read data from data-statements
- **`redim`** โ create an array prior to its first use. A synonym for dim
- **`restore`** โ reposition the data-pointer
---
## ๐ธ String processing
- **`asc()`** โ accepts a string and returns the position of its first character within the ascii charset
- **`chomp$()`** โ Chop of the trailing newline of its string-argument; if the string does not end in a newline, the string is returned unchanged
- **`chr$()`** โ accepts a number and returns the character at this position within the ascii charset
- **`glob()`** โ check if a string matches a simple pattern
- **`hex$()`** โ convert a number into hexadecimal
- **`instr()`** โ searches its second argument within the first; returns its position if found
- **`left$()`** โ return (or change) left end of a string
- **`len()`** โ return the length of a string
- **`lower$()`** โ convert a string to lower case
- **`ltrim$()`** โ trim spaces at the left end of a string
- **`mid$()`** โ return (or change) characters from within a string
- **`right$()`** โ return (or change) the right end of a string
- **`split()`** โ split a string into many strings
- **`str$()`** โ convert a number into a string
- **`token()`** โ split a string into multiple strings
- **`trim$()`** โ remove leading and trailing spaces from its argument
- **`upper$()`** โ convert a string to upper case
- **`val()`** โ converts a string to a number
---
## ๐ File operations and printing
> okay this one's a whole saga and it keeps going โ hold that thought, bestie ๐
(next part picks it right up ๐ซถ)
- **`at()`** โ lowkey the glow-up your `print` needed: use it in the print-command to drop your output at a specified position. <pink>positioning era ๐
</pink>
- **`beep`** โ rings the bell inside your computer. yes, the computer. it's a bell. it beeps. a synonym for `bell`.
- **`bell`** โ rings the bell within your computer (just as `beep`). <yellow>๐ same vibe, different spelling</yellow>
- **`clear screen`** โ erases the text window. <cyan>poof, gone, iconic</cyan>
- **`close`** โ closes a file that's been opened before.
- **`close printer`** โ stops printing of graphics. ๐จ๏ธโ
- **`print color`** โ print, but make it colorful. <rainbow>print with color</rainbow>
- **`print colour`** โ see `print color`. same thing, British spelling ate ๐
- **`eof`** โ checks if an open file contains data.
- **`getscreen$()`** โ returns a string representing a rectangular section of the text terminal.
- **`inkey$`** โ waits until a key is pressed. <pink>patience is a virtue bestie</pink>
- **`input`** โ reads input from the user (or from a file) and assigns it to a variable.
- **`line input`** โ reads in a whole line of text and assigns it to a variable.
- **`open`** โ opens a file. ๐ชโจ
- **`open printer`** โ opens the printer for printing graphics.
- **`print`** โ writes to terminal or file. <purple>the moment we've all been waiting for</purple>
- **`putscreen`** โ draws a rectangle of characters into the text terminal.
- **`reverse`** โ prints in reverse (background and foreground colors exchanged). <hotpink>aesthetic flip ๐</hotpink>
- **`screen`** โ same as `clear screen`, clears the text window.
- **`seek()`** โ changes the position within an open file.
- **`tell`** โ gets the current position within an open file. <mint>where u at fr</mint>
- **`using`** โ specifies the format for printing a number.
- **`#`** โ either a comment or a marker for a file-number.
- **`@`** โ synonymous to `at`.
- **`;`** โ suppresses the implicit newline after a print-statement.
---
### ๐ฆ Subroutines and libraries
- **`end sub`** โ ends a subroutine definition.
- **`export`** โ marks a function as globally visible. <cyan>she's famous now</cyan>
- **`import`** โ imports a library.
- **`local`** โ marks a variable as local to a subroutine.
- **`numparams`** โ returns the number of parameters that have been passed to a subroutine.
- **`return`** โ returns from a subroutine or a `gosub`.
- **`static`** โ preserves the value of a variable between calls to a subroutine. <lavender>memory queen ๐ง </lavender>
- **`step`** โ specifies the increment step in a for-loop.
- **`sub`** โ declares a user defined subroutine.
---
### ๐ Other commands
- **`bind()`** โ binds a yabasic-program and the yabasic-interpreter together into a standalone program. <purple>shipping it as one unit, periodt</purple>
- **`compile`** โ compiles a string with yabasic-code on the fly. โก
- **`date$`** โ returns a string with various components of the current date.
- **`doc`** โ a special comment, which might be retrieved by the program itself.
- **`docu$`** โ a special array containing the contents of all `docu`-statement within the program.
- **`error`** โ raises an error and terminates your program. <red>dramatic exit, honestly deserved ๐</red>
- **`execute$()`** โ executes a user defined subroutine, which must return a string.
- **`execute()`** โ executes a user defined subroutine, which must return a number.
- **`exit`** โ terminates your program.
- **`pause`** โ pause, sleep, wait for the specified number of seconds. <pink>a little break, u earned it</pink>
- **`peek`** โ retrieves various internal information.
- **`peek$`** โ retrieves various internal string-information.
- **`poke`** โ changes selected internals of yabasic.
- **`rem`** โ starts a comment.
- **`sleep`** โ pause, sleep, wait for the specified number of seconds. ๐ด
- **`system()`** โ hands a statement over to your operating system and returns its exitcode.
- **`system$()`** โ hands a statement over to your operating system and returns its output.
- **`time$`** โ returns a string containing the current time.
- **`to`** โ this keyword appears as part of other statements.
- **`wait`** โ pause, sleep, wait for the specified number of seconds.
- **`//`** โ starts a comment.
- **`:`** โ separates commands from each other.
---
### ๐ธ Graphics and printing
- **`backcolor`** โ specifies the colour for subsequent drawing of the background.
- **`box`** โ draws a rectangle. A synonym for `rectangle`.
- **`circle`** โ draws a circle in the graphic-window. โญ
- **`clear`** โ erases circles, rectangles or triangless.
- **`clear window`** โ clears the graphic window and begins a new page, if printing is under way.
- **`close curve`** โ closes a curve that has been drawn by the `line`-command.
- **`close window`** โ closes the graphics-window.
- **`colour`** โ specifies the colour for subsequent drawing.
- **`dot`** โ draws a dot in the graphic-window. <mint>tiny but mighty</mint>
- **`fill`** โ draws filled circles, rectangles or triangles.
- **`getbit$()`** โ returns a string representing the bit pattern of a rectangle within the graphic window.
- **`line`** โ draws a line.
- **`mouseb`** โ extracts the state of the mousebuttons from a string returned by `inkey$`.
- **`mousemod`** โ returns the state of the modifier keys during a mouseclick.
- **`mousex`** โ returns the x-position of a mouseclick.
- **`mousey`** โ returns the y-position of a mouseclick.
- **`new curve`** โ starts a new curve that will be drawn with the `line`-command.
- **`open window`** โ opens a graphic window.
- **`putbit`** โ draws a rectangle of pixels into the graphic window.
- **`rectangle`** โ draws a rectangle.
- **`triangle`** โ draws a triangle.
- **`text`** โ writes text into your graphic-window.
- **`window origin`** โ moves the origin of a window.
---
## ๐ Chapter 7. All commands and functions of yabasic grouped alphabetically ๐
### โจ A
### โจ B
### โจ C
### โจ D
### โจ E
### โจ F
### โจ G
### โจ H
### โจ I
### โจ L
### โจ M
### โจ N
### โจ O
### โจ P
### โจ R
### โจ S
### โจ T
### โจ U
### โจ V
### โจ W
### โจ X
### โจ Special characters
### โจ Reserved Words
---
### ๐ A
- `abs()` โ returns the absolute value of its numeric argument
- `acos()` โ returns the arcus cosine of its numeric argument
- `and` โ logical and, used in conditions
- `and()` โ the bitwise arithmetic and
- `arraydim()` โ returns the dimension of the array, which is passed as an array reference
- `arraysize()` โ returns the size of a dimension of an array
- `asc()` โ accepts a string and returns the position of its first character within the ascii charset
- `asin()` โ returns the arcus sine of its numeric argument
- `at()` โ can be used in the print-command to place the output at a specified position
- `atan()` โ returns the arctangent of its numeric argument
---
### ๐ Name
`abs()` โ returns the absolute value of its numeric argument
### ๐ Synopsis
y=abs(x)
### ๐ Description
If the argument of the `abs`-function is positive (e.g. `2`) it is returned unchanged, if the argument is negative (e.g. `-1`) it is returned as a positive value (e.g. `1`). <pink>negative vibes out, positive vibes in ๐
</pink>
### โญ Example
print abs(-2),abs(2)
This example will print `2 2`
### ๐ฆ See also
`sig`
---
### ๐ Name
`acos()` โ returns the arcus cosine of its numeric argument
### ๐ Synopsis
x=acos(angle)
### ๐ Description
`acos` is the arcus cosine-function, i.e. the inverse of the `cos`-function. Or, more elaborate: it returns the angle (in radians, **not degrees!**), which, fed to the cosine-function, will produce the argument passed to the `acos`-function. <cyan>iykyk, radians girlies stay winning</cyan>
### โญ Example
print acos(0.5),acos(cos(pi))
This example will print `1.0472 3.14159` which are ฯ/3 and ฯ respectively.
### ๐ฆ See also
`cos`, `asin`
---
### ๐ Name
`and` โ logical and, used in conditions
### ๐ Synopsis
if (a and b) โฆ while (a and b) โฆ
### ๐ Description
Used in conditions (e.g. within `if`, `while` or `until`) to join two expressions. Returns true if and only if its left and right argument are both true, and false otherwise. <green>both gotta show up, no half-effort friendships</green>
Note, that logical shortcuts may take place.
### โญ Example
input "Please enter a number" a if (a>=1 and a<=9) print "your input is between 1 and 9"
### ๐ฆ See also
`or`, `not`
---
### ๐ Name
`and()` โ the bitwise arithmetic and
### ๐ Synopsis
x=and(a,b)
### ๐ Description
Used to compute the bitwise and of both its argument. Both arguments are treated as binary numbers (i.e. a series of `0` and `1`); a bit of the resulting value will then be `1`, if both arguments have a `1` at this position in their binary representation.
> โ ๏ธ Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to `and`. <red>no cap, watch out</red>
### โญ Example
print and(6,3)
<pink>okay so</pink> this prints `2`, and bestie it's <cyan>so</cyan> obvious once you clock the binary tea โ โ the binary representation of `6` and `3` is `110` and `011` respectively, and lining those up gives you `010` in binary representation, which is `2` as decimal. <mint>math ate, no crumbs</mint> โจ
### ๐ See also
`or`, `eor` and `not` ๐ซถ
---
# ๐ฆ `arraydim()` ๐ฆ
### ๐ Name ๐
`arraydim()` ? returns the dimension of the array, which is passed as an array reference
### โจ Synopsis โจ
a=arraydim(b())
### ๐ Description ๐
So if you run the `arraydim()`-function on a one-dimensional array (that's a vector, iykyk) it hands back `1`, on a two-dimensional array (a matrix) it hands back `2`, and on and on it goes. <lavender>the way that it just keeps counting dimensions? iconic</lavender> ๐
Mostly you see this used inside subroutines that expect an array among their parameters โ those subs tend to call `arraydim` to check whether the array that got passed actually has the right dimension. Like, a subroutine meant to multiply two matrices is gonna want to vibe check that it really got invoked with two 2-dimensional arrays. <purple>fr fr</purple> ๐ง
### ๐ธ Example ๐ธ
dim a(10,10),b(10) print arraydim(a()),arraydim(b())
This will print `2 1`, which are the dimension of the arrays `a()` and `b()`. You may check out the function `arraysize` for a full-fledged example. <yellow>go look, it's a whole moment</yellow> ๐ญ
### ๐ See also
`arraysize` and `dim`.
---
# ๐ฆ `arraysize()` ๐ฆ
### ๐ Name ๐
`arraysize()` ? returns the size of a dimension of an array
### โจ Synopsis โจ
x=arraysize(a(),b)
### ๐ Description ๐
The `arraysize`-function computes the size of a specified dimension of a specified array. And here, "size" means the maximum number that may be used as an index for this array. <cyan>the more you know</cyan> โญ
First argument has to be a reference to an array, second one says which of the array's many dimensions you wanna measure to calculate the size.
<pink>An example involving subroutines, because this is where it slays:</pink> say an array got declared as `dim a(10,20)` โ that's a two-dimensional array, a matrix, main character energy ๐
. If that array gets passed as an array reference to a subroutine, the sub has <hotpink>zero</hotpink> clue what sort of array it just got handed. With the `arraydim`-function the sub can find the dimension of the array; with the `arraysize`-function it can find out the size of this array in its two dimensions, which will be `10` and `20` respectively. ๐ซถ
Our sample array is two dimensional; envision it as a matrix and that matrix has `10` lines and `20` columns (see the `dim`-statement above). More formally: the first dimension (lines) has a size of `10`, the second dimension (columns) has a size of `20`; these numbers are exactly the ones returned by `arraysize(a(),1)` and `arraysize(a(),2)` respectively. Peep the example below for a typical usage. ๐
### ๐ธ Example ๐ธ
rem rem This program adds two matrices elementwise. rem
dim a(10,20),b(10,20),c(10,20)
rem initialization of the arrays a() and b() for y=1 to 10:for x=1 to 20 a(y,x)=int(ran(4)):b(y,x)=int(ran(4)) next x:next y
matadd(a(),b(),c())
print "Result:" for x=1 to 20 for y=10 to 1 step -1 print c(y,x)," "; next y print next x
sub matadd(m1(),m2(),r())
rem This sub will add the matrices m1() and m2() rem elementwise and store the result within r() rem This is not very useful but easy to implement. rem However, this sub excels in checking its arguments rem with arraydim() and arraysize()
local x:local y
if (arraydim(m1())<>2 or arraydim(m2())<>2 or arraydim(r())<>2) then error "Need two dimensional arrays as input" endif
y=arraysize(m1(),1):x=arraysize(m1(),2) if (arraysize(m2(),1)<>y or arraysize(m2(),2)<>x) then error "The two matrices cannot be added elementwise" endif
if (arraysize(r(),1)<>y or arraysize(r(),2)<>x) then error "The result cannot be stored in the third argument" endif
local xx:local yy for xx=1 to x for yy=1 to y r(yy,xx)=m1(yy,xx)+m2(yy,xx) next yy next xx
end sub
### ๐ See also
`arraydim` and `dim`.
---
# ๐ฆ `asc()` ๐ฆ
### ๐ Name ๐
`asc()` ? accepts a string and returns the position of its first character within the ascii charset
### โจ Synopsis โจ
a=asc(char$)
### ๐ Description ๐
The `asc`-function takes a string, grabs its first character, and looks it up within the ascii-charset; that position is what gets returned. `asc`-function is literally the opposite of the `chr$`-function. There are valid uses for `asc`, <red>however</red>, comparing strings (i.e. to bring them into alphabetical sequence) is <hotpink>not</hotpink> among them; in such many cases you might consider comparing strings directly with `<`, `=` and `>` instead (rather than converting a string to a number and comparing that number). <yellow>ngl that's the move</yellow> ๐
### ๐ธ Example ๐ธ
input "Please enter a letter between 'a' and 'y': " a$ if (a$<"a" or a$>"y") print a$," is not in the proper range":end print "The letter after ",a$," is ",chr$(asc(a$)+1)
### ๐ See also
`chr$`
---
# ๐ฆ `asin()` ๐ฆ
### ๐ Name ๐
`asin()` ? returns the arcus sine of its numeric argument
### โจ Synopsis โจ
angle=asin(x)
### ๐ Description ๐
`acos` is the arcus sine-function, i.e. the inverse of the `sin`-function. Or, to be more elaborate: it returns the angle (<purple>in radians, not degrees !!</purple>) which, fed to the sine-function, will produce the argument passed to the `asin`-function. <cyan>trig but make it cute</cyan> ๐โจ
### ๐ธ Example ๐ธ
print asin(0.5),asin(sin(pi))
This will print `0.523599 -2.06823e-13` which is ? and almost `0` respectively.
### ๐ See also
`sin`, `acos`
---
# ๐ฆ `at()` ๐ฆ
### ๐ Name ๐
`at()` ? can be used in the print-command to place the output at a specified position
### โจ Synopsis โจ
clear screen ? print at(a,b) print @(a,b)
### ๐ Description ๐
The `at`-clause takes two numeric arguments (like `at(2,3)`) and can be dropped in right after the `print`-keyword. <mint>positioning era</mint> ๐
But listen: `at()` can be used <red>only if</red> `clear screen` has been executed at least once within the program โ otherwise you will get an error. <yellow>not me forgetting that and getting yelled at by the interpreter</yellow> ๐ญ
The two numeric arguments of the `at`-function may range from `0` to the width of your terminal minus 1, and from `0` to the height of your terminal minus 1; if any argument exceeds these values, it will be truncated accordingly. <lavender>however</lavender>, yabasic has <hotpink>no influence</hotpink> on the size of your terminal (`80x25` is a common, but not mandatory), so the size of your terminal and the maximum values acceptable within the `at`-clause may vary. To get the size of your terminal you may use the `peek`-function: `peek("screenwidth")` returns the width of your terminal and `peek("screenheight")` its height. ๐ซถ
### ๐ธ Example ๐ธ
clear screen maxx=peek("screenwidth")-1:maxy=peek("screenheight")-1 for x=0 to maxx print at(x,maxy*(0.5+sin(2*pi*x/maxx)/2)) "*" next x
This example plots a full period of the sine-function across the screen. <rainbow>artistic behaviour honestly</rainbow> ๐โญ
### ๐ See also
`print`, `clear screen`, `color`
---
# ๐ฆ `atan()` ๐ฆ
### ๐ Name ๐
`atan()` ? returns the arctangent of its numeric argument
### โจ Synopsis โจ
angle=atan(a,b) angle=atan(a)
### ๐ Description ๐
`atan` is the arctangent-function, i.e. the inverse of the `tan`-function. Or, more elaborate: it returns the angle (<purple>in radians, not degrees !!</purple>) which, fed to the `tan`-function, will produce the argument passed to the `atan`-function. ๐
The `atan`-function has a second form, which accepts two arguments: `atan(a,b)` which is (mostly) equivalent to `atan(a/b)` โ except for the fact that the two-argument-form returns an angle in the range -? to ?, whereas the one-argument-form returns an angle in the range -?/2 to ?/2. To understand this you have to be good at math. <blue>sorry bestie, i don't make the rules</blue> ๐ญ
### ๐ธ Example ๐ธ
print atan(1),atan(tan(pi)),atan(-0,-1),atan(-0,1)
This will print `0.463648 2.06823e-13 -3.14159 3.14159` which is ?/4, almost `0`, -? and ? respectively. โจ
### ๐ See also
`tan`, `sin`
---
# ๐ B ๐
<pink>okay bestie, alphabet time โ here's everything starting with B, quick-fire:</pink> ๐ฅ
- `backcolor` ? change color for background of graphic window
- `backcolour` ? see `backcolor`
- `beep` ? ring the bell within your computer; a synonym for `bell`
- `bell` ? ring the bell within your computer (just as `beep`)
- `bin$()` ? converts a number into a sequence of binary digits
- `bind()` ? Binds a yabasic-program and the yabasic-interpreter together into a standalone program.
- `box` ? draw a rectangle. A synonym for `rectangle`
- `break` ? breaks out of one or more loops or switch statements
---
# ๐ฆ `backcolour` ๐ฆ
### ๐ Name ๐
`color` ? change color for background of graphic window
### โจ Synopsis โจ
backcolour red,green,blue backcolour "red,green,blue"
### ๐ Description ๐
<pink>backcolour</pink> is the glow-up for your <hotpink>background</hotpink> โ it changes the color that becomes visible whenever any portion of the window gets erased, like right after a `clear window` or a `clear line`. ๐
> heads up bestie: parts of the window that are still showing the OLD background color will **not** change. it's giving stubborn. ๐
And just like the `color`-command, the new background color can come to you either as a <purple>triple of three numbers</> or as a <purple>single string</> that has those three numbers separated by commas. โจ
**Example**
open window 255,255 for x=10 to 235 step 10:for y=10 to 235 step 10 backcolour x,y,0 clear window sleep 1 next y:next x
This one keeps switching the background colour of the graphic window and clears it every single time, so the whole thing ends up filled with the brand-new background colour. ๐ฆ
**See also**
`open window`, `color`, `line`, `rectangle`, `triangle`, `circle`
---
## Name ๐ธ
`backcolour` ? see `backcolor`
## Synopsis
backcolour red,green,blue backcolour "red,green,blue"
## See also
`color`
---
## Name ๐ธ
`beep` ? ring the bell within your computer; a synonym for `bell`
## Synopsis
beep
## Description
The `bell`-command rings the bell inside your computer **once**. And no, bestie, this is not a whole sound-interface โ you can't change the length or the pitch of the sound (technically, it literally just prints `\a`). `bell` is exactly the same as `beep`. ๐๏ธ
## Example
beep:print "This is a problem ..."
## See also
`beep`
---
## Name ๐ธ
`bell` ? ring the bell within your computer (just as `beep`)
## Synopsis
bell
## Description
The `beep`-command rings the bell inside your computer **once**. `beep` is a synonym for `bell`. ๐
## Example
print "This is a problem ...":beep
## See also
`bell`
---
## Name ๐ธ
`bin$()` ? converts a number into a sequence of binary digits
## Synopsis
hexadecimal$=bin$(decimal)
## Description
The `bin$`-function takes a single numeric argument and converts it into a string of binary digits (that's zeroes and ones, iykyk). If you pass a negative number to `bin$`, the resulting string gets a `-` slapped in front of it. ๐
And if you wanna go the other way around โ like from binary back to decimal โ you can use the `dec`-function. ๐
## Example
for a=1 to 100 print bin$(a) next a
This example prints the binary representation of all digits between 1 and 100. ๐ง
## See also
`hex$`, `dec`
---
## Name ๐ธ
`bind()` ? Binds a yabasic-program and the yabasic-interpreter together into a standalone program.
## Synopsis
bind("foo.exe")
## Description
The `bind`-command glues your own yabasic-program (plus every library it imports) together with the interpreter by copying them into a **new file**, whose name you pass as an argument. This new program can then run on any computer, even one that does *not* have yabasic installed. iconic, honestly. ๐
Please see the section about creating a standalone-program for all the deets.
## Example
if (!peek("isbound")) then bind "foo" print "Successfully created the standalone executable 'foo' !" exit endif
print "Hello World !"
This example creates a standalone program `foo` from itself. main character energy fr fr. โจ
## See also
The section about creating a standalone-program, the `peek`-function and the command line options.
---
## Name ๐ธ
`box` ? draw a rectangle. A synonym for `rectangle`
## Synopsis
See the `rectangle`-command.
## Description
The `box`-command does exactly the same thing as the `rectangle`-command โ it's just a synonym, no cap. So for anything more you should head over to the entry for the `rectangle`-command. ๐
---
## Name ๐ธ
`break` ? breaks out of one or more loops or switch statements
## Synopsis
break break 2
## Description
`break` yeets control immediately outside the enclosing loop or `switch` statement. This is the **preferred** way of leaving such a statement (rather than `goto`, which is still possible in most cases). An optional digit lets you break out of multiple levels โ like leaving a loop from inside a `switch` statement. ๐
> ngl, only a literal (e.g. `2`) is allowed at this location. don't get cute with it.
## Example
for a=1 to 10 break print "Hi" next a
while(1) break print "Hi" wend
repeat break print "Hi" until(0)
switch 1 case 1:break case 2:case 3:print "Hi" end switch
This example prints absolutely nothing at all, because each of the loops (and the `switch`-statement) does an immediate `break` โ before it could ever print any `"Hi"`. ๐
## See also
`for`, `while`, `repeat` and `switch`.
---
# ๐ฆ C ๐ฆ
- `case` ? mark the different cases within a `switch`-statement
- `ceil()` ? compute the ceiling for its (float) argument.
- `chomp$()` ? Remove a single trailing newline from its string-argument; if the string does not end in a newline, the string is returned unchanged.
- `chr$()` ? accepts a number and returns the character at this position within the ascii charset
- `circle` ? draws a circle in the graphic-window
- `clear` ? Erase circles, rectangles or triangles
- `clear screen` ? erases the text window
- `clear window` ? clear the graphic window and begin a new page, if printing is under way
- `close` ? close a file, which has been opened before
- `close curve` ? close a curve, that has been drawn by the `line`-command
- `close printer` ? stops printing of graphics
- `close window` ? close the graphics-window
- `color` ? change color for any subsequent drawing-command
- `colour` ? see `color`
- `compile` ? compile a string with yabasic-code on the fly
- `continue` ? start the next iteration of a `for`-, `do`-, `repeat`- or `while`-loop
- `cos()` ? return the cosine of its single argument
---
## Name ๐ธ
`case` ? mark the different cases within a `switch`-statement
## Synopsis
switch a case 1 case 2 ? end switch
?
switch a$ case "a" case "b" ? end switch
## Description
Please see the `switch`-statement. ๐
## Example
input a switch(a) case 1:print "one":break case 2:print "two":break default:print "more" end switch
Depending on your input (a number is expected), this code will print `one`, or `two`, or otherwise `more`. ๐
## See also
`switch`
---
## Name ๐ธ
`ceil()` ? compute the ceiling for its (float) argument.
## Synopsis
print ceil(x)
## Description
The `ceil`-function returns the **smallest integer number** that is larger or equal to its argument. โฌ๏ธ
## Example
print ceil(1.5),floor(1.5) print ceil(2),floor(2)
Comparing the functions `ceil` and `floor` gives a first line of output (`1 2`), showing that `ceil` is less or equal than `floor`; but as the second line of output (`2 2`) shows, the two functions give equal results for integer arguments. math ate that. ๐งฎโจ
## See also
`floor`, `int`, `frac`
---
## Name ๐ธ
`chomp$()` ? Remove a single trailing newline from its string-argument; if the string does not end in a newline, the string is returned unchanged.
## Synopsis
print chomp$("Hallo !\n")
## Description
The `chomp$`-function checks if its string-argument ends in a newline and removes it if so โ so `chomp$` can straight-up replace an if-statement. super handy when you're dealing with input from external sources like `system$`. ๐ซถ
You can apply `chomp$` freely, because it only acts when there's actually a newline to remove. note however that user-input coming from the normal `input`-statement does **not** need this treatment, since it already arrives without a newline. ๐
## Example
The following yabasic-program uses the unix-command `whoami` to grab the username of the current user and greet them personally. It does this twice: first with the `chomp$`-function and then again with an equivalent if-statement:
print "Hello " + chomp$(system$("whoami")) + " !"
user$ = system$("whoami") if (right$(user$,1)="\n") user$=left$(user$,len(user$)-1) print "Hello again " + user$ + " !"
## <rainbow>Name</rainbow> ๐
<hotpink>`chr$()`</hotpink> โ accepts a number and returns the character at this position within the ascii charset โจ
## <rainbow>Synopsis</rainbow>
character$=chr$(ascii)
## <rainbow>Description</rainbow>
okay so bestie, `chr$` is literally the *opposite* of the `asc`-function ๐
It goes and looks up the character sitting at the position you give it inside the ascii-charset, and hands it right back to you. The classic use case? Building nonprintable characters that your keyboard simply does not have a key for ๐ซถ
That said, you won't be reaching for `chr$` as much as you'd think, because the most important nonprintable characters can be constructed with escape-sequences using the `\`-character โ like, you might use `\n` instead of `chr$(10)` literally anywhere you want the newline-character ๐ธ
## <rainbow>Example</rainbow>
print "a",chr$(10),"b"
This prints the letters `'a'` and `'b'` on different lines, because of that newline-character sitting in between them, which is what `chr$(10)` returns ๐ฅ
## <rainbow>See also</rainbow>
`asc`
---
## <rainbow>Name</rainbow> ๐
<hotpink>`circle`</hotpink> โ draws a circle in the graphic-window ๐ฆ
## <rainbow>Synopsis</rainbow>
circle x,y,r clear circle x,y,r fill circle x,y,r clear fill circle x,y,r
## <rainbow>Description</rainbow>
The `circle`-command takes three parameters: the x- and y-coordinates of the <purple>center</purple>, and the <purple>radius</purple> of the circle โจ
And some more observations related to the `circle`-command, bestie, listen up:
- The graphic-window must have been opened already ๐
- The circle may well extend over the boundaries of the window โ she does not care, she goes where she wants ๐
- If you have issued `open printer` before, the circle will finally appear in the printed hard copy of the window ๐จ๏ธ
- `fill circle` will draw a filled (with black ink) circle ๐ค
- `clear circle` will erase (or clear) the outline of the circle ๐งผ
- `clear fill circle` or `fill clear circle` will erase the full area of the circle ๐
## <rainbow>Example</rainbow>
open window 200,200
for n=1 to 2000 x=ran(200) y=ran(200) fill circle x,y,10 clear fill circle x,y,8 next n
This code opens a window and draws 2000 overlapping circles inside it ๐ Each circle gets drawn in two steps: first it's filled with black ink (`fill circle x,y,10`), then most of that circle gets erased again (`clear fill circle x,y,8`). And as a result, every circle ends up with an opaque white interior and a 2-pixel outline โ 2-pixel because the radii differ by two โญ
## <rainbow>See also</rainbow>
`open window`, `open printer`, `line`, `rectangle`, `triangle`
---
## <rainbow>Name</rainbow> ๐ธ
<hotpink>`clear`</hotpink> โ Erase circles, rectangles or triangles ๐ง
## <rainbow>Synopsis</rainbow>
clear rectangle 10,10,90,90 clear fill circle 50,50,20 clear triangle 10,10,20,20,50,30
## <rainbow>Description</rainbow>
You use this inside the `circle`, `rectangle` or `triangle` command, and it makes those shapes get erased โ i.e. drawn in the colour of the background โจ
`fill` can be used in conjunction with it, and wherever the fill-clause may appear. Used *alone*, `clear` will erase the outline (not the interior) of the shape โ circle, rectangle or triangle, whichever one you're on. But together with `fill`, the whole shape (interior included) gets erased ๐
## <rainbow>Example</rainbow>
open window 200,200 fill circle 100,100,50 clear fill rectangle 10,10,90,90
This opens a window and draws a pacman-like figure ๐ iconic honestly
## <rainbow>See also</rainbow>
`clear`, `circle`, `rectangle`, `triangle`
---
## <rainbow>Name</rainbow> ๐
<hotpink>`clear screen`</hotpink> โ erases the text window ๐งผ
## <rainbow>Synopsis</rainbow>
clear screen
## <rainbow>Description</rainbow>
`clear screen` erases the text window โ that's the window where the output of `print` shows up โจ
It must be issued at least once before some advanced screen-commands (like `print at` or `inkey$`) may be called. This requirement is due to some limitations of the curses-library, which is what yabasic uses under Unix for certain commands ๐
## <rainbow>Example</rainbow>
clear screen print "Please press a key : "; a$=inkey$ print a$
The `clear screen` command is essential here โ if it were omitted, yabasic would issue an error (`"need to call 'clear screen' first"`) while trying to execute the `inkey$`-function ๐ญ
## <rainbow>See also</rainbow>
`inkey$`
---
## <rainbow>Name</rainbow> ๐ฆ
<hotpink>`clear window`</hotpink> โ clear the graphic window and begin a new page, if printing is under way ๐จ๏ธ
## <rainbow>Synopsis</rainbow>
clear window
## <rainbow>Description</rainbow>
`clear window` clears the graphic window ๐ And if you have started printing the graphic via `open printer`, the `clear window`-command starts a new page as well ๐
## <rainbow>Example</rainbow>
open window 200,200 open printer "t.ps"
for a=1 to 10 if (a>1) clear window text 100,100,"Hallo "+str$(a) next a
close printer close window
This example prints 10 pages, with the text `"Hello 1"`, `"Hello 2"`, โฆ and so on ๐ The `clear screen`-command clears the graphics window and starts a new page.
## <rainbow>See also</rainbow>
`open window`, `open printer`
---
## <rainbow>Name</rainbow> ๐
<hotpink>`close`</hotpink> โ close a file, which has been opened before ๐
## <rainbow>Synopsis</rainbow>
close filenum close # filenum
## <rainbow>Description</rainbow>
The `close`-command closes an open file ๐
And bestie, you should issue this command as soon as you're done reading from or writing to a file โ no leaving things hanging, fr fr โจ
## <rainbow>Example</rainbow>
open "my.data" for reading as 1 input #1 a print a close 1
This program opens the file `"my.data"`, reads a number from it, prints that number, and closes the file again ๐ซถ
## <rainbow>See also</rainbow>
`open`
---
## <rainbow>Name</rainbow> ๐ธ
<hotpink>`close curve`</hotpink> โ close a curve, that has been drawn by the `line`-command ๐
## <rainbow>Synopsis</rainbow>
new curve line to x1,y1 ? close curve
## <rainbow>Description</rainbow>
The `close curve`-command closes a sequence of lines that has been drawn by repeated `line to`-commands โจ
## <rainbow>Example</rainbow>
open window 200,200 new curve line to 100,50 line to 150,150 line to 50,150 close curve
This example draws a triangle ๐บ The three `line to`-commands draw two lines; the final line is not drawn explicitly though โ it gets drawn by the `close curve`-command instead. iconic ๐
## <rainbow>See also</rainbow>
`line`, `new curve`
---
## <rainbow>Name</rainbow> ๐จ๏ธ
<hotpink>`close printer`</hotpink> โ stops printing of graphics ๐
## <rainbow>Synopsis</rainbow>
close printer
## <rainbow>Description</rainbow>
The `close printer`-command ends the printing of graphics ๐ Between `open printer` and `close printer`, everything you draw (e.g. circles, lines โฆ) is sent to your printer ๐จ๏ธ And `close printer` puts an end to printing โ and will make your printer eject the page ๐
## <rainbow>Example</rainbow>
open window 200,200 open printer circle 100,100,50 close printer close window
The moment `close printer` is executed, your printer will eject a page with a circle on it ๐ฅ
## <rainbow>See also</rainbow>
`open printer`
---
## <rainbow>Name</rainbow> ๐
<hotpink>`close window`</hotpink> โ close the graphics-window ๐ช
## <rainbow>Synopsis</rainbow>
close window
## <rainbow>Description</rainbow>
The `close window`-command closes the graphics-window, i.e. it makes it disappear from your screen ๐จ And it includes an implicit `close printer`, if a printer has been opened previously ๐
## <rainbow>Example</rainbow>
open window 200,200 circle 100,100,50 close window
This example will open a window, draw a circle, and close the window again โ all of this with no pause or delay whatsoever, so the window will be closed before you may regard the circle.. ๐ like you literally blink and she's gone, no cap
## <rainbow>See also</rainbow>
`open window`
---
## <rainbow>Name</rainbow> ๐
<hotpink>`color`</hotpink> โ change color for any subsequent drawing-command ๐จ
## <rainbow>Synopsis</rainbow>
colour red,green,blue colour "red,green,blue"
## <rainbow>Description</rainbow>
Change the color in which lines, dots, circles, rectangles or triangles are drawn ๐๏ธ The `color`-command accepts three numbers in the range `0` โ `255` (like in the first line of the synopsis above). Those numbers specify the intensity for the primary colors red, green and blue respectively. For example, `255,0,0` is red and `255,255,0` is yellow ๐
Alternatively you may specify the color with a single string (like in the second line of the synopsis above) โ this string should contain three numbers, separated by commas. For example, `"255,0,255"` would be violet ๐ And using this variant of the `colour`-command, you may use symbolic names for colours:
open window 100,100 yellow$="255,255,0" color yellow$ text 50,50,"Hallo"
<purple>...which ngl reads *so* much clearer, bestie. look at it. it's giving legibility. ๐
</purple>
### Example
open window 255,255 for x=10 to 235 step 10:for y=10 to 235 step 10 colour x,y,0 fill rectangle x,y,x+10,y+10 next y:next x
So this one just <mint>fills the whole window with a grid of colored rectangles</mint>. iconic behaviour, truly. BUT โ and this is the plot twist โ <red>none of the colours used contain any shade of blue</red>, because the `color`-command always has `0` as its third argument. zero blue. no blue at all. the blue erasure is real ๐ญ
### See also
`open window`, `backcolor`, `line`, `rectangle`, `triangle`, `circle`
---
# ๐ธ Name ๐ธ
<pink>`colour`</pink> ? see `color`
# ๐ธ Synopsis ๐ธ
colour red,green,blue colour "red,green,blue"
# ๐ธ See also ๐ธ
`color`
---
# โจ Name โจ
<pink>`compile`</pink> ? compile a string with yabasic-code on the fly
# โจ Synopsis โจ
compile(code$)
# โจ Description โจ
okay so this one is <purple>advanced</purple>, bestie โ it's closely related to the `execute`-command, they're basically siblings. what it does is let you <mint>compile a string of yabasic-code</mint>, and that string is the **only** argument. after that? the compiled code is just... a normal part of your program. it lives there now. it's part of the family. ๐ซถ
> Heads up though: there is <red>no way to remove the compiled code</red>. once it's in, it's in. no take-backs. periodt.
### Example
compile("sub mysub(a):print a:end sub") mysub(2)
This example creates a function named `mysub`, which simply prints its single argument. one job. does it well. slay. โจ
### See also
`execute`
---
# โจ Name โจ
<pink>`continue`</pink> ? start the next iteration of a for-, do-, repeat- or while-loop
# โจ Synopsis โจ
continue
# โจ Description โจ
You may use `continue` inside <mint>any</mint> loop to immediately jump to the next iteration. no waiting, no finishing the rest of the body, we're moving ON. ๐
Here's the tea though โ depending on which type of loop you're in, the loop-condition <yellow>will or will not</yellow> get checked. Specifically:
- `for`- and `while`-loops **will** evaluate their respective conditions.
- `do`- and `repeat`-loops **will not**.
> <purple>Remark:</purple> another way to change the flow of execution inside a loop is the `break`-command. different vibe, different job, iykyk.
### Example
for a=1 to 100 if mod(a,2)=0 continue print a next a
This one prints <rainbow>all the odd numbers between 1 and 100</rainbow>. every even number gets politely skipped. not today, evens. ๐
### See also
`for`, `do`, `repeat`, `while`, `break`
---
# ๐ฆ Name ๐ฆ
<pink>`cos()`</pink> ? return the cosine of its single argument
# ๐ฆ Synopsis ๐ฆ
x=cos(angle)
# ๐ฆ Description ๐ฆ
The `cos`-function expects an angle (in <yellow>radians</yellow>, bestie, not degrees, don't do that to yourself) and returns its cosine. that's it. that's the whole thing. math girlies rise ๐ง
### Example
print cos(pi)
This example will print `-1`. iconic result honestly.
### See also
`acos`, `sin`
---
# ๐ D ๐
- `data` ? introduces a list of data-items
- `date$` ? returns a string with various components of the current date
- `dec()` ? convert a base 2 or base 16 number into decimal form
- `default` ? mark the default-branch within a switch-statement
- `dim` ? create an array prior to its first use
- `do` ? start a (conditionless) do-loop
- `doc` ? special comment, which might be retrieved by the program itself
- `docu$` ? special array, containing the contents of all docu-statement within the program
- `dot` ? draw a dot in the graphic-window
---
# โญ Name โญ
<pink>`data`</pink> ? introduces a list of data-items
# โญ Synopsis โญ
data 9,"world" ? read b,a$
# โญ Description โญ
The `data`-keyword introduces a comma-separated list of strings or numbers, and you can grab them later with the `read`-command. it's like a lil snack drawer for your program. ๐
The `data`-command itself <purple>does nothing</purple> โ it just stores data. and one single `data`-command can precede an <mint>arbitrarily long</mint> list of values, mixing strings and numbers however you want. go wild.
yabasic internally uses a <yellow>data-pointer</yellow> to keep track of where you currently are in the data-list, and that pointer can be reset with the `restore`-command. rewind button, basically. โช
### Example
do restore for a=1 to 4 read num$,num print num$,"=",num next a loop data "eleven",11,"twelve",12,"thirteen",13,"fourteen",14
This example just prints a series of lines `eleven=11` up to `fourteen=14` and so on <red>without end</red>. forever. an infinite slay, if you will.
The `restore`-command makes sure the list of data-items is read from the start with every iteration. ๐
### See also
`read`, `restore`
---
# ๐ Name ๐
<pink>`date$`</pink> ? returns a string with various components of the current date
# ๐ Synopsis ๐
a$=date$
# ๐ Description ๐
The `date$`-function returns a string containing various components of a date. example: `4-05-27-2004-Thu-May`.
> โ ๏ธ Important, bestie: this one **must be called without parentheses**. like, `date$()` <red>would be an error</red>. no parens. none. we don't do that here. ๐
This string is made of several fields separated by hyphens (`"-"`):
- The day within the week as a number in the range `0` (=Sunday) to `6` (=Saturday) (in the example above: `4`, i.e. Thursday).
- The month as a number in the range `1` (=January) to `12` (=December) (in the example: `5`, which stands for May).
- The day within the month as a number in the range `1` to `31` (in the example: `27`).
- The full, 4-digit year (in the example: `2004`, which reminds me that I should adjust the clock within my computer ๐ญ).
- The abbreviated name of the day within the week (`Mon` to `Sun`).
- The abbreviated name of the month (`Jan` to `Dec`).
So the whole example above (`4-05-27-2004-Thu-May`) would read: day `4` in the week (counting from `0`), May `27` in the year `2004`, which is a Thursday in May. see? it all adds up. the math is mathing. ๐ง
Also note that all fields in the string returned by `date$` have a <yellow>fixed width</yellow> (numbers get padded with zeroes), which means it's super easy to pull the various fields out with `mid$`. chef's kiss. ๐
### Example
rem Two ways to print the same ... print mid$(date$,3,10)
dim fields$(6) a=split(date$,fields$(),"-") print fields$(2),"-",fields$(3),"-",fields$(4)
This example shows <mint>two different techniques</mint> to extract components from the value returned by `date$`. The `mid$`-function is the <purple>preferred</purple> way, but you could just as well split the return-value of `date$` at every `"-"` and store the result inside an array of strings. both valid. one's just more main character. ๐
### See also
`time$`
---
# ๐ธ Name ๐ธ
<pink>`dec()`</pink> ? convert a base 2 or base 16 number into decimal form
# ๐ธ Synopsis ๐ธ
a=dec(number$) a=dec(number$,base)
# ๐ธ Description ๐ธ
The `dec`-function takes the string-representation of a <yellow>base-2</yellow> or <yellow>base-16</yellow> number (base-16 is the default) and converts it into a decimal number. the optional second argument (`base`) lets you specify a base other than `16` โ **however**, currently only base `2` or base `16` are supported, so don't get creative. ๐
Also, quick tip: for base `16` you can just write literals the usual way by putting `0x` in front, like
print 0xff
which might save you from applying `dec` altogether. work smarter, not harder. โจ
### Example
input "Please enter a binary number: " a$ print a$," is ",dec(a$)
### See also
`bin$`, `hex$`
---
# ๐ Name ๐
<pink>`default`</pink> ? mark the default-branch within a switch-statement
# ๐ Synopsis ๐
switch a+3 case 1 ? case 2 ? default ? end switch
# ๐ Description ๐
The `default`-clause is an <purple>optional</purple> part of the `switch`-statement (go read that one for the full lore). It introduces a series of statements that get executed <mint>if none of the cases match</mint> โ specifically, none of the cases that were specified before it, each with its own `case`-clause.
So `default` specifies a default to be executed when none of the explicitly named cases matches. hence the name. it's literally in the name, bestie. ๐ซถ
### Example
print "Please enter a number between 0 and 6," print "specifying a day in the week." input d switch d case 0:print "Monday":break case 1:print "Tuesday":break case 2:print "Wednesday":break case 3:print "Thursday":break case 4:print "Friday":break case 5:print "Saturday":break case 6:print "Sunday":break default:print "Hey you entered something invalid !" end switch
This program translates a number between `0` and `6` into the name of a weekday, and the `default`-case is there to <red>detect (and complain about) invalid input</red>. the default branch is basically the friend who calls you out. ๐
### See also
`sub`, `case`
---
# ๐ Name ๐
<pink>`dim`</pink> ? create an array prior to its first use
# ๐ Synopsis ๐
dim array(x,y) dim array$(x,y)
# ๐ Description ๐
The `dim`-command prepares one or more arrays (of either strings or numbers) for later use. it's the lil pre-game ritual before your array hits the stage. โจ
This command can also be used to <mint>enlarge an existing array</mint>. glow-up, but for data structures. ๐
...okay so when you `dim` an array, yabasic actually <pink>allocates memory</pink> for it and every single element gets initialized โ <green>0</green> if it's a numerical array, <purple>""</purple> if it's a string array. That's it, that's the starting state, no mystery values lurking in there ๐
If the array <hotpink>already existed</hotpink> and your `dim` says a <yellow>bigger</yellow> size than what it currently is? Slay, the array gets enlarged and literally all the old content is preserved ๐ซถ
> โ ๏ธ But bestie listen: `dim` **cannot shrink** an array. If you specify a size that's smaller than the current size, the `dim`-command does <red>nothing</red>. Zero. Nada. It's giving "I'm not doing that" ๐
And finally, the plot twist: if you want an array that's only known inside <purple>one single subroutine</purple>, use the `local` command instead โ it creates local variables *and* local arrays. iykyk โจ
### โจ Example โจ
dim a(5,5) for x=1 to 5:for y=1 to 5 a(x,y)=int(ran(100)) next y:next x printmatrix(a()) dim a(7,7) printmatrix(a())
sub printmatrix(ar()) local x,y,p,q x=arraysize(ar(),1) y=arraysize(ar(),2) for q=1 to y for p=1 to y print ar(p,q),"\t"; next p print next q end sub
So what's happening here: this example creates a <cyan>2-dimensional array</cyan> (aka a matrix, main character energy) with the `dim`-statement and fills it with random numbers ๐ฒ The second `dim`-statement <hotpink>enlarges</hotpink> the array, and all the new elements get filled with <green>0</green>.
And the subroutine `printmatrix` just does, what its name says. No cap, it prints the matrix ๐
### โจ See also โจ
`arraysize`, `arraydim`, `local`
---
# โจ Name โจ
`do` โ start a (conditionless) do-loop
# ๐ซ Synopsis ๐ซ
do ? loop
# ๐ธ Description ๐ธ
Starts a loop, which is terminated by `loop`; everything between `do` and `loop` gets repeated <rainbow>forever</rainbow> ๐ This loop has <pink>no condition</pink>, so it's an infinite loop, bestie. But note โ a `break`- or `goto`-statement can be used to leave this loop <yellow>anytime</yellow> ๐
# โจ Example โจ
do a=a+1 print a if (a>100) break loop
This one prints the numbers between <green>1</green> and <green>101</green>. The `break`-statement is what's used to leave the loop โ without it you'd be stuck there till the heat death of the universe ๐ญ
# โจ See also โจ
`loop`, `repeat`, `while`, `break`
---
# โจ Name โจ
`doc` โ special comment, which might be retrieved by the program itself
# ๐ซ Synopsis ๐ซ
doc This is a comment docu This is another comment
# ๐ธ Description ๐ธ
Introduces a comment, which spans up to the end of the line โ๏ธ But unlike the `rem`-comment, any docu-comment is <hotpink>collected</hotpink> inside the special `docu$`-array and might be retrieved later on ๐ Better yet, you can invoke `yabasic -docu foo.yab` on the command line to retrieve the embedded documentation within the program `foo.yab` ๐
And instead of `doc` you may just as well write `docu` or even `documentation`. Same vibe, same energy ๐
# โจ Example โจ
rem Hi, this has been written by me rem doc This program asks for a number and doc prints this number multiplied with 2 rem rem Print out rhe above message for a=1 to arraysize(docu$()):print docu$(a):next a
rem Read and print the number input "Please input a number: " x print x*2
This program uses the comments inside its own code to print out a <cyan>help message</cyan> for the user ๐ self-documenting queen behavior
The contents of the `doc`-lines are retrieved from the `docu$`-array; if you do <red>not</red> want a comment to be collected within that array, use the `rem`-statement instead ๐ซถ
# โจ See also โจ
`docu$`, `rem`
---
# โจ Name โจ
`docu$` โ special array, containing the contents of all docu-statement within the program
# ๐ซ Synopsis ๐ซ
a$=docu$(1)
# ๐ธ Description ๐ธ
Before your program is even executed, yabasic collects the content of all the `doc`-statements within your program inside this <purple>1-dimensional array</purple> ๐ (well, only those within the main-program โ libraries are skipped, sorry bestie ๐)
You may use the `arraysize` function to find out how many lines it contains ๐
# โจ Example โจ
docu docu This program reads two numbers docu and adds them. docu
rem retrieve and print the embedded documentation for a=1 to arraysize(docu$(),1) print docu$(a) next a
input "First number: " b input "Second number: " c
print "The sum of ",b," and ",c," is ",b+c
This program uses the embedded documentation to issue a <hotpink>usage-message</hotpink>. It's giving "I wrote my own help text and I'm proud of it" โจ
# โจ See also โจ
`arraydim`, `rem`
---
# โจ Name โจ
`dot` โ draw a dot in the graphic-window
# ๐ซ Synopsis ๐ซ
dot x,y clear dot x,y
# ๐ธ Description ๐ธ
Draws a dot at the specified coordinates within your graphic-window ๐จ If printing is in effect, the dot appears on your printout too ๐จ๏ธ
Use the functions `peek("winheight")` or `peek("winwidth")` to get the size of your window and hence the boundaries of the coordinates specified for the `dot`-command ๐
# โจ Example โจ
open window 200,200 circle 100,100,100 do x=ran(200):y=ran(200) dot x,y total=total+1 if (sqrt((x-100)^2+(y-100)^2)<100) in=in+1 print 4*in/total loop
This program uses a well known algorithm to compute ? ๐งฎ math girlies rise up
# โจ See also โจ
`line`, `open window`
---
# โจ E โจ
okay bestie, here's the whole <rainbow>E roster</rainbow> โ every command, function and constant starting with E, in one iconic lineup ๐
- **`else`** โ mark an alternative within an `if`-statement
- **`elsif`** โ starts an alternate condition within an `if`-statement
- **`end`** โ terminate your program
- **`endif`** โ ends an `if`-statement
- **`end sub`** โ ends a subroutine definition
- **`eof`** โ check, if an open file contains data
- **`eor()`** โ compute the bitwise exclusive or of its two arguments
- **`error`** โ raise an error and terminate your program
- **`euler`** โ another name for the constant `2.71828182864`
- **`execute$()`** โ execute a user defined subroutine, which must return a string
- **`execute()`** โ execute a user defined subroutine, which must return a number
- **`exit`** โ terminate your program
- **`exp()`** โ compute the exponential function of its single argument
- **`export`** โ mark a function as globally visible
---
# โจ Name โจ
`else` โ mark an alternative within an `if`-statement
# ๐ซ Synopsis ๐ซ
if (?) then ? else ? endif
# ๐ธ Description ๐ธ
The `else`-statement introduces the <purple>alternate branch</purple> of an `if`-statement ๐
Like, it starts the sequence of statements that gets executed when the condition of the `if`-statement is <red>not true</red>. It's the "okay plan B" of your code ๐ซถ
# โจ Example โจ
input "Please enter a number: " a if (mod(a,2)=1) then print a," is odd." else print a," is even." endif
This program detects if the number you entered is even or odd ๐ข classic, iconic, never misses
# โจ See also โจ
`if`
---
# โจ Name โจ
`elsif` โ starts an alternate condition within an `if`-statement
# ๐ซ Synopsis ๐ซ
if (?) then ? elseif (?) ? elsif (?) then ? else ? endif
# ๐ธ Description ๐ธ
The `elsif`-statement is used to select a <hotpink>single alternative</hotpink> among a series of choices โจ
With each `elsif`-statement you may specify a condition, which is tested if the main condition (specified with the `if`-statement) has failed. And note โ `elsif` might just as well be written as `elseif` ๐ same energy, different spelling
In the example below, two variables `a` and `b` are tested against a range of values. The variable `a` is tested with the `elsif`-statement. The very same tests are performed for the variable `b` too โ but there an involved series of `if`-`else`-statements is employed, making the tests <red>much more obscure</red> ๐ not it
# โจ Example โจ
input "Please enter a number: " a if (a<0) then print "less than 0" elseif (a<=10) then print "between 0 and 10" elsif (a<=20) print "between 11 and 20" else print "over 20" endif
input "Please enter another number: " b if (b<0) then print "less than 0" else if (b<=10) then print "between 0 and 10" else if (b<=20) then print "between 11 and 20" else print "over 20" endif endif endif
Note that the very same tests are performed for the variables `a` and `b`, but they can be stated <green>much more clearly</green> with the `elsif`-statement ๐
Note too, that `elsif` might be written as `elseif` as well, and that the keyword `then` is <yellow>optional</yellow> ๐
# โจ See also โจ
`if`, `else`
---
# โจ Name โจ
`end` โ terminate your program
# ๐ซ Synopsis ๐ซ
end
# ๐ธ Description ๐ธ
Terminate your program. Much (but not exactly) like the `exit` command ๐ it's giving "we're done here, bestie"
okay so <hotpink>real talk</hotpink> bestie: `end` might <rainbow>not</rainbow> actually end your program the *second* it runs. ๐ If you've opened a window or called clear screen, yabasic is like "hmm, my user probably wants to *study* the output after the program's done" โ so it issues the line `---Program done, press RETURN---` and then just... sits there. Waiting for a key. Any key. ๐ญ If that's not the vibe you're going for, consider using `exit` instead. ๐
## ๐ธ Example ๐ธ
print "Do you want to continue ?" input "Please answer y(es) or n(o): " a$ if (lower$(left$(a$,1))="n") then print "bye" end fi
## ๐ซถ See also ๐ซถ
`exit`
---
## ๐ Name โ `endif` ๐
`endif` ? ends an if-statement
## โจ Synopsis โจ
if (?) then ? endif
## ๐ Description ๐
The `endif`-statement closes (or ends) an `if`-statement. slay. โจ
And lowkey, `endif` is *flexible* โ you can write it a whole bunch of other ways: `end if`, `end-if` or even `fi`. ๐
**But** bestie, listen: you **must omit** `endif` if your `if`-statement doesn't contain the keyword `then` (peep the example below ๐). That kind of `if`-statement without an `endif` only stretches over a single line. no cap.
## ๐ธ Example ๐ธ
input "A number please: " a if (a<10) then print "Your number is less than 10." endif
REM and now without endif
input "A number please: " a if (a<10) print "Your number is less than 10."
## ๐ซถ See also ๐ซถ
`if`
---
## ๐ Name โ `end sub` ๐
`end sub` ? ends a subroutine definition
## โจ Synopsis โจ
sub foo(?) ? end sub
## ๐ Description ๐
This marks the end of a subroutine-definition (the thing that kicks off with the `sub` keyword). The whole concept of subroutines gets explained over in the entry for `sub`. โจ
## ๐ธ Example ๐ธ
print foo(3)
sub foo(a) return a*2 end sub
This program prints out `6`. The subroutine `foo` simply returns twice its argument. iconic behavior, honestly. ๐
## ๐ซถ See also ๐ซถ
`sub`
---
## ๐ Name โ `eof` ๐
`eof` ? check, if an open file contains data
## โจ Synopsis โจ
open 1,"foo.bar" if (eof(1)) then ? end if
## ๐ Description ๐
The `eof`-function checks if there's still data left inside an open file. As an argument it expects the file-number โ the one returned by (or used within) the `open`-function (or statement). ๐ฆ
## ๐ธ Example ๐ธ
a=open("foo.bar") while(not eof(a)) input #a,a$ print a$ end while
This example will print the contents of the file `"foo.bar"`. The `eof`-function will terminate the loop when there's no more data left in the file. ๐
## ๐ซถ See also ๐ซถ
`open`
---
## ๐ Name โ `eor()` ๐
`eor()` ? compute the bitwise exclusive or of its two arguments
## โจ Synopsis โจ
print eor(a,b)
## ๐ Description ๐
The `eor`-function takes two arguments and computes their bitwise exclusive or. Go read your favorite introductory text on informatics if you want the full lore on this function. ๐ฆ
Also the `xor`-function is the same as the `eor` function โ both are synonymous. But they each have their own description, so you can check out the entry for `xor` for a slightly different view. ๐
## ๐ธ Example ๐ธ
for a=0 to 3 for b=0 to 3 print fill$(bin$(a))," eor ",fill$(bin$(b))," = ",fill$(bin$(eor(a,b))) next b next a
sub fill$(a$) return right$("0"+a$,2) end sub
This example prints a table, and from it you can figure out how the `eor`-function is computed. โจ
## ๐ซถ See also ๐ซถ
`and`, `or`
---
## ๐ Name โ `error` ๐
`error` ? raise an error and terminate your program
## โจ Synopsis โจ
error "Wrong, wrong, wrong !!"
## ๐ Description ๐
Produces the same kind of error messages that yabasic itself produces (like when there's a syntax-error). The single argument gets issued along with the current line-number. ๐
## ๐ธ Example ๐ธ
input "Please enter a number between 1 and 10: " a if (a<1 or a>10) error "Oh no ..."
This program is **very** harsh about checking the user's input; instead of just asking again, the program terminates with an error if the user enters something wrong. ๐ญ
The error message would look like this:
---Error in t.yab, line 2: Oh no ... ---Error: Program stopped due to an error
## ๐ซถ See also ๐ซถ
Well, there should be a corresponding called `warning`; unfortunately ther is none yet. ๐
---
## ๐ Name โ `euler` ๐
`euler` ? another name for the constant 2.71828182864
## โจ Synopsis โจ
foo=euler
## ๐ Description ๐
`euler` is the well known constant named after Leonard Euler; its value is `2.71828182864`. `euler` is **not** a function, so parens are not allowed (i.e. `euler()` will produce an error). And finally, you may not assign to `euler` โ it wouldn't make sense anyway, because it's a constant. ๐
## ๐ธ Example ๐ธ
print euler
## ๐ซถ See also ๐ซถ
`pi`
---
## ๐ Name โ `execute$()` ๐
`execute$()` ? execute a user defined subroutine, which must return a string
## โจ Synopsis โจ
print execute$("foo$","arg1","arg2")
## ๐ Description ๐
`execute$` can be used to execute a user defined subroutine, whose name may be specified as a string expression. โจ
This feature is the **only** way to execute a subroutine whose name isn't known by the time you write your program. That might happen if you want to execute a subroutine which is compiled (using the `compile` command) during the course of execution of your program. ๐ฆ
Note however, that the `execute$`-function is not the preferred method to execute a user defined subroutine; in almost all cases you should just execute a subroutine by writing down its name within your yabasic program (see the example). ๐
## ๐ธ Example ๐ธ
print execute$("foo$","Hello","world !") sub foo$(a$,b$) return a$+" "+b$ end sub
The example simply prints `Hello world !`, which is the return value of the user defined subroutine `foo$`. The same could be achieved by executing:
print foo$(a$,b$)
## ๐ซถ See also ๐ซถ
`compile`, `execute`
---
## ๐ Name โ `execute()` ๐
`execute()` ? execute a user defined subroutine, which must return a number
## โจ Synopsis โจ
print execute("bar","arg1","arg2")
## ๐ Description ๐
The `execute`-function is the counterpart of the `execute$`-function (please see there for some caveats). `execute` executes subroutines which return a number. ๐
## ๐ธ Example ๐ธ
print execute("bar",2,3) sub bar(a,b) return a+b end sub
## ๐ซถ See also ๐ซถ
`compile`, `execute$`
---
## ๐ Name โ `exit` ๐
`exit` ? terminate your program
## โจ Synopsis โจ
exit exit 1
## ๐ Description ๐
Terminate your program and return any given value to the operating system. `exit` is similar to `end`, but it will terminate your program **immediately**, no matter what. ๐ฅ
## ๐ธ Example ๐ธ
print "Do you want to continue ?" input "Please answer y(es) or n(o): " a$ if (lower$(left$(a$,1))="n") exit 1
## ๐ซถ See also ๐ซถ
`end`
---
## ๐ Name โ `exp()` ๐
`exp()` ? compute the exponential function of its single argument
## โจ Synopsis โจ
foo=exp(bar)
## ๐ Description ๐
This function computes `e` to the power of its argument, where `e` is the well known euler constant `2.71828182864`. โจ
The `exp`-function is the inverse of the `log`-function. ๐ฆ
## ๐ธ Example ๐ธ
open window 100,100 for x=0 to 100 dot x,100-100*exp(x/100)/euler next x
This program plots part of the `exp`-function, however the range is rather small, so that you may not recognize the function from this plot. ๐ญ
## ๐ซถ See also ๐ซถ
`log`
---
## ๐ Name โ `export` ๐
`export` ? mark a function as globally visible
## โจ Synopsis โจ
export sub foo(bar) ? end sub
## ๐ Description ๐
okay so this one's all about making your function visible to the whole world, bestie โ here's the tea ๐
okay so the `export`-statement is <pink>literally</pink> a library-only flex ๐
โ you use it inside libraries to mark a user-defined subroutine as visible outside the library wherein it is defined. Subroutines that are **not** exported have to be qualified with the name of the library, like `foo.baz` (where `foo` is the name of the library and `baz` is the name of the subroutine). Exported subroutines though? They can be used without specifying the name of the library at all, e.g. `bar`. no cap.
So basically <yellow>`export` may only be useful within libraries</yellow>. That's its whole thing. ๐
### โจ Example โจ
The library `foo.bar` (which is listed below) defines two functions `bar` and `baz`, however only the function `bar` is exported and therefore visible even outside the library; `baz` is not exported and may only be used within the library `foo.yab`:
export sub bar() print "Hello" end sub
sub baz() print "World" end sub
Now within your main program `cux.yab` (which imports the library `foo.yab`); note that this program produces an error:
import foo
print "Calling subroutine foo.bar (okay) ..." foo.bar() print "done."
print "Calling subroutine bar (okay) ..." bar() print "done."
print "Calling subroutine foo.baz (okay) ..." foo.baz() print "done."
print "Calling subroutine baz (NOT okay) ..." baz() print "done."
The output when executing `yabasic foo.yab` is this:
Calling subroutine foo.bar (okay) ... Hello done. Calling subroutine bar (okay) ... Hello done. Calling subroutine foo.baz (okay) ... World done. Calling subroutine baz (NOT okay) ... ---Error in main.yab, line 16: can't find subroutine 'baz' ---Dump: sub baz() called in main.yab,16 ---Error: Program stopped due to an error
As the error message above shows, the subroutine `baz` must be qualified with the name of the library, if used outside the library wherein it is defined (e.g. `foo.baz`. I.e. outside the library `foo.yab` you need to write `foo.baz`. `baz` alone would be an error. <red>rip bestie</red> ๐ญ
The subroutine `bar` (without adding the name of the library) however may (and probably should) be used in any program which imports the library `foo.yab`. she's the main character of that file fr ๐ซถ
### ๐ Note ๐
In some sense the set of exported subroutines constitutes the interface of a library.
### ๐ See also ๐
`sub`, `import`
---
# ๐ฅ F ๐ฅ
- <hotpink>`false`</hotpink> ? a constant with the value of 0
- <hotpink>`fi`</hotpink> ? another name for `endif`
- <hotpink>`fill`</hotpink> ? draw a filled circles, rectangles or triangles
- <hotpink>`floor()`</hotpink> ? compute the floor for its (float) argument.
- <hotpink>`for`</hotpink> ? starts a for-loop
- <hotpink>`frac()`</hotpink> ? return the fractional part of its numeric argument
---
## ๐ Name
<pink>`false`</pink> ? a constant with the value of 0
## ๐ Synopsis
okay=false
## ๐ Description ๐
The constant `false` can be assigned to variables which later appear in conditions (e.g. within an if-statement.
`false` may also be written as `FALSE` or even `FaLsE`. <rainbow>case-insensitive queen</rainbow> ๐
## โจ Example โจ
input "Please enter a number between 1 and 10: " a if (check_input(a)) print "Okay"
sub check_input(x) if (x>10 or x<1) return false return true end sub
The subroutine `check_input` checks its argument and returns `true` or `false` according to the outcome of the check.. ๐
## ๐ See also ๐
`true`
---
## ๐ Name
<pink>`fi`</pink> ? another name for `endif`
## ๐ Synopsis
if (?) ? fi
## ๐ Description ๐
`fi` marks the end of an if-statement and is exactly equivalent to `endif`, please see there for further information. same energy, different spelling, slay ๐
## โจ Example โจ
input "A number please: " a if (a<10) then print "Your number is less than 10." fi
## ๐ See also ๐
`endif`
---
## ๐ Name
<pink>`fill`</pink> ? draw a filled circles, rectangles or triangles
## ๐ Synopsis
fill rectangle 10,10,90,90 fill circle 50,50,20 fill triangle 10,20,20,10,20,20
## ๐ Description ๐
The keyword `fill` may be used within the `circle`, `rectangle` or `triangle` command and causes these shapes to be filled. <mint>filled shapes >>> outlines</mint> ๐
`fill` can be used in conjunction with and wherever the `clear`-clause may appear. Used alone, `fill` will fill the interior of the shape (`circle`, `rectangle` or `triangle`); together with `clear` the whole shape (including its interior) is erased. <purple>two completely different vibes ngl</purple>
## โจ Example โจ
open window 200,200 fill circle 100,100,50 clear fill rectangle 10,10,90,90
This opens a window and draws a pacman-like figure. iconic honestly ๐ก๐ฎ
## ๐ See also ๐
`clear`, `circle`, `rectangle`, `triangle`
---
## ๐ Name
<pink>`floor()`</pink> ? compute the floor for its (float) argument.
## ๐ Synopsis
print floor(x)
## ๐ Description ๐
The `floor`-function returns the largest integer number that is smaller or equal than its argument. For positive numbers `x`, `floor(x)` is the same as `int(x)`; for negative numbers it can be different (see the example below). lowkey a glow-up on `int` for the negatives ๐
## โจ Example โจ
print int(-1.5),floor(-1.5) print int(-1),floor(-1) print int(1.5),floor(1.5)
This example compares the functions `int` and `floor`, starting with `-1 -2`, then `-1 -1` and ending with `1 1`, which shows the different behaviour of both functions. <cyan>bestie they are NOT the same function</cyan> ๐ญ
## ๐ See also ๐
`ceil`, `int`, `frac`
---
## ๐ Name
<pink>`for`</pink> ? starts a for-loop
## ๐ Synopsis
for a=1 to 100 step 2 ? next a
## ๐ Description ๐
The for-loop lets its numerical variable (`a` in the synopsis) assume all values within the given range. The optional `step`-clause may specify a value (**default: `1`**) by which the variable will be incremented (or decremented, if `step` is negative). <yellow>negative step = going backwards, she contains multitudes</yellow> โจ
Any for-statement can be replaced by a set of `if`s and `goto`s; as you may infer from the example below this is normally not feasible. However if you want to know in detail how the for-statement works, you should study this example, which presents a for-statement and an exactly equivalent series of `if`s and `goto`s. <purple>nerd mode activated, and honestly? obsessed</purple> ๐ง
## โจ Example โจ
for a=1 to 10 step 2:print a:next
a=1 label check if (a>10) goto done print a a=a+2 goto check label done
This example simply prints the numbers `1`, `3`, `5`, `7` and `9`. It does this twice: First with a simple for-statement and then with `if`s and `goto`s. <mint>same result, two paths, both ate</mint> ๐ฅ
## ๐ See also ๐
`step`, `next`
---
## ๐ Name
<pink>`frac()`</pink> ? return the fractional part of its numeric argument
## ๐ Synopsis
x=frac(y)
## ๐ Description ๐
The `frac`-function takes its argument, removes all the digits to the left of the comma and just returns the digits right of the comma, i.e. the fractional part. <lavender>she said "keep the decimals, drop the rest"</lavender> ๐
Refer to the example to learn how to rewrite `frac` by employing the `int`-function (which is not suggested anyway). <yellow>don't do it, but here's how you'd do it</yellow> ๐
## โจ Example โจ
for a=1 to 10 print frac(sqr(a)) print sqr(a)-int(sqr(a)) next a
The example prints the fractional part of the square root of the numbers between `1` and `10`. Each result is computed (and printed) twice: Once by employing the `frac`-function and once by employing the `int`-function. <cyan>double the work, double the validation</cyan> ๐ซถ
## ๐ See also ๐
`int`, `floor`, `ceil`
---
# ๐ G ๐
- <hotpink>`getbit$()`</hotpink> ? return a string representing the bit pattern of a rectangle within the graphic window
- <hotpink>`getscreen$()`</hotpink> ? returns a string representing a rectangular section of the text terminal
- <hotpink>`glob()`</hotpink> ? check if a string matches a simple pattern
- <hotpink>`gosub`</hotpink> ? continue execution at another point within your program (and return later)
- <hotpink>`goto`</hotpink> ? continue execution at another point within your program (and never come back)
---
## ๐ Name
<pink>`getbit$()`</pink> ? return a string representing the bit pattern of a rectangle within the graphic window
## ๐ Synopsis
a$=getbit$(10,10,20,20) a$=getbit$(10,10 to 20,20)
## ๐ Description ๐
The function `getbit` returns a string, which contains the encoded bit-pattern of a rectangle within graphic window; the four arguments specify two opposite corners of the rectangle. The string returned might later be fed to the `putbit`-command. <purple>screenshot but make it a string</purple> ๐ธ
The `getbit$`-function might be used for simple animations (as in the example below). <yellow>animation bestie era incoming</yellow> ๐ฆ
## โจ Example โจ
open window 40,40 fill circle 20,20,18 circle$=getbit$(0,0,40,40) close window
open window 200,200 for x=1 to 200 putbit circle$,x,80 next x
This example features a circle moving from left to right over the window. <rainbow>she's literally traveling, main character energy</rainbow> โญ
## ๐ See also ๐
`putbit`
## โจ NAME โจ
<hotpink>`getscreen$()`</hotpink> โ it hands you back a string that's basically a lil rectangular slice of your text terminal ๐
## โจ SYNOPSIS โจ
a$=getscreen$(2,2,20,20)
## โจ DESCRIPTION โจ
okay so the `getscreen$` function gives you a string that represents the area of the screen you picked, using its four arguments (those four args are two opposite corners, bestie ๐). Like, everything you've printed inside that rectangle gets encoded into the returned string โ and yes, <purple>including any colour-information</purple>. no colour left behind ๐
Just like most of the other commands that deal with advanced text output, `getscreen$` <yellow>requires that you have called `clear screen` before</yellow>. no clear screen, no vibe check. periodt.
## โจ EXAMPLE โจ
clear screen for a=1 to 1000: print color("red") "1"; print color("green") "2"; print color("blue") "3"; next a screen$=getscreen$(10,10,40,10) print at(10,10) " Please Press 'y' or 'n' ! " a$=inkey$ putscreen screen$,10,10
So this lil program fills the whole screen with colored digits, then asks the user for a choice ( `Please press 'y' or 'n' !` ). After that, the area of the screen that got overwritten by the question gets <mint>restored</mint> with its previous contents โ the ones that were saved earlier via `getscreen$`. the glow-up is real โจ
## โจ SEE ALSO โจ
`putscreen$`
---
## โจ NAME โจ
<hotpink>`glob()`</hotpink> โ check if a string matches a simple pattern ๐ฆ
## โจ SYNOPSIS โจ
if (glob(string$,pattern$)) ?
## โจ DESCRIPTION โจ
The `glob`-function takes two arguments โ a string and a (glob-) pattern โ and checks if the string matches the pattern. But lowkey, `glob` does <red>not</red> use the powerful rules of regular expressions. nope. it only has <purple>two special characters</purple>:
- `*` โ matches any number (even zero) of characters
- `?` โ matches exactly a single character
that's it, that's the whole alphabet of chaos ๐
## โจ EXAMPLE โจ
for a=1 to 10 read string$,pattern$ if (glob(string$,pattern$)) then print string$," matches ",pattern$ else print string$," does not match ",pattern$ endif next a
data "abc","a*" data "abc","a?" data "abc","a??" data "abc","b" data "abc","" data "abc","???" data "abc","?" data "abc","c" data "abc","A*" data "abc","????"
This program checks the string `abc` against various patterns and prints the result. The output is:
abc matches a* abc does not match a? abc matches a?? abc matches b abc matches * abc matches ??? abc does not match ? abc matches c abc does not match A abc does not match ????
look at her go ๐ญ `A*` said absolutely not, case-sensitivity said i am the main character.
## โจ SEE ALSO โจ
There are no related commands.
> bestie there is literally nothing else. no friends, no cousins, no mutuals. she's an only child ๐
---
## โจ NAME โจ
<hotpink>`gosub`</hotpink> โ continue execution at another point within your program (and return later) ๐
## โจ SYNOPSIS โจ
gosub foo
?
label foo ? return
## โจ DESCRIPTION โจ
`gosub` remembers where you are in your program right now, then yeets the flow of execution over to another point (which is normally marked with a `label`). Later, when a `return`-statement shows up, execution resumes right back at the previous location. it's giving โจboomerangโจ
`gosub` is the traditional command for calling code that needs to run from various places within your program. <yellow>However</yellow>, with subroutines yabasic offers a much more flexible way to achieve this (and more). So `gosub` <red>must be considered obsolete</red>. she's retired, she's living her soft life now, no cap.
## โจ EXAMPLE โจ
print "Do you want to exit ? " gosub ask if (r$="y") exit
label ask input "Please answer yes or no, by typing 'y' or 'n': ",r$ return
## โจ SEE ALSO โจ
`return`, `goto`, `sub`, `label`, `on gosub`
---
## โจ NAME โจ
<hotpink>`goto`</hotpink> โ continue execution at another point within your program (and never come back) ๐
## โจ SYNOPSIS โจ
goto foo
?
label foo
## โจ DESCRIPTION โจ
The `goto`-statement passes the flow of execution to another point within your program (which is normally marked with a `label`).
`goto` is normally considered <red>obsolete and harmful</red> โ iconic reputation honestly โ however in yabasic it may be put to the good use of <mint>leaving loops (e.g. `while` or `for`) prematurely</mint>. <yellow>Note however, that subroutines may not be left with the `goto`-statement.</yellow> so do not try it, bestie, she will not let you out the door ๐ช
## โจ EXAMPLE โจ
print "Please press any key to continue." print "(program will continue by itself within 10 seconds)" for a=1 to 10 if (inkey$(1)<>"") then goto done next a label done print "Hello World !"
Here the `goto`-statement is used to leave the `for`-loop prematurely. exit strategy? slay. ๐
## โจ SEE ALSO โจ
`gosub`, `on goto`
---
## H
<hotpink>`hex$()`</hotpink> โ convert a number into hexadecimal ๐ขโจ
## โจ NAME โจ
<hotpink>`hex$()`</hotpink> โ convert a number into hexadecimal ๐ขโจ
## โจ SYNOPSIS โจ
print hex$(foo)
## โจ DESCRIPTION โจ
The `hex$`-function converts a number into a string with its hexadecimal representation. `hex$` is the <purple>inverse</purple> of the `dec`-function. they're the mirror image besties ๐ช
## โจ EXAMPLE โจ
open 1,"foo" while(!eof(1)) print right$("0"+hex$(peek(1)),2)," "; i=i+1 if (mod(i,10)=0) print end while print
This program reads the file `foo` and prints its output as a hex-dump using the `hex`-function. very hacker-girl of her ๐
## โจ SEE ALSO โจ
`decbin`
---
## I
<hotpink>`if`</hotpink> โ evaluate a condition and execute statements or not, depending on the result ๐ง
<hotpink>`import`</hotpink> โ import a library ๐
<hotpink>`inkey$`</hotpink> โ wait, until a key is pressed โจ๏ธ
<hotpink>`input`</hotpink> โ read input from the user (or from a file) and assign it to a variable ๐ฅ
<hotpink>`instr()`</hotpink> โ searches its second argument within the first; returns its position if found ๐
<hotpink>`int()`</hotpink> โ return the integer part of its single numeric argument ๐ข
## โจ NAME โจ
<hotpink>`if`</hotpink> โ evaluate a condition and execute statements or not, depending on the result ๐ง
## โจ SYNOPSIS โจ
if (?) then ? endif
if (?) ?
if (?) then ? else ? endif
if (?) then ? elsif (?) ? elsif (?) then ? else ? endif
## โจ DESCRIPTION โจ
The `if`-statement is used to evaluate a condition and take actions accordingly. (<italic>as an aside, please note that there is no real difference between conditions and expressions</italic> โ yes they're the same thing wearing different outfits ๐)
There are <purple>two major forms</purple> of the `if`-statement:
- The <mint>one-line-form</mint> without the keyword `then`:
if (?) ?
This form evaluates the condition and if the result is true, executes all commands (separated by colons) up to the end of the line. There is <red>neither an `endif` keyword nor an `else`-branch</red>. one line and done, she's efficient like that ๐
- The <mint>multi-line-form</mint> with the keyword `then`:
if (?) then ? elsif (?) ? else ? endif
(where `elsif` and `else` are optional, whereas `endif` is <red>not</red>. `endif` is mandatory, bestie, do not ghost her.)
According to the requirements of your program, you may specify:
- `elsif(?)`, which specifies a condition that will be evaluated <purple>only if</purple> the condition(s) within `if` or any preceding `elsif` did not match.
- `else`, which introduces a sequence of commands that will be executed if none of the conditions above did match.
- `endif` is <red>required</red> and ends the `if`-statement.
## โจ EXAMPLE โจ
input "Please enter a number between 1 and 4: " a if (a<=1 or a>=4) error "Wrong, wrong !" if (a=1) then print "one" elsif (a=2) print "two" elsif (a=3) print "three" else print "four" endif
The input-number between 1 and 4 is simply echoed as text (`one`, `two`, ?). The example demonstrates <purple>both forms</purple> (short and long) of the `if`-statement. (<italic>Note however, that the same thing can be done, probably somewhat more elegant, with the `switch`-statement.</italic>) so yeah, switch ate a lil bit ๐
## โจ SEE ALSO โจ
`else`, `elsif`, `endif`, conditions and expressions.
---
## โจ NAME โจ
<hotpink>`import`</hotpink> โ import a library ๐โจ
## โจ SYNOPSIS โจ
import foo
## โจ DESCRIPTION โจ
The `import`-statement imports a library. It expects a <purple>single argument</purple>, which must be the name of a library (<red>without</red> the trailing `.yab` โ do not add it, bestie, she knows her own extension ๐). This library will then be read and parsed, and its subroutines (and variables) will be made available within the importing program. Most of the time this will be the main program, but libraries may also import and use other libraries. it's a whole friend group of libraries ๐ซถ
Libraries will first be searched in <mint>three locations</mint> in order:
- The current directory, i.e. the directory from which you have invoked `yabasic`
- <purple>The directory where your **main program** lives.</purple> This can be a totally different directory from the first one, if you specify a path for your main program, like `yabasic foo/bar.yab`. Bestie, it follows *your* program, not the cwd ๐
- <purple>And finally</purple>, libraries get searched inside one special directory, and where that directory sits depends on your system or on the options you used when you invoked yabasic. Typical values would be `/usr/lib` on Unix or `C:\yabasic\lib` on Windows. Run `yabasic --help` and it'll show you the correct directory, no cap. You can move that directory around with the `--librarypath` option (peep the options section for that one).
## ๐ธ Example ๐ธ
Okay so picture this: you've got a yabasic program called `foo.yab`, and it imports a library called `lib.yab`. `foo.yab` would read like this:
import lib
rem This works lib.x(0)
rem This works too x(1)
rem And this lib.y(2)
rem But this not ! y(3)
And now the library `lib.yab` reads like this:
rem Make the subroutine x easily available outside this library export sub x(a) print a return end sub
rem sub y must be referenced by its full name rem outside this library sub y(a) print a return end sub
And this program throws an error:
0 1 2 ---Error in foo.yab, line 13: can't find subroutine 'y' ---Dump: sub y() called in foo.yab,13 ---Error: Program stopped due to an error
So like, as you can see from that error message, yabasic straight up can't find the subroutine `y` unless you spell out the library name too (so `lib.y`). Why? Because `y`, unlike `x`, is **not** exported from the library `lib.yab` (you'd use the `export` statement for that). It's giving unexported, honestly ๐ญ
## โจ See also โจ
`export`, `sub`
---
## ๐ Name ๐
`inkey$` โ wait, until a key is pressed
## ๐ซ Synopsis ๐ซ
clear screen foo$=inkey$ inkey$ foo$=inkey$(bar) inkey$(bar)
## ๐ Description ๐
The `inkey$`-function waits until the user presses a key on the keyboard or a button on their mouse, and returns that very key. An optional argument specifies the number of seconds to wait; if you leave it out, `inkey$` will wait indefinitely. Iconic patience behavior ๐ซถ
> Heads up: `inkey$` may **only** be used if `clear screen` has been called at least once. No `clear screen`, no `inkey$`. Periodt.
For normal keys, yabasic just returns the key, e.g. `a`, `1` or `!`. For function keys you'll get `f1`, `f2` and so on. Other special keys return these strings respectively: `enter`, `backspace`, `del`, `esc`, `scrnup` (for screen up), `scrndown` and `tab`. Modifier keys (like `ctrl`, `alt` or `shift`) on their own can't be detected โ so if you press `shift` and `'a'` at the same time, `inkey$` will of course return the letter `'A'` instead of `'a'`.
If a graphical window has been opened (via `open window`), any mouseclick inside that window will get returned by `inkey$` too. The string returned (e.g. `MB1d+0:0028,0061`, `MB2u+0:0028,0061` or `MB1d+1:0028,0061`) is constructed like this:
- Every string associated with a mouseclick starts with the fixed string `MB`
- The next digit (`1`, `2` or `3`) tells you which mousebutton was pressed.
- A single letter, `d` or `u`, says whether the mousebutton was pressed or released: `d` stands for down, i.e. the mousebutton has been pressed; `u` means up, i.e. the mousebutton has been released.
- The plus-sign (`'+'`) that follows is always fixed.
- The next digit (in the range `0` to `7`) encodes the modifier keys pressed, where `1` stands for shift, `2` stands for alt and `4` stands for ctrl.
- The next four digits (e.g. `0028`) contain the x-position where the mousebutton has been pressed.
- The comma after that is always fixed.
- The last four digits (e.g. `0061`) contain the y-position where the mousebutton has been pressed.
All those fields are fixed length, so you can totally use functions like `mid$` to pull certain fields out. But ngl, note that there are specialized functions โ `mousex`, `mousey`, `mouseb` and `mousemod` โ that return detailed info about the mouseclick. And finally, note that `inkey$` will only register mouseclicks *within the graphic-window*; mouseclicks in the text-window cannot be detected. Sorry bestie ๐
`inkey$` accepts an optional argument specifying a timeout in seconds; if no key has been pressed within that span of time, an empty string is returned. If the timeout-argument is omitted, `inkey$` will wait for ever.
## ๐ Example ๐
clear screen open window 100,100 print "Press any key or press 'q' to stop." repeat a$=inkey$ print a$ until(a$="q")
This program simply returns the key pressed. You can use it to learn which strings are returned for the special keys on your keyboard (e.g. function-keys). Lowkey the best little key-spotting toy ๐ฆ
## โจ See also โจ
`clear screen`, `mousex`, `mousey`, `mouseb`, `mousemod`
---
## ๐ Name ๐
`input` โ read input from the user (or from a file) and assign it to a variable
## ๐ซ Synopsis ๐ซ
input a input a,b,c input a$ input "Hello" a input #1 a$
## ๐ Description ๐
`input` reads the new contents of one or many (numeric- or string-) variables, either from the keyboard (i.e. from you, hi ๐) or from a file. An optional first string-argument specifies a prompt, which will be issued before reading any contents.
If you want to read from an open file, you need to specify a hash (`'#'`), followed by the number under which the file has been opened.
> Note, that the input is split at spaces. So if you enter a whole line consisting of many space-separated words, the first `input`-statement will only return the first word; the other words will only be returned on subsequent calls to `input`. Same deal if a single `input` reads multiple variables: the first variable gets only the first word, the second one the second word, and so on. If you don't like this behaviour, you may use `line input`, which returns a whole line (including embedded spaces) at once. The way that spaces just vibe-check your variables ๐ญ
## ๐ธ Example ๐ธ
input "Please enter the name of a file to read: " a$ open 1,a$ while(!eof(1)) input #1 b$ print b$ wend
If this program is stored within a file `test.yab` and you enter this name when prompted for a file to read, you will see this output:
Please enter the name of a file to read: t.yab input "Please enter the name of a file to read: " a$ open 1,a$ while(!eof(1)) input #1 b$ print b$ wend
## โจ See also โจ
`line input`
---
## ๐ Name ๐
`instr()` โ searches its second argument within the first; returns its position if found
## ๐ซ Synopsis ๐ซ
print instr(a$,b$) if (instr(a$,b$)) ? pos=instr(a$,b$,x)
## ๐ Description ๐
The `instr`-function requires two string arguments and searches the second argument within the first. If the second argument can be found within the first, the position is returned (counting from one). If it can not be found, the `instr`-function returns `0`; this makes this function usable within the condition of an `if`-statement (see the example below). Sneaky little `0`, slaying as a falsey ๐
If you supply a third, numeric argument to the `instr`-function, it will be used as a starting point for the search. Therefore `instr("abcdeabcdeabcde","e",8)` will return `10`, because the search for an `"e"` starts at position `8` and finds the `"e"` at position `10` (and not the one at position `5`). Skipping the first one like it's not even there โจ
## ๐ Example ๐
input "Please enter a text containing the string 'cat': " a$ if (instr(a$,"cat")) then print "Well done !" else print "No cat in your input ..." endif
## โจ See also โจ
`rinstr`
---
## ๐ Name ๐
`int()` โ return the integer part of its single numeric argument
## ๐ซ Synopsis ๐ซ
print int(a)
## ๐ Description ๐
The `int`-function returns only the digits before the comma; `int(2.5)` returns `2` and `int(-2.3)` returns `-2`. It just chops the decimal part right off, no negotiating ๐
## ๐ธ Example ๐ธ
input "Please enter a whole number between 1 and 10: " a if (a=int(a) and a>=1 and a<=10) then print "Thanx !" else print "Never mind ..." endif
## โจ See also โจ
`frac`, `floor`, `ceil`
<lavender>L</lavender>
- **`label`** โ mark a specific location within your program for `goto`, `gosub` or `restore`
- **`left$()`** โ return (or change) left end of a string
- **`len()`** โ return the length of a string
- **`line`** โ draw a line
- **`line input`** โ read in a whole line of text and assign it to a variable
- **`local`** โ mark a variable as local to a subroutine
- **`log()`** โ compute the natural logarithm
- **`loop`** โ marks the end of an infinite loop
- **`lower$()`** โ convert a string to lower case
- **`ltrim$()`** โ trim spaces at the left end of a string
---
## ๐ท๏ธ Name
**`label`** โ mark a specific location within your program for `goto`, `gosub` or `restore`
### ๐ Synopsis
label foo
goto foo
### ๐ฌ Description
okay so the `label`-command is literally just giving a name to a specific spot inside your program. that's it, that's the whole job ๐
and then three different commands can come find that spot: `goto`, `gosub` and `restore`.
here's the cute part: you can use labels **safely inside libraries**, because a label like `foo` does *not* collide with another label named `foo` in your main program or in some other library. yabasic will not mix them up, periodt. no cap.
and as an aside bestie, heads up: line numbers are a special โ but **deprecated** ๐ โ case of labels. peep the second example below.
### โจ Example
for a=1 to 100 if (ran(10)>5) goto done next a label done
10 for a=1 to 100 20 if (ran(10)>5) goto 40 30 next a 40
in this example the for-loop will *probably* get left early via a `goto`-statement. and it's done twice, because why not: first with labels, then again with line numbers. two ways, same vibe. ๐ฆ
### ๐ See also
`gosub`, `goto`.
---
## ๐ท๏ธ Name
**`left$()`** โ return (or change) left end of a string
### ๐ Synopsis
print left$(a$,2) left$(b$,3)="foobar"
### ๐ฌ Description
the `left$`-function takes two arguments โ a string and a number โ and hands you back the part from the left end of the string, with the length you specified as the second argument. loosely speaking, it just returns however many chars you asked for from the left side of the string you gave it. simple, iconic, no notes. โจ
but wait, there's more: `left$`-function can be **assigned to**, meaning it's allowed to show up on the left hand side of an assignment. so yes, you can change part of the variable you passed into the `left$`-function. โ ๏ธ just know that the length of the string **cannot** be changed that way โ characters might get overwritten, but nothing gets added. example's down below if you wanna see it in the wild.
### โจ Example
input "Please answer yes or no: " a$ l=len(a$):a$=lower$(a$):print "Your answer is "; if (left$("yes",l)=a$ and l>=1) then print "yes" elsif (left$("no",l)=a$ and l>=1) then print "no" else print "?" endif
this one asks a lil yes/no question and goes out of its way to accept even *incomplete* input, while still being able to reject the invalid stuff. ๐
and this second example shows off the whole "you can assign to the `left$`-function" thing:
a$="Heiho World !" print a$ left$(a$,5)="Hello" print a$
### ๐ See also
`right$`, `mid$`
---
## ๐ท๏ธ Name
**`len()`** โ return the length of a string
### ๐ Synopsis
x=len(a$)
### ๐ฌ Description
the `len`-function returns the length of its single string argument. one argument in, one number out, we love a low-maintenance icon. ๐ธ
### โจ Example
input "Please enter a password: " a$ if (len(a$)<6) error "Password too short !"
this example checks the length of the password the user typed in. security queen behavior. ๐
### ๐ See also
`left$`, `right$` and `mid$`,
---
## ๐ท๏ธ Name
**`line`** โ draw a line
### ๐ Synopsis
open window 100,100 line 0,0,100,100 line 0,0 to 100,100 new curve line 100,100 line to 100,100
open window 100,100 clear line 0,0,100,100 clear line 0,0 to 100,100 new curve clear line 100,100 clear line to 100,100
### ๐ฌ Description
the `line`-command draws a line. sounds simple, right? wrong, bestie โ this thing has a whole *variety* of forms, all listed up in the synopsis. let's get into them one by one: ๐
- a line has a starting point and an end point, so the `line`-command (normally) needs **four numbers** as arguments, representing those two points. that's the first form in the synopsis.
- you can separate the two points with either `,` or `to`, which is where the second form of the `line`-command comes from.
- the `line`-command can draw a connected sequence of lines, using a sequence of commands like `line x,y`. each command draws a line from the point where the last `line`-command left off, to the point given in the arguments. โ ๏ธ but note: you **need** to use the command `new curve` before you can issue a `line`-command like that. example's below.
- you may insert the word `to` for beauty: `line to x,y`, which does *exactly* the same thing as `line x,y`. purely aesthetic, and honestly? respect. ๐
- finally, you can choose not to draw but to **erase** the lines, by prepending the phrase `clear`. that accounts for all the other forms of the `line`-command.
### โจ Example
open window 200,200 line 10,10 to 10,190 line 10,190 to 190,190 new curve for a=0 to 360 line to 10+a*180/360,100+60*sin(a*pi/180) next a
this draws a sine-curve (with an offset in x- and y-direction). โ ๏ธ note that the first `line`-command after `new curve` **does not draw anything** โ only the coordinates get stored. then the second iteration of the loop uses those coordinates as the starting point for the first line. sneaky but iconic. ๐
### ๐ See also
`new curve`, `close curve`, `open window`
---
## ๐ท๏ธ Name
**`line input`** โ read in a whole line of text and assign it to a variable
### ๐ Synopsis
line input a line input a$ line input "Hello" a line input #1 a$
### ๐ฌ Description
in most respects `line input` is just like the `input`-command: it reads the new contents of a variable, either from the keyboard or from a file. **however**, `line input` always reads a *complete line* and assigns it to its variable. it does **not** stop reading at spaces, which makes it the absolute best way to read in a string that might contain whitespace. ๐ซถ and note that the final newline gets stripped off.
### โจ Example
line input "Please enter your name (e.g. Frodo Beutelin): " a$ print "Hello ",a$
โ ๏ธ and note that using `line input` is **essential** here โ a plain `input`-statement would only give you the string up to the first space, like `Frodo`. and we're not doing Frodo dirty like that. ๐ญ
### ๐ See also
`input`
---
## ๐ท๏ธ Name
**`local`** โ mark a variable as local to a subroutine
### ๐ Synopsis
sub foo()
local a,b,c$,d(10),e$(5,5)
?
end sub
### ๐ฌ Description
the `local`-command can โ and honestly **should** โ be used to mark a variable (or array) as local to the subroutine it's sitting inside. what that means: a local variable in your subroutine is *totally different* from a variable with the same name in your main program. variables that are known everywhere in your program are called **global**, in contrast. ๐
declaring variables inside the subroutine as local helps you dodge those hard-to-find bugs, so local variables should be used whenever possible. fr fr, do it. ๐
and note: the parameters of your subroutines are **always** local.
as you can see in the example, local arrays can be created without using the keyword `dim` (which is only required for global arrays). slay.
### โจ Example
a=1 b=1 print a,b foo() print a,b
sub foo() local a a=2 b=2 end sub
this example shows the difference between local and global variables, and it produces this output:
1 1 1 2
as you can see, the content of the global variable `a` is unchanged after the subroutine `foo` โ because the assignment `a=2` inside the subroutine only affects the **local** `a`, not the global one. but the variable `b` is never declared local, so the subroutine *does* change the global variable, which you can see reflected in the second `print`-statement's output. โจ
### ๐ See also
`sub`, `static`, `dim`
---
## ๐ท๏ธ Name
**`log()`** โ compute the natural logarithm
### ๐ Synopsis
a=log(x) a=log(x,base)
### ๐ฌ Description
the `log`-function computes the logarithm of its first argument. the optional second argument gives the base for the logarithm โ and if you skip that second argument, the euler-constant `2.71828โฆ` gets taken as the base. ๐งฎ
### โจ Example
open window 200,200 for x=10 to 190 step 10:for y=10 to 190 step 10 r=3*log(1+x,1+y) if (r>10) r=10 if (r<1) r=1 fill circle x,y,r next y:next x
okay this one draws <pink>another nice plot</pink> and honestly it's giving abstract art installation. run it, screenshot it, post it. ๐จโจ
## See also
`exp`
---
## Name
`loop` ? marks the end of an infinite loop
## Synopsis
do ? loop
## Description
the `loop`-command marks the <hotpink>end</hotpink> of a loop โ and that loop got started by `do`. everything you shove in between those two gets repeated <rainbow>forever and ever and ever</rainbow>. ๐ so yeah, a `do` โฆ `loop` loop is infinite, that's the whole bit. BUT (and this is the important part, bestie) you can dip out whenever you want using `break` or `goto`. you are never actually trapped. ๐ซถ
## Example
print "Hello, I will throw dice, until I get a 2 ..." do r=int(ran(6))+1 print r if (r=2) break loop
## See also
`do`, `for`, `repeat`, `while`, `break`
---
## Name
`lower$()` ? convert a string to lower case
## Synopsis
l$=lower$(a$)
## Description
the `lower$`-function takes <yellow>one</yellow> string-argument and hands it back to you all in lower case. that's it. that's the whole function. iconic, no notes. ๐
## Example
input "Please enter a password: " a$ if (a$=lower$(a$)) error "Your password is NOT mixed case !"
this little guy prompts you for a password and then checks whether it's <purple>actually</> lower case. if it is, it yells at you. rude but correct. ๐ญ
## See also
`upper$`
---
## Name
`ltrim$()` ? trim spaces at the left end of a string
## Synopsis
a$=ltrim$(b$)
## Description
the `ltrim$`-function strips <mint>all</mint> the whitespace off the left end of a string and returns the result. the right side stays exactly where it was, don't worry. ๐ง
## Example
input "Please answer 'yes' or 'no' : " a$ a$=lower$(ltrim$(rtrim$(a$))) if (len(a$)>0 and a$=left$("yes",len(a$))) then print "Yes ..." else print "No ..." endif
this one prompts for an answer and cleans off any spaces that might be sitting in front of the input. so it's ready for the (admittedly kind of pathological) case where someone hits space before they even type their answer. we've all done it. ๐
## See also
`rtrim$`, `trim$`
---
# ๐ธ M ๐ธ
- `max()` ? return the larger of its two arguments
- `mid$()` ? return (or change) characters from within a string
- `min()` ? return the smaller of its two arguments
- `mod` ? compute the remainder of a division
- `mouseb` ? extract the state of the mousebuttons from a string returned by `inkey$`
- `mousemod` ? return the state of the modifier keys during a mouseclick
- `mousex` ? return the x-position of a mouseclick
- `mousey` ? return the y-position of a mouseclick
---
## Name
`max()` ? return the larger of its two arguments
## Synopsis
print max(a,b)
## Description
returns the <hotpink>maximum</hotpink> of its two arguments. whichever one is bigger, that's the one you get. simple as. ๐
## Example
dim m(10) for a=1 to 1000 m=0 For b=1 to 10 m=max(m,ran(10)) next b m(m)=m(m)+1 next a
for a=1 to 9 print a,": ",m(a) next a
inside the inner `for`-loop (the one whose loop-variable is `b`), the example computes the max of <cyan>10</cyan> random numbers. the outer loop (loop-variable `a`) then does that whole thing <purple>1000</purple> times and counts how often each maximum shows up. the last loop finally spills the results. ๐
now the genuinely juicy question would be what happens as we push the number of iterations from a thousand to <rainbow>infinity</rainbow>. and honestly? if somebody knows, just tell me :-) ๐โจ
## See also
`min`
---
## Name
`mid$()` ? return (or change) characters from within a string
## Synopsis
print mid$(a$,2,1) print mid$(a$,2) mid$(a$,5,3)="foo" mid$(a$,5)="foo"
## Description
the `mid$`-function wants <yellow>three</yellow> arguments: a string and two numbers. the first number is the <mint>position</mint> inside the string, and the second one is <mint>how many characters</mint> you want back. if you skip that second number, `mid$` just keeps going all the way to the end of the string. no biggie. ๐
> โ ๏ธ and here's the spicy bit: you can <hotpink>assign</hotpink> to `mid$`, meaning `mid$` is allowed to sit on the left-hand side of an assignment. that way you can rewrite a chunk of the variable you passed in. BUT โ and this is important โ you cannot change the <red>length</red> of the string that way. characters can be <purple>overwritten</purple>, never <purple>added</purple>. example's right below, go look. ๐
## Example
input "Please enter a string: " a$ for a=1 to len(a$) if (instr("aeiou",lower$(mid$(a$,a,1)))) mid$(a$,a,1)="e" next a print "When you turn everything to lower case and" print "replace every vowel with 'e', your input reads:" print print a$
this one messes with your input a little, using `mid$` both to <cyan>grab</cyan> a character out of the middle of the string and to <cyan>replace</cyan> it. it's giving vowel chaos. ๐
## See also
`left$` and `right$`.
---
## Name
`min()` ? return the smaller of its two arguments
## Synopsis
print min(a,b)
## Description
returns the <hotpink>minimum</hotpink> of its two arguments. the tiny one. the underdog. ๐ฅบ
## Example
dim m(10) for a=1 to 1000 m=min(ran(10),ran(10)) m(m)=m(m)+1 next a
for a=1 to 9 print a,": ",m(a) next a
every time through the loop it records the lower of two random numbers, then prints the tally at the end. that's it, that's the plot. ๐
## See also
`max`
---
## Name
`mod` ? compute the remainder of a division
## Synopsis
print mod(a,b)
## Description
the `mod`-function divides its two arguments and gives you back the <mint>remainder</mint>. and heads up: `a/b-int(a/b)` and `mod(a,b)` are <hotpink>always</hotpink> equal. always. no cap. ๐ฅ
## Example
clear screen print at(10,10) "Please wait "; p$="-|/" for a=1 to 100 rem ... do something lengthy here, or simply sleep :-) pause(1) print at(22,10) mid$(p$,1+mod(a,4)) next a
this example does something time-consuming inside a loop (spoiler: it just <yellow>sleeps</yellow> ๐ด) and keeps you posted with a little spinning bar. that spinning bar is literally where `mod` comes in. math but make it โจaestheticโจ.
## See also
`int`, `frac`
---
## Name
`mouseb` ? extract the state of the mousebuttons from a string returned by `inkey$`
## Synopsis
inkey$ print mouseb() print mouseb a$=inkey$ print mouseb(a$)
## Description
`mouseb` is a helper function for decoding part of the (genuinely kind of <purple>complicated</purple>) strings that `inkey$` hands back. if a mousebutton got pressed, `mouseb` returns the <cyan>number</cyan> of that button (`1`, `2` or `3`). if it got <mint>released</mint>, you get the negative (`-1`, `-2` or `-3`). yes bestie, negative numbers mean let go. ๐
`mouseb` takes <yellow>zero or one</yellow> arguments. if you pass one, it should be a string returned by `inkey$`. if you call `mouseb` with no arguments at all, it pulls the values from the <purple>last call to `inkey$`</purple> โ yabasic quietly stores those internally for you. ๐ซถ
### Note
> ๐จ real talk though: the value `mouseb` gives you does <red>NOT</red> reflect the <hotpink>current</hotpink> state of the mousebuttons. it's extracting info out of the string you passed in (or out of the last `inkey$` call if you passed nothing). so what you get back is the state of the mousebuttons <yellow>at the moment `inkey$` was called</yellow> โ not at the moment `mouseb` was called. those are two different moments and the difference matters. ๐ญ
## Example
open window 200,200 clear screen print "Please draw lines; press (and keep it pressed)" print "the left mousebutton for the starting point," print "release it for the end-point." do if (mouseb(release$)=1) press$=release$ release$=inkey$ if (mouseb(release$)=-1) then line mousex(press$),mousey(press$) to mousex(release$),mousey(release$) endif loop
this is maybe the most <mint>simplistic</mint> line-drawing program possible, and it catches both the press and the release of the first mousebutton. tiny program, big vibes. ๐จ
## See also
`inkey$`, `mousex`, `mousey` and `mousemod`
---
## Name
`mousemod` ? return the state of the modifier keys during a mouseclick
## Synopsis
inkey$ print mousemod() print mousemod a$=inkey$ print mousemod(a$)
## Description
<pink>okay so</pink> the `mousemod` function is your little decoding bestie ๐
for those <purple>(honestly kinda extra)</purple> strings that `inkey$` hands you when somebody clicks a mouse button. It tells you what the keyboard modifiers are doing โ shift, ctrl, or alt.
Here's the tea โ: if the shift-key is pressed, `mousemod` returns <yellow>1</yellow>. Alt-key? That's <yellow>2</yellow>. Ctrl-key? <yellow>4</yellow>. And if you're holding down more than one at the same time, it just <hotpink>adds them up</hotpink> โ so `mousemod` returns <yellow>5</yellow> if shift and ctrl are pressed simultaneously. math girlies stay winning ๐งฎโจ
`mousemod` takes <cyan>zero or one</cyan> arguments. If you pass one, it should be a string that came back from `inkey$`. And if you call `mousemod` with no arguments at all? It just reaches for the values from the <purple>last</purple> call to `inkey$` โ which yabasic stores implicitly and internally all on its own. no cap, it's already keeping receipts ๐ซถ
## ๐ Note
Please see also the Note within the `mouseb`-function.
## โจ Example
open window 200,200 clear screen do a$=inkey$ if (left$(a$,2)="MB") then x=mousex(a$) y=mousey(a$) if (mousemod(a$)=0) then circle x,y,20 else fill circle x,y,20 endif endif loop
So what does this do? It draws a circle <rainbow>whenever a mousebutton is pressed</rainbow>. The circles come out **filled** when any modifier is being held, and **empty** when it's not. vibes only ๐
## ๐ฆ See also
`inkey$`, `mousex`, `mousey` and `mouseb`
---
# ๐ธ Name ๐ธ
**`mousex`** โ return the x-position of a mouseclick
## โจ Synopsis
inkey$ print mousex() print mousex a$=inkey$ print mousex(a$)
## ๐ Description
The `mousex` function is a helper bestie for decoding part of the <purple>(rather complicated)</purple> strings that come back from the `inkey$` function. It returns the **x-position of the mouse** as encoded inside its argument. ๐ฑ๏ธ
`mousex` accepts <cyan>zero or one</cyan> arguments. A single argument should be a string returned by `inkey$`; if `mousex` is called with no arguments, it returns the values from the last call to `inkey$` โ which yabasic stores implicitly and internally, as always. she remembers everything ๐
## ๐ Note
Please see also the Note within the `mouseb`-function.
## โจ Example
open window 200,200 clear screen do a$=inkey$ if (left$(a$,2)="MB") then line mousex,0 to mousex,200 endif loop
This one draws <cyan>vertical lines</cyan> at the exact position where the mousebutton was pressed. iconic behavior honestly โจ
## ๐ฆ See also
`inkey$`, `mousemod`, `mousey` and `mouseb`
---
# ๐ธ Name ๐ธ
**`mousey`** โ return the y-position of a mouseclick
## โจ Synopsis
inkey$ print mousey() print mousey a$=inkey$ print mousey(a$)
## ๐ Description
The `mousey` function is a helper for decoding part of the <purple>(rather complicated)</purple> strings returned by the `inkey$` function. `mousey` returns the **y-position of the mouse** as encoded within its argument. ๐ฑ๏ธ
`mousey` accepts <cyan>zero or one</cyan> arguments. A single argument should be a string returned by `inkey$`; if `mousey` is called without any arguments, it returns the values from the last call to `inkey$` โ which are stored implicitly and internally by yabasic. same energy, different axis ๐
## ๐ Note
Please see also the Note within the `mouseb`-function.
## โจ Example
open window 200,200 clear screen do a$=inkey$ if (left$(a$,2)="MB") then line 0,mousey to 200,mousey endif loop
This example draws <mint>horizontal lines</mint> at the position where the mousebutton has been pressed. we love a consistent queen ๐
## ๐ฆ See also
`inkey$`, `mousemod`, `mousex` and `mouseb`
---
# ๐ค N ๐ค
okay bestie, alphabetical era, let's go ๐
- `new curve` ? start a new curve, that will be drawn with the `line`-command
- `next` ? mark the end of a `for` loop
- `not` ? negate an expression; can be written as `!`
- `numparams` ? return the number of parameters, that have been passed to a subroutine
---
# ๐ธ Name ๐ธ
**`new curve`** โ start a new curve, that will be drawn with the `line`-command
## โจ Synopsis
new curve line to x,y
## ๐ Description
The `new curve` function starts a **new sequence of lines** that get drawn by repeated `line to`-commands. it's giving glow-up pipeline โจ
## ๐ Example
open window 200,200 ellipse(100,50,30,60) ellipse(150,100,60,30) sub ellipse(x,y,xr,yr) new curve for a=0 to 2*pi step 0.2 line to x+xr*cos(a),y+yr*sin(a) next a close curve end sub
This example defines a subroutine `ellipse` that draws an ellipse. Inside that subroutine, the ellipse is drawn as a sequence of lines โ started with the `new curve` command and closed with `close curve`. chef's kiss ๐ค๐
## ๐ฆ See also
`line`, `close curve`
---
# ๐ธ Name ๐ธ
**`next`** โ mark the end of a `for` loop
## โจ Synopsis
for a=1 to 10 next a
## ๐ Description
The `next`-keyword marks the **end of a `for`-loop**. Every statement up to the `next`-keyword gets repeated as specified by the `for`-clause. And heads up: the name of the variable is <cyan>optional</cyan> โ so instead of `next a` you can literally just write `next`. lowkey a shortcut queen ๐
## ๐ Example
for a=1 to 300000 for b=1 to 21+20*sin(pi*a/20) print "*"; next b print sleep 0.1 next a
This example simply plots a sine-curve <hotpink>until you fall asleep</hotpink>. ๐ด accurate tbh
## ๐ฆ See also
`for`
---
# ๐ธ Name ๐ธ
**`not`** โ negate an expression; can be written as `!`
## โจ Synopsis
if (not a<b) then ? bad=!okay
## ๐ Description
The keyword `not` (or `!` if you're feeling brief) is mostly used inside conditions โ think `if`-statements or `while`-statements. There, it's employed to **negate the condition or expression**, i.e. flip <green>TRUE</green> into <red>FALSE</red> and vice versa. no cap ๐
But plot twist: `not` can be used inside arithmetic calculations too. simply because there is <rainbow>no difference between arithmetic and logical expressions</rainbow>. it's all the same soup bestie ๐
## ๐ Example
input "Please enter three ascending numbers: " a,b,c if (not (a<b and b<c)) error " the numbers you have entered are not ascending ..."
## ๐ฆ See also
`and`,`or`
---
# ๐ธ Name ๐ธ
**`numparams`** โ return the number of parameters, that have been passed to a subroutine
## โจ Synopsis
sub foo(a,b,c) if (numparams=1) ? ? end sub
## ๐ Description
Inside a subroutine, the local variable `numparam` or `numparams` contains the **number of parameters that have actually been passed** to that subroutine. This info is genuinely useful, because a subroutine may have been called with *fewer* parameters than it was declared with. The number of values that actually got passed while calling the subroutine can be found in `numparams`. detective work ๐โจ
And here's the important bit: arguments that are used in the definition of a subroutine but get left out during a call to it โ which lowers the value of `numparams` โ receive a value of <yellow>0</yellow> or <yellow>""</yellow> (empty string) respectively. so they're not just vibing in the void, they get defaults ๐ซถ
## ๐ Example
a$="123456789" print part$(a$,4) print part$(a$,3,7)
sub part$(a$,f,t) if (numparams=2) then return mid$(a$,f) else return mid$(a$,f,t-f+1) end if end sub
When you run this example, it will print <cyan>`456789`</cyan> and <cyan>`34567`</cyan>. Take a look at the subroutine `part$`, which returns part of the string that got passed as an argument. If (besides the string) **two** numbers are passed, they define the starting and end position of the substring that will be returned. But if only **one** number is passed, the rest of the string starting from that position gets returned instead. Each of these cases is recognized with the help of the `numparams` variable. she's flexible, she's clever, she ate ๐
## ๐ฆ See also
`sub`
---
# ๐ค O ๐ค
- `on gosub` ? jump to one of multiple gosub-targets
- `on goto` ? jump to one of many goto-targets
- `on interrupt` ? change reaction on keyboard interrupts
- `open` ? open a file
- `open printer` ? open printer for printing graphics
- `open window` ? open a graphic window
- `logical or` ? logical or, used in conditions
- `or()` ? arithmetic or, used for bit-operations
---
# ๐ธ Name ๐ธ
**`on goto`** โ jump to one of multiple gosub-targets
## โจ Synopsis
on a gosub foo,bar,baz ? label foo ? return
label bar ? return
label baz ? return
## ๐ Description
<purple>okay so</purple> the `on gosub` statement grabs its numeric argument (the lil guy sitting between `on` and `gosub`) and uses it to pick an element out of the label list that comes right after the gosub-keyword. Number is 1? โ it does a gosub to the **first** label. Number is 2? โ the **second**, and so on, you get the vibe. If the number is **zero or less**, the program just keeps going at the position of the **first** label. If the number is **bigger than the total count of labels**, execution continues at the position of the **last** label. So likeโฆ the first and last label in the list are kinda acting as a fallback-slot. ๐ซถ
> <red>real talk</red> โ `on gosub` can <red>no longer be considered state of the art</red>. People (not me!) may even start to mock you if you use it. ๐
## Example โจ
do print "Please enter a number between 1 and 3: " print input "Your choice " a on a gosub bad,one,two,three,bad loop
label bad print "No. Please between 1 and 3" return
label one print "one" return
label two print "two" return
label three print "three" return
See how invalid input (a number less than 1, or larger than 3) gets <mint>automatically detected</mint>? no extra work, she just *knows*. ๐
## See also ๐
`goto`, `on gosub/function>`
---
## Name ๐
`on goto` โ jump to one of many goto-targets, pick-your-own-adventure style
## Synopsis ๐ธ
on a goto foo,bar,baz ? label foo ? label bar ? label baz ?
## Description ๐
The `on goto` statement uses its numeric argument (the one chilling between `on` and `goto`) to select an element from the list of labels that follows the goto-keyword. Number is 1 โ execution continues at the **first** label; number is 2 โ the **second**, and so on, forever and ever. If the number is **zero or less**, the program continues at the position of the **first** label; if the number is **larger than the total count of labels**, execution continues at the position of the **last** label. i.e. the first and last label in the list constitute some kind of fallback-slot. ๐ฆ
> <red>heads up bestie</red> โ (unlike the `goto`-command) the `on goto`-command can <red>no longer be considered state of the art</red>. People may (not me!) even start to mock you if you use it. ๐
## Example โจ
label over print "Please Select one of these choices: " print print " 1 -- show time" print " 2 -- show date" print " 3 -- exit" print input "Your choice " a on a goto over,show_time,show_date,terminate,over
label show_time print time$() goto over
label show_date print date$() goto over
label terminate exit
And again โ invalid input (a number less than 1, or larger than 3) is <mint>automatically detected</mint>; when that happens the question just gets asked all over again. it's giving โจresilientโจ
## See also ๐
`goto`, `on gosub/function>`
---
## Name ๐
`on interrupt` โ change reaction on keyboard interrupts
## Synopsis ๐
on interrupt break ? on interrupt continue
## Description ๐ธ
With the `on interrupt`-command you can change the way yabasic reacts to a keyboard interrupt, and it comes in <purple>two</purple> variants: `on interrupt break` and `on interrupt continue`. A keyboard interrupt happens when you press `ctrl-C` on your keyboard. Normally (and definitely after you've called `on interrupt break`), yabasic will terminate with an error message. BUT after the command `on interrupt continue`, yabasic just **ignores** any keyboard interrupt entirely. Which is lowkey useful if you don't want your program being interruptible during certain critical operations (e.g. updating of files). ๐ซถ
## Example ๐
print "Please stand by while writing a file with random data ..." on interrupt continue open "random.data" for writing as #1 for a=1 to 100 print #1 ran(100) print a," percent done." sleep 1 next a close #1 on interrupt continue
This program writes a file with 100 random numbers. The `on interrupt continue` command insures that the program will not be terminated on a keyboard interrupt, and the file will be written entirely in any case. The `sleep`-command just stretches the process artificially to give you a chance to try a `ctrl-C`. go on, try it, she won't even flinch ๐ญ
## See also โญ
There is no related command.
---
## Name ๐
`open` โ open a file
## Synopsis ๐ฆ
open a,"file","r" open #a,"file","w" open #a,printer open "file" for reading as a open "file" for writing as #a a=open("file") a=open("file","r") if (open(a,"file")) ? if (open(a,"file","w")) ?
## Description ๐ธ
The `open`-command opens a file for reading or writing, or a printer for printing text. `open` comes in a <rainbow>wide variety of ways</rainbow>; it requires these arguments:
- **`filenumber`** โ In the synopsis this is `a` or `#a`. In yabasic each file is associated with a number between 1 and a maximum value, which depends on the operating system. For historical reasons the filenumber can be preceded by a hash (`'#'`). Note, that specifying a filenumber is **optional**; if it is omitted, the `open`-function will return a filenumber, which should then be stored in a variable for later reference. This filenumber can be a simple number or an arbitrary complex arithmetic expression, in which case braces might be necessary to save yabasic from getting confused. ๐
- **`filename`** โ In the synopsis above this is `"file"`. This string specifies the name of the file to open (note the important caveat on specifying these filenames).
- **`accessmode`** โ In the synopsis this is `"r"`, `"w"`, `for reading` or `for writing`. This string or clause specifies the mode in which the file is opened; it may be one of:
- **`"r"`** โ Open the file for reading (may also be written as `for reading`). If the file does not exist, the command will <red>fail</red>. This mode is the **default**, i.e. if no mode is specified with the `open`-command, the file will be opened with this mode.
- **`"w"`** โ Open the file for writing (may also be written as `for writing`). If the file does not exist, it will be created. โจ
- **`"a"`** โ Open the file for appending, i.e. what you write to the file will be appended after its initial contents. If the file does not exist, it will be created.
- **`"b"`** โ This letter may **not** appear alone, but may be combined with the other letters (e.g. `"rb"`) to open a file in binary mode (as opposed to text mode).
As you may see from the synopsis, the `open`-command may either be called as a command (without braces) or as a function (with braces). If called as a function, it will return the filenumber, or **zero** if the operation fails. Therefore the `open`-function may be used within the condition of an `if`-statement. ๐
If the `open`-command fails, you may use `peek("error")` to retrieve the exact nature of the error.
Furthermore note, that there is another, somewhat separate usage of the `open`-command; if you specify the bareword `printer` instead of a filename, the command opens a printer for printing text. Every text (and **only** text) you print to this file will appear on your printer. Note, that this is <hotpink>very different</hotpink> from printing graphics, as can be done with `open printer`.
## Example ๐
open "foo.bar" for writing as #1 print #1 "Hallo !" close #1 if (not open(1,"foo.bar")) error "Could not open 'foo.bar' for reading" while(not eof(1)) line input #1 a$ print a$ wend
This example simply opens the file `foo.bar`, writes a single line, reopens it and reads its contents again. round trip, slay ๐
## See also ๐
`close`, `print`, `peek`, `peek("error")` and `open printer`
---
## Name ๐
`open printer` โ open printer for printing graphics
## Synopsis โจ
open printer open printer "file"
## Description ๐ฆ
The `open printer`-command opens a printer for printing **graphics**. The command requires that a graphic window has been opened before. Everything that is drawn into this window will then be sent to the printer too. ๐
A new piece of paper may be started with the `clear window`-command; the final (or only) page will appear after the `close printer`-command.
Note, that you may specify a filename with `open printer`; in that case the printout will be sent to a filename instead of to a printer. Your program or the user will be responsible for sending this file to the printer afterwards. ๐
If you use yabasic under Unix, you will need a <purple>postscript printer</purple> (because yabasic produces postscript output). Alternatively you may use `ghostscript` to transform the postscript file into a form suitable for your printer; but that is <italic>beyond the responsibility of yabasic</italic>. ๐ซถ
## ๐ธ Example ๐ธ
open window 200,200 open printer line 0,0 to 200,200 text 100,100,"Hallo" close window close printer
<purple>This example will open a window, draw a line and print some text within; everything will appear on your printer too.</purple> ๐จ๏ธโจ
## ๐ฆ See also ๐ฆ
- `close printer`
---
# ๐ Name ๐
<hotpink>**`open window`**</hotpink> โ open a graphic window ๐ช
## โจ Synopsis โจ
open window x,y open window x,y,"font"
## ๐ Description ๐
The <cyan>`open window`</cyan>-command opens a window of the size you asked for. <yellow>Only one window can be opened at any given moment of time.</yellow> Like, one. That's it. That's the whole window budget. ๐
An optional third argument specifies a font to be used for any text within the window. It can however be changed with any subsequent `text`-command, so it's not a forever commitment or anything. ๐
## ๐ธ Example ๐ธ
for a=200 to 400 step 10 open window a,a for b=0 to a line 0,b to a,b line b,0 to b,a sleep 0.1 close window next a
## ๐ฆ See also ๐ฆ
- `close window`, `text`
---
# ๐ Name ๐
<hotpink>**`or`**</hotpink> โ logical or, used in conditions ๐
## โจ Synopsis โจ
if (a or b) ? while (a or b) ?
## ๐ Description ๐
Used in conditions (e.g within `if` or `while`) to join two expressions. Returns <green>`true`</green>, if <purple>either</purple> its left or its right or <purple>both</purple> arguments are true; returns <red>`false`</red> otherwise. So it's the chill one โ one yes is enough, bestie. ๐ซถ
## ๐ธ Example ๐ธ
input "Please enter a number" if (a>9 or a<1) print "a is not between 1 and 9"
## ๐ฆ See also ๐ฆ
- `and,not`
---
# ๐ Name ๐
<hotpink>**`or()`**</hotpink> โ arithmetic or, used for bit-operations ๐ข
## โจ Synopsis โจ
x=or(a,b)
## ๐ Description ๐
Used to compute the <cyan>bitwise or</cyan> of both its argument. Both arguments are treated as binary numbers (i.e. a series of `0` and `1`); a bit of the resulting value will then be `1`, if any of its arguments has `1` at this position in their binary representation.
> <yellow>โ ๏ธ Note, that both arguments are silently converted to integer values</yellow> and that <red>negative numbers have their own binary representation and may lead to unexpected results</red> when passed to `or`. Not me warning you twice. ๐
## ๐ธ Example ๐ธ
print or(14,3)
<purple>This will print `15`.</purple> This result is clear, if you note, that the binary representation of `14` and `3` are `1110` and `0011` respectively; this will yield `1111` in binary representation or `15` as decimal. Math ate, honestly. ๐
โจ
## ๐ฆ See also ๐ฆ
- `oand, eor and not`
---
# ๐ P ๐
- **`pause`** โ pause, sleep, wait for the specified number of seconds โณ
- **`peek`** โ retrieve various internal information ๐
- **`peek$`** โ retrieve various internal string-information ๐งต
- **`pi`** โ a constant with the value `3.14159` ๐ฅง
- **`poke`** โ change selected internals of yabasic ๐
- **`print`** โ Write to terminal or file ๐จ๏ธ
- **`print color`** โ print with color ๐
- **`print colour`** โ see `print color` ๐ฌ๐ง
- **`putbit`** โ draw a rectangle of pixels encoded within a string into the graphics window ๐จ
- **`putscreen`** โ draw a rectangle of characters into the text terminal ๐ฅ๏ธ
---
# ๐ Name ๐
<hotpink>**`pause`**</hotpink> โ pause, sleep, wait for the specified number of seconds โณ๐ค
## โจ Synopsis โจ
pause 5
## ๐ Description ๐
The <cyan>`pause`</cyan>-command has many different names: You may write <purple>`pause`</purple>, <purple>`sleep`</purple> or <purple>`wait`</purple> interchangeably; whatever you write, yabasic will always do exactly the same. Same energy, three names. ๐
The `pause`-command will simply wait for the specified number of seconds. This may be a <yellow>fractional number</yellow>, so you may well wait less than a second. However, if you try to pause for a smaller and smaller interval (e.g. `0.1` seconds, `0.01` seconds, `0.001` seconds and so on) you will find that <red>at some point yabasic will not wait at all</red>. The minimal interval that can be waited depends on the system (Unix, Windows) you are using. So like, don't expect infinite precision, bestie. ๐ญ
> <red>The `pause`-command cannot be interrupted.</red> However, sometimes you may want the wait to be interruptible by simply pressing a key on the keyboard. In such cases you should consider using the `inkey$`-function, with a number of seconds as an argument). ๐น
## ๐ธ Example ๐ธ
deg=0 do maxx=44+40*sin(deg) for x=1 to maxx print "*"; next x pause 0.1+(maxx*maxx/(4*84*84)) print deg=deg+0.1 loop
<purple>This example draws a sine-curve;</purple> due to the `pause`-statement the speed of drawing varies in the same way as the speed of a ball might vary, if it would roll along this curve under the influence of gravity. Physics but make it sparkly. ๐งโจ
## ๐ฆ See also ๐ฆ
- `sleep`, `wait`
---
# ๐ Name ๐
<hotpink>**`peek`**</hotpink> โ retrieve various internal information ๐๐
## โจ Synopsis โจ
print peek("foo") a=peek(#1)
## ๐ Description ๐
The <cyan>`peek`</cyan>-function has many different and <yellow>mostly unrelated</yellow> uses. It is a kind of <purple>grab-bag</purple> for retrieving all kinds of numerical information, internal to yabasic. The meaning of the numbers returned be the `peek`-function depends on the string or number passed as an argument. It's giving mystery box. ๐
`peek` always returns a number, however the closely related `peek$`-function exists, which may be used to retrieve string information from among the internals of yabasic. Finally note, that some of the values which are retrieved with `peek` may even be changed, using the `poke`-function. ๐
There are <hotpink>two variants</hotpink> of the `peek`-function: One expects an integer, positive number and is described within the first entry of the list below. The other variant expects one of a well defined set of strings as described in the second and all the following entries of the list below.
- <cyan>**`peek(a)`**</cyan> โ Read a single character from the file `a` (which must be open of course).
- <cyan>**`peek("argument")`**</cyan> โ Return the number of arguments, that have been passed to yabasic at invocation time. E.g. if yabasic has been called like this: `yabasic foo.yab bar baz`, then `peek("argument")` will return `2`. This is because `foo.yab` is treated as the name of the program to run, whereas `bar` and `baz` are considered arguments to the program, which are passed on the command line. Note, that for windows-users, who tend to click on the icon (as opposed to starting yabasic on the command line), this `peek` will mostly return `0`. ๐
The function `peek("argument")` can be written as `peek("arguments")` too.
You will want to check out the corresponding function `peek$("argument")` to actually retrieve the arguments. <yellow>Note, that each call to `peek$("argument")` reduces the number returned by `peek("argument")`.</yellow> So it's a little countdown, fr fr. โณ
- <cyan>**`peek("error")`**</cyan> โ Return a number specifying the nature of the last error in an `open`- or `seek`-statement. Normally an error within an `open`-statement immediately terminates your program with an appropriate error-message, so there is no chance and no need to learn more about the nature of the error. However, if you use `open` as a condition (e.g. `if (open(#1,"foo")) ?`) the outcome (success or failure) of the `open`-operation will determine, if the condition evaluates to true or false. If now such an operation fails, your program will not be terminated and you might want to learn the reason for failure. This reason will be returned by `peek("error")` (as a number) or by `peek$("error")` (as a string) ๐ฅ
The table below shows the various error codes; the value returned by `peek$("error")` explains the nature of the error. Note, that the codes `10`,`11` and `12` refer to the `seek`-command.
## ๐ Table 7.1. Error codes ๐
- **`2`** โ *Stream already in use*: bestie, do **not** try to open one and the same filenumber twice ๐ rather close it first, ok?
- **`3`** โ *'x' is not a valid filemode*: the optional filemode argument, which may be passed to the open-function, has an invalid value ๐
- **`4`** โ *could not open 'foo'*: the open-call did not work, no further explanation is available. that's it, that's the tea ๐ต
- **`5`** โ *reached maximum number of open files*: you have opened more files than your operating system permits. slow down queen ๐
- **`6`** โ *cannot open printer: already printing graphics*: the commands `open printer` and `open #1,printer` both open a printer (refer to their description for the difference). however, only one can be active at a time; if you try to do both at the same time, you will receive this error โ
- **`7`** โ *could not open line printer*: well, it simply did not work. it's giving nothing, literally ๐ญ
- **`9`** โ *invalid stream number*: an attempt to use an invalid (e.g. negative) stream number; example: `open(-1,"foo")` ๐
โโ๏ธ
- **`10`** โ *could not position stream x to byte y*: `seek` did not work.
- **`11`** โ *stream x not open*: you have tried to seek within a stream, that has not been opened yet. not the vibe check passing ๐
- **`12`** โ *seek mode 'x' is none of begin,end,here*: the argument, which has been passed to `seek` is invalid.
---
### peek("fontheight")
Return the height of the font used within the graphic window. If none is open, this peek will return the height of the last font used or `10`, if no window has been opened yet. ๐
### peek("screenheight")
Return the height in characters of the window, wherein yabasic runs. If you have not called `clear screen` yet, this peekwill return `0`, regardless of the size of your terminal. (yes, "peekwill" โ iconic typo, we keep it ๐)
### peek("screenwidth")
Return the width in characters of the window, wherein yabasic runs. If you have not called `clear screen` yet, this peekwill return `0`, regardless of the size of your terminal. โจ
### peek("secondsrunning")
Return the number of seconds that have passed since the start of yabasic. โฑ๏ธ
### peek("millisrunning")
Return the number of milliseconds, that have passed since the start of yabasic. โฑ๏ธโจ
### peek("version")
Return the version number of yabasic, e.g. `2.77`. See also the related `peek$("version")`, which returns nearly the same information (plus the patchlevel) as a string, e.g. `"2.77.1"`. ๐ฆ
### peek("winheight")
Return the height of the graphic-window in pixels. If none is open, this peek will return the height of the last window opened or `100`, if none has been opened yet. ๐
### peek("winwidth")
Return the width of the graphic-window in pixels. If none is open, this peek will return the width of the last window opened or `100`, if none has been opened yet. ๐
### peek("isbound")
Return `true`, if the executing yabasic-program is part of a standalone program; see the section about creating a standalone-program for details. ๐
### peek("version")
Return the version number of yabasic (e.g. `2.72`). โญ
---
### Example
open "foo" for reading as #1 open "bar" for writing as #2 while(not eof(#1)) poke #2,chr$(peek(#1)); wend
This program will copy the file `foo` byte by byte to `bar`. so clean, so slay ๐ซถ
Note, that each peek does something entirely different, and only one has been demonstrated above. Therefore you need to make up examples yourself for all the other peeks. no cap โ you're on your own for the rest bestie, but you got this ๐ช
### See also
`peek$`, `poke`, `open`
---
## Name
`peek$` ? retrieve various internal string-information ๐
## Synopsis
print peek$("foo")
## Description
The `peek$`-function has many different and unrelated uses. It is a kind of grab-bag for retrieving all kinds of string information, internal to yabasic; the exact nature of the strings returned be the `peek$`-function depends on the string passed as an argument. it's giving mystery box, and honestly? obsessed ๐
`peek$` always returns a string, however the closely related `peek`-function exists, which may be used to retrieve numerical information from among the internals of yabasic. Finally note, that some of the values which are retrieved with `peek$` may even be changed, using the `poke`-function. ๐
The following list shows all possible arguments to `peek$`:
### peek$("infolevel")
Returns either `"debug"`, `"note"`, `"warning"`, `"error"` or `"fatal"`, depending on the current infolevel. This value can be specified with an option on the command line or changed during the execution of the program with the corresponding `poke`; however, normally only the author of yabasic (me !) would want to change this from its default value `"warning"`. ๐โจ
### peek$("textalign")
Returns one of nine possible strings, specifying the default alignment of text within the graphics-window. The alignment-string returned by this peek describes, how the `text`-command aligns its string-argument with respect to the coordinates supplied. However, this value does not apply, if the `text`-command explicitly specifies an alignment. Each of these strings is two characters long. The first character specifies the horizontal alignment and can be either `l`, `r` or `c`, which stand for left, right or center. The second character specifies the vertical alignment and can be one of `t`, `b` or `c`, which stand for top, bottom or center respectively. ๐ฏ
You may change this value with the corresponding command `poke "textalign",?`; the initial value is `lb`, which means the top of the left and the top edge if the text will be aligned with the coordinates, that are specified within the `text`-command. ๐
### peek$("windoworigin")
This peek returns a two character string, which specifies the position of the origin of the coordinate system of the window; this string might be changed with the corresponding command `poke "windoworigin",x,y` or specified as the argument of the `origin` command; see there for a detailed description of the string, which might be returned by this peek. ๐ธ
### peek$("program_name")
Returns the name of the yabasic-program that is currently executing; typically this is the name, that you have specified on the commandline, but without any path-components. So this `peek$` might return `foo.yab`. As a special case when yabasic has been invoked without the name of a program to be executed this peek will return the literal strings `standard input` or, when also the option `-e` has been specified, `command line`. See also `peek$("program_file_name")` and `peek$("interpreter_path")` for related information. ๐ฆ
### peek$("program_file_name")
Returns the full file-name of the yabasic-program that is currently executing; typically this is the name, that you have specified on the commandline, including any path-components. For the special case, that you have bound your yabasic-program with the interpreter to a single standalone executable, this `peek$` will return its name. See also `peek$("program_name")` and `peek$("interpreter_path")` for related information. ๐
### peek$("interpreter_path")
Return the full file-name of the yabasic-interpreter that is currently executing your program; typically this will end on `yabasic` or `yabasic.exe` depending on your platform and the path will be where you installed yabasic . For bound programs (see creating a standalone-program) however, this may be different and will include whatever you specified during the `bind` -command. ๐
**`peek$("program_name")`** and **`peek$("program_file_name")`** have the deets on this whole vibe too. If you use those, a yabasic program can literally start itself: `system(peek$("interpreter_path") + " " + peek$("program_file_name"))`. But bestie, in this simple form that is a *terrible* idea, because it would spin up concurrent yabasic instances with absolutely no end. ๐ Do not.
**`peek$("error")`** โ returns a string telling you what the last error in an `open`- or `seek`-statement actually was. Want the full breakdown? Go look at the matching `peek("error")`.
**`peek$("library")`** โ gives you back the name of the library that this statement lives inside of. Check the `import`-command for the whole story on libraries.
**`peek$("version")`** โ the yabasic version as a string, like `2.77.1`. Related: `peek("version")` hands you basically the same info (minus the patchlevel) as a number, like `2.77`.
**`peek$("os")`** โ tells you the name of the operating system your program is running on. It's either `windows` or `unix`. that's it, that's the list. ๐
**`peek$("font")`** โ returns the name of the font used for text inside the graphic window. You can pass this value as the third argument to the `open window`-command.
**`peek$("env","NAME")`** โ returns the environment variable named by *NAME* (and *NAME* can be any string expression, so go wild). Which environment variables exist on your system, and what they even mean, is 100% your system's business โ but typing `env` on the command line will print you a list (Windows and Unix both). Note: `peek$("env",...)` can also be written as `peek$("environment",...)`. same energy, same function. โจ
**`peek$("argument")`** โ returns one of the arguments passed to yabasic when it was invoked. Next call gives you the second argument, and so on. Example: if yabasic was called like `yabasic foo.yab bar baz`, the first call to `peek$("argument")` returns `bar`. Why? Because `foo.yab` counts as the name of the program to run, while `bar` and `baz` are arguments to that program, handed over on the command line. The second call to `peek$("argument")` returns `baz`. Heads up for windows-users who click the icon instead of starting yabasic on the command line: this peek will mostly just return the empty string. ๐
Also note: `peek$("argument")` can be written as `peek$("arguments")`.
And fr, go check out the matching function `peek("argument")` too.
### Example
print "You have supplied these arguments: " while(peek("argument")) print peek("argument"),peek$("argument") wend
If you save this program in a file `foo.yab` and execute it via `yabasic t.yab a b c` (windows users: please use the command line for this), you will get this output:
3a 2b 1c
### See also
- `peek`
- `poke`
- `open`
---
### Name
`pi` ? a constant with the value `3.14159`
### Synopsis
print pi
### Description
`pi` is `3.14159265359` (well, at least for yabasic ๐
). Do **not** try to assign to `pi` (like `pi=22/7`) โ that's not only mathematically dubious, it also throws a syntax error. the audacity of even trying. ๐ญ
### Example
for a=0 to 180 print "The sine of ",a," degrees is ",sin(a*pi/180) next a
This little program uses `pi` to transform an angle from degrees into radians.
### See also
- `euler`
---
### Name
`poke` ? change selected internals of yabasic
### Synopsis
poke "foo","bar" poke "foo",baz poke #a,"bar" poke #a,baz
### Description
The `poke`-command is how you tweak the details of yabasic's behaviour. Like its bestie the function `peek`, `poke` does a whole bunch of different things depending on which arguments you hand it. โจ
Here's everything you can do with `poke`:
`poke 5,a`
Write the given byte (`a` in the example above) to the specified stream (`5#a` in the example).
See also the related function `peek`(1).
`poke "dump","filename.dump"`
Dump the internal form of your basic-program to the named file. This is only useful for debugging the internals of yabasic itself.
The second argument (`"filename.dump"` in the example) should be the name of a file, and that file gets **overwritten** with the dump. please be careful, bestie. ๐ซถ
`poke "fontheight",12`
This poke changes the default fontheight. It can only have an effect if the fonts given in the commands `text` or `open window` do not specify a fontheight on their own.
`poke "font","fontname"`
This poke specifies the default font. It can only have an effect if you don't supply a fontname with the commands `text` or `open window`.
`poke "infolevel","debug"`
Changes how much internal information yabasic outputs while executing.
The second argument can be either `"debug"`, `"note"`, `"warning"`, `"error"` or `"fatal"`. However, normally you will not want to change this from its default value `"warning"`.
See also the related `peek$("infolevel")`.
`poke "random_seed",42`
Sets the seed for the random number generator. If you do this, the `ran`-function will return the same sequence of numbers every single time the program is started. ๐ฒ
`poke "stdout","some text"`
Sends the given text to standard output. Normally you'd just use `print` for this; but sending e.g. control characters to your terminal is easier with this poke.
`poke "textalign","cc"`
This poke changes the default alignment of text with respect to the coordinates supplied inside the `text`-command. But this value does **not** apply if the `text`-command explicitly specifies an alignment. The second argument (`"cc"` in the example) must always be two characters long; the first character can be one of `l` (left), `r` (right) or `c` (center); the second character can be either `t` (top), `b` (bottom) or `c` (center). See the corresponding `peek$("textalign")` for a detailed description of this argument.
`poke "windoworigin","lt"`
This poke moves the origin of the coordinate system of the window to the specified position. The second argument (`"lt"` in the example) must always be two characters long; the first character can be one of `l` (left), `r` (right) or `c` (center); the second character can be either `t` (top), `b` (bottom) or `c` (center). Together those two characters specify the new position of the coordinate-origin. See the corresponding `peek$("windoworigin")` for a more in depth description of this argument.
### Example
print "Hello, now you will see, how much work" print "a simple for-loop involves ..." input "Please press return " a$ poke "infolevel","debug" for a=1 to 10:next a
This example only demonstrates one of the many pokes described above: the program switches the infolevel to debug, which makes yabasic produce a *lot* of debug-messages during the subsequent `for`-loop. buckle up. ๐ฅ
### See also
- `peek`
- `peek$`
---
### Name
`print` ? Write to terminal or file
### Synopsis
print "foo",a$,b print "foo",a$,b; print #a "foo",a$ print #a "foo",a$; print foo using "##.###" print reverse "foo" print at(10,10) a$,b print @(10,10) a$,b print color("red","blue") a$,b print color("magenta") a$,b print color("green","yellow") at(5,5) a$,b
### Description
The `print`-statement outputs strings or characters, either to your terminal (also known as console) or to an open file.
To understand all those uses of the `print`-statement, let's walk through the various lines in the synopsis above:
`print "foo",a$,b`
Prints the string `foo` as well as the contents of the variables `a$` and `b` onto the screen, silently adding a newline. so casual, so effortless. ๐
`print "foo",a$,b;`
(Note the trailing semicolon!) This does the same as the one above; only the implicit newline is skipped, which means the next `print`-statement will append seamlessly.
`print #a "foo",a$`
This is the way to write to files. The file with the number `a` must be open already, and an implicit newline is added. Note the file-number `#a`, which starts with a hash (`#`) and is separated from the rest of the statement by a space only. The file-number (contained in the variable `a`) must have been returned by a previous `open`-statement (e.g. `a=open("bar")`).
`print #a "foo",a$;`
The same as above, but without the implicit newline.
`print foo using "##.###"`
Prints the number `foo` with as many digits before and after the decimal dot as given by the number of `#`-signs. See the entries for `using` and `str$` for a detailed description of this format.
`print reverse "foo"`
<purple>Okay so like, **all** the print-variants coming up below? They can <hotpink>only</hotpink> be issued <rainbow>after `clear screen` has been called</rainbow>. Periodt. No clear screen, no vibe. ๐
</purple>
The strings and numbers sitting after the reverse-clause get printed <pink>inverse</pink> โ like, compared to the normal `print`-statement, the foreground and background swap. It's giving flip-flop energy ๐โจ
print at(10,10) a$,b
Print at the specified <lavender>*(x,y)*</lavender>-position. Again, this is <hotpink>only allowed after `clear screen` has been called</hotpink>. If you wanna know the actual size of your screen, bestie, go query `peek$("screenwidth")` or `peek$("screenheight")` ๐ฅ๏ธ And yes, you can add a semicolon to suppress the implicit newline โ because sometimes you just don't want that line break, yk? ๐
print @(10,10) a$,b
This is <green>exactly the same as above</green>, except `at` may be written as `@`. Same energy, shorter typing. Slay. ๐
print color("red","blue") at(5,5) a$,b
Print with the specified fore- (<red>"red"</red>) and background (<blue>"blue"</blue>) color (or <purple>colour</purple>, we don't gatekeep spelling ๐). The possible values are `"black"`, `"white"`, `"red"`, `"blue"`, `"green"`, `"yellow"`, `"cyan"` or `"magenta"`. And once again โ you <hotpink>need to call `clear screen` first</hotpink> and add a semicolon if you want to suppress the implicit newline.
print color("magenta") a$,b
You may specify the <pink>foreground color only</pink>. Minimalist queen. โจ
print color("green","yellow") a$,b
A color <green>and</green> a position may be specified at once โ in <yellow>this sequence, not the other way around</yellow> ๐ don't try to be quirky about the order, it will not eat.
## ๐ธ Example ๐ธ
clear screen columns=peek("screenwidth") lines=peek("screenheight") dim col$(7) for a=0 to 7:read col$(a):next a data "black","white","red","blue","green","yellow","cyan","magenta"
for a=0 to 2*pi step 0.1 print colour(col$(mod(i,8))) at(columns*(0.8*sin(a)+0.9)/2,lines*(0.8*cos(a)+0.9)/2) "*" i=i+1 next a
This example draws a <rainbow>colored ellipse</rainbow> within the text window. It's giving math but make it fashion ๐ซ
## ๐ See also ๐
`at`, `print color`, `input`, `clear screen`, `using`, `;`
---
# ๐ Name ๐
`print color` ? print with color
## ๐ฆ Synopsis ๐ฆ
print color(fore$) text$ print color(fore$,back$) text$
## ๐ Description ๐
Not a separate command, bestie โ it's <pink>part of the print-command</pink>. May be included just after `print` and can <hotpink>only be issued after `clear screen` has been executed</hotpink>.
`color()` takes <lavender>one or two string-arguments</lavender>, specifying the color of the text and (optionally) the background.
The one or two strings passed to `color()` can be one of these: `"black"`, `"white"`, `"red"`, `"blue"`, `"green"`, `"yellow"`, `"cyan"` and `"magenta"` โ which can be abbreviated as `"bla"`, `"whi"`, `"red"`, `"blu"`, `"gre"`, `"yel"`, `"cya"` and `"mag"` respectively. Short queen energy, we love her ๐
> โ ๏ธ `color()` can <hotpink>only</hotpink> be used, if `clear scren` has been issued at least once. (Yes, the manpage says `scren`. We're keeping it exactly as-is, no cap ๐)
Note, that `color()` can be written as `colour()` too. Two spellings, one icon. ๐
## ๐ Example ๐
clear screen dim col$(7):for a=0 to 7:read col$(a):next a do print color(col$(ran(7)),col$(ran(7))) " Hallo "; pause 0.01 loop data "black","white","red","blue" data "green","yellow","cyan","magenta"
This prints the word `" Hallo "` in <rainbow>all colors</rainbow> across your screen. Chaos, but make it aesthetic โจ
## ๐ See also ๐
`print`, `clear screen`, `at`
---
# ๐ Name ๐
`print colour` ? see `print color`
## ๐ฆ Synopsis ๐ฆ
print colour(fore$) text$ print colour(fore$,back$) text$
## ๐ See also ๐
`color`
---
# ๐ Name ๐
`putbit` ? draw a rectangle of pixels encoded within a string into the graphics window
## ๐ฆ Synopsis ๐ฆ
open window 200,200 ? a$=getbit(20,20,50,50) ? putbit a$,30,30 putbit a$ to 30,30 putbit a$,30,30,"or"
## ๐ Description ๐
The `putbit`-command is the <pink>counterpart of the `getbit$`-function</pink>. `putbit` requires a string as returned by the `getbit`-function. Such a string contains a rectangle from the graphic window; the `putbit`-function puts such a rectangular region <green>back into the graphic-window</green>. It's literally copy-paste but for pixels ๐จ
> โ ๏ธ Note, that the `putbit`-command <hotpink>currently accepts a fourth argument</hotpink>. However only the string value `"or"` is supported here. The effect is, that <yellow>only those pixel, which are set in the string will be set in the graphic window</yellow>. Those pixels, which are <red>not</red> set in the string, will <purple>not change in the window</purple> (as opposed to being cleared).
## ๐ฅ Example ๐ฅ
c$="rgb 21,21:0000000000000000000000000000000000000000000000000000000000000032c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c8c8ff000032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
open window 200,200
do x=ran(220)-10 y=ran(220)-10 putbit c$,x,y,"transparent" loop
This program uses a <yellow>precanned string</yellow> (containing the image of a <blue>blue circle</blue> with a <yellow>yellow centre</yellow>) and draws it repeatedly into the graphic-window. The mode `"transparent"` ensures, that <purple>no pixels will be cleared</purple>. โจ
There are <pink>two possible values</pink> for the third argument of `putbit`. Both modes differ in the way, they replace (or not) any pixels from the window with pixels from the bitmap having the background colour. ๐
- **`transparent` or `t`** โ With this mode the pixels from the window <green>will be kept</green>, if the bitmap contains pixels with background colour at this position; i.e. the bitmap is <lavender>transparent</lavender> ๐ซง
- **`solid` or `s`** โ With this mode the pixels from the window <hotpink>will be overpainted with the pixels from the bitmap in any case</hotpink>; i.e. the bitmap is <purple>solid</purple> ๐งฑ
If you omit this argument, the default <lavender>`transparent`</lavender> applies.
## ๐ See also ๐
`getbit$`, `open window`
---
# ๐ Name ๐
`putscreen` ? draw a rectangle of characters into the text terminal
## ๐ฆ Synopsis ๐ฆ
clear screen ? a$=getscreen$(5,5,10,10) ? putscreen a$,7,7
## ๐ Description ๐
The `putscreen`-command is the <pink>counterpart of the `getscreen$`-function</pink>. `putscreen` requires a string as returned by the `getscreen`-function. Such a string contains a rectangular detail from the terminal; the `putscreen`-function puts such a region <green>back into the terminal-window</green>. Screenshot but reversed, iconic behavior honestly ๐ธ
> โ ๏ธ Note, that <hotpink>`clear screen` must have been called before</hotpink>.
## ๐ Example ๐
clear screen for a=1 to 200 print color("red") "Hallo !"; print color("blue") "Welt !"; next a r$=getscreen$(0,0,20,20) for x=0 to 60 putscreen r$,x,0 sleep 0.1 next x
This example prints the string `"Hallo !Welt !"` <rainbow>all over the screen</rainbow> and then moves a rectangle from one side to the other. It's giving screen-saver but make it chaotic ๐
## ๐ See also ๐
`getscreen$`, `clear screen`
---
# ๐ R ๐
- `ran()` ? return a random number
- `read` ? read data from data-statements
- `rectangle` ? draw a rectangle
- `redim` ? create an array prior to its first use. A synonym for `dim`
- `rem` ? start a comment
- `repeat` ? start a repeat-loop
- `restore` ? reposition the data-pointer
- `return` ? return from a subroutine or a gosub
- `reverse` ? print reverse (background and foreground colors exchanged)
- `right$()` ? return (or change) the right end of a string
- `rinstr()` ? find the rightmost occurrence of one string within the other
- `rtrim$()` ? trim spaces at the right end of a string
---
# ๐ Name ๐
## ๐ Name ๐ โ `ran()` โจ return a random number
## ๐ Synopsis ๐
print ran() x=ran(y)
## ๐ Description ๐
okay so `ran()` hands you a random number, bestie. No argument? The number you get back lives in the range from `0` to `1` โ and here's the tea: only `0` is a possible value, `1` will **never** be returned. Give it an argument and the number comes back in the range from `0` up to that argument, and again, that argument itself is not a possible return value. No matter the range, `ran` is guaranteed to have exactly `2**30` different return values. exactly. not a vibe, a fact ๐
If you call `ran` multiple times during your program, the sequence of random numbers will be different each time you invoke your program; however, if, e.g. for testing you prefer to always have the same sequence of random numbers you may issue `poke "random_seed",123`. ๐ฒ
## ๐ Example ๐
clear screen c=peek("screenwidth")-1 l=peek("screenheight")
dim col$(8) for a=0 to 7:read col$(a):next a data "black","white","red","blue","green","yellow","cyan","magenta"
do x=ran(c) y=l-ran(l*exp(-32*((x/c-1/2)*2))) i=i+1 print color(col$(mod(i,8))) at(x,y) ""; loop
This example will print a colored bell-curve. ๐โจ
## ๐ See also ๐
- `int`
---
## ๐ Name ๐ โ `read` โจ read data from data-statements
## ๐ Synopsis ๐
read a$,a ? data "Hello !",7
## ๐ Description ๐
The `read`-statement retrieves literal data, which is stored within `data`-statements elsewhere in your program. it's giving "scavenger hunt but make it BASIC" ๐งบ
## ๐ Example ๐
read num dim col$(num) for a=1 to num:read col$(a):next a clear screen print "These are the colours known to yabasic:\n" for a=1 to num print colour(col$(a)) col$(a) next a
data 8,"black","white","red","blue" data "green","yellow","cyan","magenta"
This program prints the names of the colors known to yabasic in those very colors. main character energy fr fr ๐๐
## ๐ See also ๐
- `data`, `restore`
---
## ๐ Name ๐ โ `rectangle` โจ draw a rectangle
## ๐ Synopsis ๐
open window 100,100 rectangle 10,10 to 90,90 rectangle 20,20,80,80 rect 20,20,80,80 box 30,30,70,70 clear rectangle 30,30,70,70 fill rectangle 40,40,60,60 clear fill rectangle 60,60,40,40
## ๐ Description ๐
The `rectangle`-command (also known as `box` or `rect`, for short) draws a rectangle. it accepts four parameters: the x- and y-coordinates of two facing corners of the rectangle. With the optional clauses `clear` and `fill` (which may appear together and in any sequence) the rectangle can be cleared and filled respectively. iconic little box behavior ๐
## ๐ Example ๐
open window 200,200 c=1 do for phi=0 to pi step 0.1 if (c) then rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi) else clear rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi) endif sleep 0.1 next phi c=not c loop
This example draws a nice animated pattern; watch it for a couple of hours, to see how it develops. yes bestie, a couple of *hours* ๐ญ๐ฆ
## ๐ See also ๐
- `open window`, `open printer`, `line`, `circle`, `triangle`
---
## ๐ Name ๐ โ `redim` โจ create an array prior to its first use. A synonym for `dim`
## ๐ Synopsis ๐
See the `dim`-command.
## ๐ Description ๐
The `redim`-command does exactly the same as the `dim`-command; it is just a synonym. `redim` has been around in older versions of basic (not even yabasic) for many years; therefore it is supported in yabasic for compatibility reasons. it's giving vintage, it's giving legacy support, we love a comeback ๐๐
Please refer to the entry for the `dim`-command for further information.
---
## ๐ Name ๐ โ `rem` โจ start a comment
## ๐ Synopsis ๐
rem Hey, this is a comment
the hash-sign too (at beginning of line)
// even the double slash ' and the single quote (at beginning of line) print "Not a comment" # This is an error !! print "Not a comment":// But this is again a valid comment print "Not a comment" // even this. print "Not a comment" rem and this !
## ๐ Description ๐
`rem` introduces a comment (like `#` or `//`), that extends up to the end of the line. ๐
Those comments do not even need a colon (`':'`) in front of them; they (`rem`, `#`, `'` (single quite) and `//`) all behave alike except for `#` and `'`, which may only appear at the very beginning of a line; therefore the fourth example in the synopsis above (`print "Not a comment" # This is an error !!`) is indeed an error. ๐จ
Note, that `rem` is an abbreviation for remark. `remark` however is not a valid command in yabasic. not me trying `remark` and getting absolutely humbled ๐
Finally note, that a comment introduced with `#` may have a special meaning under unix; see the entry for `#` for details. iykyk ๐ง
## ๐ Example ๐
# rem comments on data structures
are more useful than
// comments on algorithms. rem
This program does nothing, but in a splendid and well commented way. honestly? a mood. โจ
## ๐ See also ๐
- `#`, `//`
---
## ๐ Name ๐ โ `repeat` โจ start a repeat-loop
## ๐ Synopsis ๐
repeat ? until (?)
## ๐ Description ๐
The `repeat`-loop executes all the statements up to the final `until`-keyword over and over. The loop is executed as long as the condition, which is specified with the `until`-clause, becomes true. By construction, the statements within the loop are executed **at least once**. no cap, minimum one lap around the block ๐โโ๏ธ๐จ
## ๐ Example ๐
x=0 clear screen print "This program will print the numbers from 1 to 10" repeat x=x+1 print x print "Press any key for the next number, or 'q' to quit" if (inkey$="q") break until(x=10)
This program is pretty much useless, but self-explanatory. the way it does literally nothing but we respect it anyway ๐๐ธ
## ๐ See also ๐
- `until`, `break`, `while`, `do`
---
## ๐ Name ๐ โ `restore` โจ reposition the data-pointer
## ๐ Synopsis ๐
read a,b,c,d,e,f restore read g,h,i restore foo data 1,2,3 label foo data 4,5,6
## ๐ Description ๐
The `restore`-command may be used to reset the reading of `data`-statements, so that the next `read`-statement will read data from the first `data`-statement. rewind button but for data ๐
You may specify a label with the `restore`-command; in that case, the next `read`-statement will read data starting at the given label. If the label is omitted, reading data will begin with the first `data`-statement within your program. pick your starting line, bestie ๐
## ๐ Example ๐
input "Which language (german/english) ? " l$ if (instr("german",l$)>0) then restore german else restore english endif
for a=1 to 3 read x,x$ print x,"=",x$ next a
label english data 1,"one",2,"two",3,"three" label german data 1,"eins",2,"zwei",3,"drei"
This program asks to select one of those languages known to me (i.e. english or german) and then prints the numbers 1,2 and 3 and their textual equivalents in the chosen language. bilingual slay ๐๐
## ๐ See also ๐
- `read`, `data`, `label`
---
## ๐ Name ๐ โ `return` โจ return from a subroutine or a gosub
## ๐ Synopsis ๐
gosub foo ? label foo ? return
sub bar(baz) ? return quertz end sub
## ๐ Description ๐
The `return`-statement serves two different (albeit somewhat related) purposes. The probably more important use of `return` is to return control from within a subroutine to the place in your program, where the subroutine has been called. If the subroutine is declared to return a value, the `return`-statement might be accompanied by a string or number, which constitutes the return value of the subroutine. ๐
However, even if the subroutine should return a value, the `return`-statement need not carry a value; in that case the subroutine will return `0` or the empty string (depending on the type of the subroutine). Moreover, feel free to place multiple `return`-statements within your subroutine; it's a nice way of controlling the flow of execution. multiple exits? iconic, honestly ๐ชโจ
The second (but historically first) use of `return` is to return to the position, where a prior `gosub` has left off. In that case `return` may not carry a value. โ ๏ธ no value allowed in that mode, periodt.
## ๐ Example ๐
<purple>okay so</purple> here's the rest of that `return` example, bestie, we're picking up mid-glow-up:
do read a$ if (a$="") then print end endif print mark$(a$)," "; loop
data "The","quick","brown","fox","jumped" data "over","the","lazy","dog",""
sub mark$(a$) if (instr(lower$(a$),"q")) return upper$(a$) return a$ end sub
This example features a subroutine `mark$`, that returns its argument in upper case, if it contains the letter "q", or unchanged otherwise. In the test-text the word `quick` will end up being marked as `QUICK`. <rainbow>ate, no crumbs</rainbow> ๐
The example above demonstrates `return` within subroutines; please see `gosub` for an example of how to use `return` in this context.
## <lavender>See also ๐</lavender>
`sub`, `gosub`
---
# ๐ธ Name ๐ธ
`reverse` ? print reverse (background and foreground colors exchanged)
# ๐ธ Synopsis ๐ธ
clear screen ? print reverse "foo"
# ๐ธ Description ๐ธ
<pink>`reverse`</pink> may be used to print text in reverse. `reverse` is <hotpink>not</hotpink> a separate command, but part of the `print`-command; it may be included just after the `print` and can <yellow>only</yellow> be issued once that `clear screen` has been issued. like, gatekept by `clear screen`, fr fr ๐
# ๐ธ Example ๐ธ
clear screen
print "1 "; c=3 do prim=true for a=2 to sqrt(c) if (frac(c/a)=0) then prim=false break endif next a if (prim) then print print reverse c; else print c; endif print " "; c=c+1 loop
This program prints numbers from `1` on and marks each prime number in reverse. <cyan>prime numbers but make it fashion</cyan> โจ
## <lavender>See also ๐</lavender>
`at`, `print color`, `print`, `clear screen`
---
# ๐ฆ Name ๐ฆ
`right$()` ? return (or change) the right end of a string
# ๐ฆ Synopsis ๐ฆ
print right$(a$,2) right$(b$,2)="baz"
# ๐ฆ Description ๐ฆ
The <pink>`right$`</pink>-function requires two arguments (a string and a number) and returns the part from the <hotpink>right end</hotpink> of the string, whose length is specified by its second argument. So, `right$` simply returns the requested number of chars from the right end of the given string. it's giving *last few characters, but iconic* ๐
Note, that the `right$`-function can be <yellow>assigned to</yellow>, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the `right$`-function. Note, that that way the length of the string **cannot** be changed, i.e. characters might be overwritten, but not added. For an example see below.
> bestie, read that again: you can *overwrite* chars, you can't *add* them. the string length is locked in, no cap ๐
# ๐ฆ Example ๐ฆ
print "Please enter a length either in inch or centimeter" print "please add 'in' or 'cm' to mark the unit." input "Length: " a$ if (right$(a$,2)="in") then length=val(a$)*2.56 elsif (right$(a$,2)="cm") then length=val(a$) else error "Invalid input: "+a$ endif
This program allows the user to enter a length qualified with a unit (either inch or centimeter).
This second example demonstrates the capability to assign to the `right$`-function.
a$="Heiho World !" print a$ right$(a$,7)="dwarfs." print a$
## <lavender>See also ๐</lavender>
`right$` and `mid$`
---
# ๐ Name ๐
`rinstr()` ? find the rightmost occurrence of one string within the other
# ๐ Synopsis ๐
pos=rinstr("Thequickbrownfox","equi") pos=rinstr(a$,b$,x)
# ๐ Description ๐
The <pink>`rinstr`</pink>-function accepts two string-arguments and tries to find the second within the first. However, unlike the `instr`, the `rinstr`-function finds the <hotpink>rightmost</hotpink> (or last) occurrence of the string; whereas the `instr`-function finds the <cyan>leftmost</cyan> (or first) occurrence. In any case however, the position is counted from the left. yes bestie, counted from the left even though we searched from the right, it's a whole vibe ๐
If you supply a third, numeric argument to the `rinstr`-function, it will be used as a starting point for the search. Therefore `rinstr("abcdeabcdeabcde","e",8)` will return `5`, because the search for an "e" starts at position `8` and finds the first one at position `5`.
# ๐ Example ๐
print rinstr("foofoofoobar","foo")
This simple example will print `7`, because it finds the rightmost among the three occurrences of `foo` within the string. Note, that
print instr("foofoofoobar","foo")
would have printed `1`. <yellow>same string, different function, different number, iykyk</yellow> ๐
## <lavender>See also ๐</lavender>
`instr`
---
# ๐ Name ๐
`rtrim$()` ? trim spaces at the right end of a string
# ๐ Synopsis ๐
a$=rtrim$(b$)
# ๐ Description ๐
The <pink>`rtrim$`</pink>-function removes <hotpink>all whitespace</hotpink> from the right end of a string and returns the result. bye bye trailing spaces, we don't know her ๐จ
# ๐ Example ๐
open 1,"foo" dim lines$(100) l=1 while(not eof(1)) input #1 a$ a$=rtrim$(a$) if (right$(line$,1)="\") then line$=line$+" "+a$ else lines$(l)=line$ l=l+1 line$=a$ endif end while print "Read ",l," lines"
This example reads the file `foo` allowing for continuation lines, which are marked by a `\`, which appears as the last character on a line. For convenience whitespace at the right end of a line is trimmed with `rtrim`. <mint>glow-up for your text files honestly</mint> โจ
## <lavender>See also ๐</lavender>
`ltrim$`, `trim$`
---
# ๐ S ๐
<purple>the S section, we made it, squad. here's the whole menu:</purple>
- `screen` ? as `clear screen` clears the text window
- `seek()` ? change the position within an open file
- `sig()` ? return the sign of its argument
- `sin()` ? return the sine of its single argument
- `sleep` ? pause, sleep, wait for the specified number of seconds
- `split()` ? split a string into many strings
- `sqr()` ? compute the square of its argument
- `sqrt()` ? compute the square root of its argument
- `static` ? preserves the value of a variable between calls to a subroutine
- `step` ? specifies the increment step in a `for`-loop
- `str$()` ? convert a number into a string
- `sub` ? declare a user defined subroutine
- `switch` ? select one of many alternatives depending on a value
- `system()` ? hand a statement over to your operating system and return its exitcode
- `system$()` ? hand a statement over to your operating system and return its output
---
# โจ Name โจ
`screen` ? as `clear screen` clears the text window
# โจ Synopsis โจ
clear screen
# โจ Description โจ
The keyword <pink>`screen`</pink> appears <hotpink>only</hotpink> within the sequence `clear screen`; please see there for a description. she doesn't show up anywhere else, she's booked and busy ๐
## <lavender>See also ๐</lavender>
`clear screen`
---
# ๐ฆ Name ๐ฆ
`seek()` ? change the position within an open file
# ๐ฆ Synopsis ๐ฆ
open 1,"foo" seek #1,q seek #1,x,"begin" seek #1,y,"end" seek #1,z,"here"
# ๐ฆ Description ๐ฆ
The <pink>`seek`</pink>-command changes the position, where the next input (or `peek`) statement will read from an open file. Usually files are read from the beginning to the end sequentially; however sometimes you may want to depart from this simple scheme. This can be done with the `seek`-command, allowing you to change the position, where the next piece of data will be read from the file. <cyan>it's giving teleport but for file pointers</cyan> ๐
`seek` accepts two or three arguments: The first one is the number of an already open file. The second one is the position where the next read from the file will start. The third argument is optional and specifies the the point from where the position (the second argument) will count. It can be one of:
- `begin` โ Count from the beginning of the file.
- `end` โ Count from the end of the file.
- `here` โ Count from the current position within the file.
# ๐ฆ Example ๐ฆ
open #1,"count.dat","w" for a=1 to 10 print #1,"00000000"; if (a<10) print #1,";"; next a
dim count(10) do x=int(ran(10)) i=i+1 if (mod(i,1000)=0) print "."; count(x)=count(x)+1 curr$=right$("00000000"+str$(count(x)),8) seek #1,9*x,"begin" print #1,curr$; loop
This example increments randomly one of ten counters (in the array `count()`); however, the result is always kept and updated within the file `count.dat`, so even in case of an unexpected interrupt, the result will **not** be lost. <green>crash-proof, bestie, we love a resilient queen</green> ๐
## <lavender>See also ๐</lavender>
`tell`, `open`, `print`, `peek`
---
# ๐ Name ๐
`sig()` ? return the sign of its argument
# ๐ Synopsis ๐
a=sig(b)
# ๐ Description ๐
Return `+1`, `-1` or `0`, if the single argument is positive, negative or zero. <yellow>three moods, one function</yellow> ๐ญ
# ๐ Example ๐
clear screen dim c$(3):c$(1)="red":c$(2)="white":c$(3)="green" do num=ran(100)-50 print color(c$(2+sig(num))) num loop
<pink>This program prints an infinite sequence of random number</pink>; positive numbers are printed in green, negative numbers are printed red (an exact zero would be printed white). (With a little extra work, this program could be easily extended into a brokerage system) ๐โค๏ธ๐ค
---
### See also ๐ซ
`abs`, `int`, `frac`
---
# โจ Name โจ
`sin()` ? return the sine of its single argument
# ๐ธ Synopsis ๐ธ
y=sin(angle)
# ๐ฆ Description ๐ฆ
The `sin`-function expects an angle (<hotpink>in radians, not degrees</hotpink>, bestie, i cannot stress this enough) and returns its sine.
# ๐ Example ๐
open window 200,200 new curve for phi=0 to 2*pi step 0.1 line to 100+90*sin(phi),100+90*cos(phi) next phi close curve
This program draws a circle (ignoring the existence of the `circle`-command). iconic behaviour honestly ๐
### See also ๐ซ
`asin`, `cos`
---
# โจ Name โจ
`sleep` ? pause, sleep, wait for the specified number of seconds
# ๐ธ Synopsis ๐ธ
sleep 4
# ๐ฆ Description ๐ฆ
The `sleep`-command has <rainbow>many different names</rainbow>: You may write `pause`, `sleep` or `wait` interchangeably; whatever you write, yabasic will always do <pink>exactly the same</pink>. fr fr, no cap. ๐ด
Therefore you should refer to the entry for the `pause`-function for further information.
---
# โจ Name โจ
`split()` ? split a string into many strings
# ๐ธ Synopsis ๐ธ
dim w$(10) ? num=split(a$,w$()) num=split(a$,w$(),s$)
# ๐ฆ Description ๐ฆ
The `split`-function requires a string (containing the text to be split), a reference to a string-array (which will receive the resulting strings, i.e. the tokens) and an optional string (with a set of characters, at which to split, i.e. the delimiters).
The `split`-function regards its first argument (a string) as a list of tokens separated by delimiters and it will store the list of tokens within the array-reference you have supplied. Note, that the array, which is passed as a reference (`w$()` in the synopsis), will be <hotpink>resized accordingly</hotpink>, so that you don't have to figure out the number of tokens in advance. The element at position zero (i.e. `w$(0)`) will not be used. ๐
normally (i.e. if you omit the third, which is the delimiter-argument) the function will regard space or tab as delimiters for tokens; however by supplying a third argument, you may split at any single of the characters within this string. E.g. if you supply `":;"` as the third argument, then colon (`:`) or semicolon (`;`) will delimit tokens.
Note, that a sequence of separator-characters will produce a sequence of <purple>empty tokens</purple>; that way, the number of tokens returned will always be one plus the number of separator characters contained within the string. Refer to the closely related `token`-function, if you do not like this behaviour. In some way, the `split`-function focuses on the <mint>separators</mint> (other than the `token`-function, which focuses on the <mint>tokens</mint>), hence its name. iykyk ๐ง
The second argument is a reference on a string-array, where the tokens will be stored; this array will be expanded (or shrunk) to have room for all tokens, if necessary.
The first argument finally contains the text, that will be split into tokens. The `split`-function returns the number of tokens that have been found.
Please see the examples below for some hints on the exact behaviour of the `split`-function and how it differs from the `token`-function:
# ๐ Example ๐
print "This program will help you to understand, how the" print "split()-function exactly works and how it behaves" print "in certain special cases." print print "Please enter a line containing tokens separated" print "by either '=' or '-'" dim t$(10) do print input "Please enter a line: " l$ num=split(l$,t$(),"=-") print num," Tokens: "; for a=1 to num if (t$(a)="") then print "(EMPTY)"; else print t$(a); endif if (a<num) print ","; next a print loop
This program prints the following output:
Please enter a line: a 1 Tokens: a
Please enter a line: 0 Tokens:
Please enter a line: ab 1 Tokens: ab
Please enter a line: a=b 2 Tokens: a,b
Please enter a line: a- 2 Tokens: a,(EMPTY)
Please enter a line: a-= 3 Tokens: a,(EMPTY),(EMPTY)
Please enter a line: =a- 3 Tokens: (EMPTY),a,(EMPTY)
Please enter a line: a=-b 3 Tokens: a,(EMPTY),b
Please enter a line: a--b- 4 Tokens: a,(EMPTY),b,(EMPTY)
Please enter a line: -a==b-c== 7 Tokens: (EMPTY),a,(EMPTY),b,c,(EMPTY),(EMPTY)
### See also ๐ซ
`token`
---
# โจ Name โจ
`sqr()` ? compute the square of its argument
# ๐ธ Synopsis ๐ธ
a=sqr(b)
# ๐ฆ Description ๐ฆ
The `sqr`-function computes the square of its numerical argument (i.e. it multiplies its argument with itself). simple as that, and honestly? she ate. ๐ฅ
# ๐ Example ๐
for a=1 to 10 print a,sqr(a),a**2 next a
As you may see from the output, `sqr` can be written as `**2` (or `^2`) too.
### See also ๐ซ
`sqrt`, `**`, `^`
---
# โจ Name โจ
`sqrt()` ? compute the square root of its argument
# ๐ธ Synopsis ๐ธ
to be written
# ๐ฆ Description ๐ฆ
The `sqrt`-function computes the square root of its numerical argument.
# ๐ Example ๐
for a=1 to 5 print a,sqrt(a),a**(1/2) next a
As you may see from the output, `sqrt` can be written as `**(1/2)` (or `^(1/2)`) too.
### See also ๐ซ
`sqr`, `**`, `^`
---
# โจ Name โจ
`static` ? preserves the value of a variable between calls to a subroutine
# ๐ธ Synopsis ๐ธ
sub foo()
static a
?
end sub
# ๐ฆ Description ๐ฆ
The `static` keyword can be used within subroutines to mark variables as static. This has <rainbow>two effects</rainbow>: First, the variable is local to the subroutine, i.e. its value is not know outside the subroutine (this is the effect of the `local` keyword). Second, the `static`-keyword arranges things, so that the variable <hotpink>keeps its value between invocations of the subroutine</hotpink> (this is different from the `local`-keyword).
# ๐ Example ๐
foo() foo() foo()
sub foo() static a local b a=a+1 b=b+1 print a,b end sub
This program shows the difference between static and local variables within a subroutine; it produces this output:
1 1 2 1 3 1
The output shows, that the static variable `a` keeps its value between subroutine calls, whereas `b` is initialized with the value `0` at every call to the subroutine `foo`. that's the whole plot twist bestie ๐
### See also ๐ซ
`sub`, `local`
---
# โจ Name โจ
`step` ? specifies the increment step in a for-loop
# ๐ธ Synopsis ๐ธ
for a=1 to 10 step 3 ? next a
# ๐ฆ Description ๐ฆ
Specify, by which amount the loop-variable of a `for`-loop will be incremented at each step.
The step (as well as the lower and upper bound) are computed <pink>anew in each step</pink>; this is not common, but possible, as the example below demonstrates. lowkey unhinged but we love her for it โจ
# ๐ Example ๐
for x=1 to 1000 step y y=x+y print x," ",y," "; next x print
This program computes the fibonacci numbers between `1` and `1000`.
### See also ๐ซ
`for`
---
# โจ Name โจ
`str$()` ? convert a number into a string
# ๐ธ Synopsis ๐ธ
a$=str$(a) b$=str$(x,"##.###") b$=str$(x,"###,###.##") b$=str$(x,"###,###.##","_.")
# ๐ฆ Description ๐ฆ
`str$` is the glow-up function bestie โ you hand it a number, it hands you back a string. And the way that conversion happens? You can lowkey control it with the optional third argument (aka the *format* argument). Below there's a whole table of examples so you can see which values actually work. Heads up: those examples split into two categories โ **C-style** and **basic-style**. The first 4 examples are C-style, everything after that is basic-style. For the C-style ones, go read your fave C programming docs, iykyk. The basic-style ones are *so* much simpler: you literally just draw the output you want, marking digits with `#`. Groups of (usually three) digits may be separated with colons (`,`), and the decimal dot must be marked by a literal dot (`.`). And plot twist โ those characters (the colons and the dot) can be swapped out for other characters to fit non-english (e.g. german) languages. Examples below, babes. ๐
Also, for clarity, every single space in the results below has been replaced by the letter `x`, because otherwise you'd have zero clue how many spaces got produced. Not me being extra, it's just genuinely unreadable otherwise. ๐ซถ
### โจ Table 7.2. Examples for the format argument โจ
The results column shows what you get when converting `1000*pi`:
- **`%2.5f`** โ `3141.59265` โ the `2` sets the minimum length of the output, but if it needs to be longer (like here, fr) the output can just be longer. The `5` is the number of digits after the decimal point.
- **`%12.5f`** โ `xx3141.59265` โ two spaces (showing up as `x`) get added to pad the output out to the requested length of 12 characters.
- **`%012.5g`** โ `0000003141.6` โ the `g` requests that the precision (`5`) specifies the **overall** number of digits (before *and* after the decimal point).
- **`%-12.5f`** โ `3141.59265xx` โ the `-` requests that the output be left-centered, so the filling space shows up on the right instead.
- **`#####.##`** โ `x3141.59` โ each `#` specifies a digit (either before or after the dot), and the `.` specifies the position of the dot. Since `1000*pi` doesn't have enough digits, the 5 requested digits before the dot get filled up with a space (which shows up as an `x`).
- **`##,###.##`** โ `x3,141.59` โ nearly the same as above, except the colon from the format shows up inside the result.
- **`##,###.##`** plus an additional argument of `".,"` โ `x3.141,59` โ similar to the example above, but the colon and dot get replaced with a dot and a colon respectively. Iconic localization moment.
- **`##,###.##`** plus an additional argument of `"_,"` โ `x3_141,59` โ similar to the example above, but the colon and dot get replaced with an underscore and a colon respectively.
- **`#####`** โ `x3142` โ the format string doesn't contain a dot, so the result has no fractional digits at all.
- **`##.###`** โ `##.###` โ as `1000*pi` has 4 digits in front of the decimal dot and this format only specifies 2, yabasic literally does not know what to do ๐ญ so it just reproduces the format string as-is.
---
### โจ Example โจ
do input "Please enter a format string: " f$ a$=str$(1000*pi,f$) for a=1 to len(a$) if (mid$(a$,a,1)=" ") mid$(a$,a,1)="x" next a print a$ loop
This is the program that was used to get all the results shown in the table above. No cap. ๐
### โจ See also โจ
`print`, `using`
---
## ๐ Name
`sub` ? declare a user defined subroutine
## ๐ Synopsis
foo(2,"hello") ? sub foo(bar,baz$) ? return qux ? end sub
## ๐ Description
The `sub` keyword kicks off the definition of a user defined subroutine. With these you can kinda-sorta extend yabasic with your own commands or functions โ main character energy, honestly. ๐
A subroutine accepts arguments (numbers or strings) and returns a number or a string. Although, real talk, you are **not** required to assign the returned value to a variable. Live your life.
The name of the subroutine comes right after the `sub` keyword. If that name (in the synopsis: `foo`) ends on a `$`, the subroutine should return a string (using the `return`-statement), otherwise it returns a number.
After the name, yabasic requires a pair of braces; inside those braces you can list your parameters, and values for them can (but don't have to) be included when you call the subroutine. If you skip one of those parameters on the call, it assumes the value zero (for numeric parameters) or the empty string (for string-parameters). But bestie, there's a special variable called `numparams` that tells you how many arguments *actually* got passed when the subroutine was called. Obsessed with that. โจ
Parameters of a subroutine are always local variables (go check the keyword `local` for more explanation).
From inside the subroutine you can bounce out at any time with the keyword `return`; and along with `return` you can specify the return value. Note that more than one `return` is allowed within a single subroutine.
Finally, the keyword `end sub` closes out the subroutine definition. And ngl, the definition of a subroutine doesn't have to appear in the program before the first call to that sub. She can show up whenever. ๐
## ๐ Note
> As braces have two uses in yabasic (i.e. for supplying arguments to a subroutine as well as to list the indices of an array), yabasic can not tell apart an array from a subroutine with the same name. Therefore you cannot define a subroutine with the same name as an array ! ๐จ
## ๐ Example
p=2 do if (is_prime(p)) print p p=p+1 loop
sub is_prime(a) local b for b=2 to sqrt(a) if (frac(a/b)=0) return false next b return true end sub
This example is *not* the recommended way to compute prime numbers. But it does give a nice demonstration of using a subroutine, so slay. ๐ธ
## ๐ See also
`local`, `static`, `peek`
---
## ๐ซ Name
`switch` ? select one of many alternatives depending on a value
## ๐ซ Synopsis
switch a case 1 case 2 ? end switch
?
switch a$ case "a" case "b" end switch
## ๐ซ Description
The `switch`-statement picks one of many codepaths depending on a numerical or string expression. Basically: it takes an expression (either numeric or string) and compares it against a series of values, each one wrapped up in a `case`-clause. If the expression equals the value given in a `case`-clause, the statements after it get executed. Periodt. ๐
The `default`-clause lets you specify commands that should run if **none** of the `case`-clauses match. Your safety net, bestie.
Note that many `case`-clauses might be clustered (e.g. `case "a":case "b":case "c"`). Or put another way: you need a `break`-statement at the end of a `case`-branch if you do not want to run straight into the next case. That's the fallthrough trap, don't get got. ๐
## ๐ซ Example
input "Please enter a single digit: " n switch n case 0:print "zero":break case 1:print "one":break case 2:print "two":break case 3:print "three":break case 4:print "four":break case 5:case 6: case 7:case 8:case 9 print "Much !":break default:print "Hey ! That was more than a single digit !" end switch
okay so bestie this example is literally turning one single digit into a word, and <pink>the way that</pink> cases 5 through 7 are all clustered together is lowkey iconic โ one shared body, no drama, no repetition ๐
## ๐ซถ See also
- <cyan>`switch`</cyan>, <cyan>`case`</cyan>, <cyan>`break`</cyan>
---
## ๐ Name
<rainbow>`system()`</rainbow> ? hand a statement over to your operating system and return its exitcode
## โจ Synopsis
ret=system("foo") system("bar")
## ๐ Description
`system` takes exactly one string argument, and that string is a command you want your operating system to go run. It hands back the <purple>exitcode</purple> of that command โ and that's it. Whatever the command printed? <red>gone.</red> its output (if any) is lost, no cap, it does not come back to you ๐ญ
## ๐ธ Example
print "Please enter the name of the file, that should be deleted." input f$ if (system("rm "+f$+" >/dev/null 2>&1")) then print "Error !" else print "okay." endif
heads up bestie, this program is <red>Unix-specific</red>: it uses the Unix command `rm` to remove a file ๐๏ธ
## ๐ซถ See also
- <cyan>`system$`</cyan>
---
## ๐ Name
<rainbow>`system$()`</rainbow> ? hand a statement over to your operating system and return its output
## โจ Synopsis
print system$("dir")
## ๐ Description
`system$` takes one string argument โ a command that your operating system can find and execute โ and gives you back <purple>the output of that command as one big string</purple>. one giant string, that's the whole vibe โจ
## ๐ธ Example
input "Please enter the name of a directory: " d$ print print "This is the contents of the '"+d$+"':" print system$("dir "+d$)
this one lists what's inside a directory using the `dir` command โ and honestly? `dir` is like the only program that's known under <cyan>Unix</cyan> *and* <cyan>Windows</cyan> at the same time, which is kind of a slay ๐
## ๐ซถ See also
- <cyan>`system`</cyan>, <cyan>`chomp`</cyan>
---
# ๐ฆ T ๐ฆ
- <cyan>`tan()`</cyan> ? return the tangent of its argument
- <cyan>`tell`</cyan> ? get the current position within an open file
- <cyan>`text`</cyan> ? write text into your graphic-window
- <cyan>`then`</cyan> ? tell the long from the short form of the if-statement
- <cyan>`time$`</cyan> ? return a string containing the current time
- <cyan>`to`</cyan> ? this keyword appears as part of other statements
- <cyan>`token()`</cyan> ? split a string into multiple strings
- <cyan>`triangle`</cyan> ? draw a triangle
- <cyan>`trim$()`</cyan> ? remove leading and trailing spaces from its argument
- <cyan>`true`</cyan> ? a constant with the value of 1
---
## ๐ Name
<rainbow>`tan()`</rainbow> ? return the tangent of its argument
## โจ Synopsis
foo=tan(bar)
## ๐ Description
`tan` computes the <purple>tangent</purple> of its argument โ and bestie, that argument should be in <hotpink>radians</hotpink>, just so you know ๐
## ๐ธ Example
for a=0 to 45 print tan(a*pi/180) next a
this just prints the tangent of every angle from <cyan>0</cyan> to <cyan>45</cyan> degrees. simple, clean, no notes ๐
## ๐ซถ See also
- <cyan>`atan`</cyan>, <cyan>`sin`</cyan>
---
## ๐ Name
<rainbow>`tell`</rainbow> ? get the current position within an open file
## โจ Synopsis
open #1,"foo" ? position=tell(#1)
## ๐ Description
`tell` wants the number of an open file as its argument, and it gives you back the <purple>position</purple> where the next read is gonna start โ counted in <hotpink>bytes</hotpink>, starting from the very beginning of the file ๐ง
## ๐ธ Example
open #1,"foo","w" print #1 "Hello World !" close #1
open #1,"foo" seek #1,0,"end" print tell(#1) close 1
okay so this example is *technically* (mis)using `tell` to get the size of the file ๐ the `seek` moves the file pointer all the way to the end, so when `tell` runs, it hands you the total length of the whole file. sneaky but it works, iykyk
## ๐ซถ See also
- <cyan>`tell`</cyan>, <cyan>`open`</cyan>
---
## ๐ Name
<rainbow>`text`</rainbow> ? write text into your graphic-window
## โจ Synopsis
text x,y,"foo" text x,y,"foo","lb" text x,y,"foo","cc","font" text x,y,"foo","font","rt"
## ๐ Description
`text` shows a text-string (that's the third argument) at a given position (the first two arguments) inside a window that's already open โจ
the <purple>font</purple> you want can optionally be given as either the fourth or the fifth argument (that's `"font"` up in the example). and here's the tea: a font set this way will <hotpink>also be used for any later `text` commands</hotpink>, as long as those don't specify a font of their own ๐
the fourth *or* fifth optional argument (that's `"lb"` in the example) sets the <purple>alignment</purple> of the text relative to that position. it's always exactly two characters long:
- the <cyan>first character</cyan> is the horizontal alignment, and it's either `l`, `r` or `c` โ for <green>left</green>, <green>right</green> or <green>center</green>
- the <cyan>second character</cyan> is the vertical alignment, and it's one of `t`, `b` or `c` โ for <green>top</green>, <green>bottom</green> or <green>center</green>
if you skip the alignment argument entirely, the default `"lb"` kicks in โ but heads up, that default can be changed with `poke "textalign","xx"` ๐
## ๐ธ Example
open window 500,200 clear screen data "lt","lc","lb","ct","cc","cb","rt","rc","rb" for a=1 to 9 read align$ print "Alignment: ",align$ line 50*a-15,100,50*a+15,100 line 50*a,85,50*a,115 text 50*a,100,"Test",align$ inkey$ next a
this draws <purple>nine crosses</purple> and writes the same text at each one, but it cycles through all nine possible alignment strings so you can literally *see* what each one does ๐
## ๐ซถ See also
- <cyan>`open window`</cyan>, <cyan>`peek`</cyan>, <cyan>`poke`</cyan>
---
## ๐ Name
<rainbow>`then`</rainbow> ? tell the long from the short form of the if-statement
## โจ Synopsis
if (a<b) then ? endif
## ๐ Description
`then` is part of the `if`-statement โ go peek at that one for the full lore. but here's the thing: <hotpink>not every</hotpink> `if`-statement needs the keyword `then` ๐
- if `then` <green>is</green> there, the `if`-clause can stretch over more than one line, and you <red>must</red> close it with the keyword `endif`
- if `then` is <red>not</red> there, the `if`-statement only runs to the end of that line โ and any `endif` you throw in would be an <red>error</red>
## ๐ธ Example
if (1<2) then print "Hello "; endif
if (2<3) print "world" if (2<1) print "!"
this example prints `Hello world`. note that <red>no exclamation mark (`!`) gets printed</red> โ which might lowkey surprise you, and it may get changed in future versions of `yabasic` ๐ญ
## ๐ซถ See also
- <cyan>`if`</cyan>
---
## ๐ Name
<rainbow>`time$`</rainbow> ? return a string containing the current time
## โจ Synopsis
print time$ print time$()
## ๐ Description
`time$` returns the current time in <purple>four fields separated by hyphens</purple> (`-`). the fields are:
- the current <cyan>hour</cyan>, in the range from <green>0</green> to <green>23</green>, padded with zeroes (like `00` or `04`) out to a length of two characters
- the number of <cyan>minutes</cyan>, padded with zeroes
- the number of <cyan>seconds</cyan>, padded with zeroes
- the number of <cyan>seconds</cyan> that have elapsed since the program was started. this value just keeps climbing as long as your program runs, so it's <hotpink>unbound</hotpink> and <red>not</red> padded with zeroes
at the time this documentation was written, `time$` returns `22-58-53-0` โญ and ngl, because the first three of those four fields have a fixed width, it's super easy to pull fields out with the usual string functions like `mid$` (and friends) ๐
## ๐ธ Example
print "Hello it is ",time$ print "An empty for-loop with ten million iterations takes "; for a=1 to 10000000:next a print "Now it is ",time$ print peek("secondsrunning")," seconds have passed."
this program benchmarks the `for`-loop, but it does <red>not</red> use the fourth field of the string `time$` gives back โ because that field <hotpink>wraps around every 60 seconds</hotpink> ๐ instead, it queries `peek "secondsrunning"` ๐ง
## ๐ซถ See also
- <cyan>`date`</cyan>
---
## ๐ Name
<rainbow>`to`</rainbow> ? this keyword appears as part of other statements
## โจ Synopsis
for a=1 to 100 step 2 ? next a
line x,y to a,b
## ๐ Description
the `to`-keyword serves <purple>two purposes</purple> (and bestie, they are not related at all, not even a little):
- inside `for`-statements, it sets the <cyan>upper bound</cyan> of the loop
- inside any graphical command (like `line`) that needs <hotpink>two points</hotpink> โ that's four numbers โ as arguments, a comma `,` can be swapped for the keyword `to`. so instead of `100,100,200,200` you can just write `100,100 to 200,200` in those commands โจ
## ๐ธ Example
Please see the command listed under "See also" for examples.
See also โจ
- `for`, `line`, `rectangle`
---
# ๐ Name
`token()` ? split a string into multiple strings
## ๐ Synopsis
dim w$(10) ? num=token(a$,w$()) num=token(a$,w$(),s$)
## ๐ฌ Description
okay bestie, `token()` is the "chop my string into lil pieces" icon ๐
she takes a string (the text you wanna split up), a <pink>reference</pink> to a string-array (which is where the resulting strings โ the *tokens* โ are gonna live), and an optional string (the set of characters you wanna split on, aka the *delimiters*).
what `token()` does is look at her first argument like it's a whole list of tokens that got separated by delimiters, and she drops that list of tokens into the array-reference you handed her. and here's the cute part: the array you pass as a reference (`w$()` in the synopsis) gets **resized accordingly**, so you literally never have to figure out how many tokens there are in advance. no math, no vibes-based guessing. ๐ซถ
> one thing though โ the element at position zero (i.e. `w$(0)`) is **not used**. she said not today.
normally (like, if you just skip the third argument entirely) the function treats space or tab as the delimiters between tokens. but if you do supply that third argument, you can split at any single one of the characters inside that string. for example: pass `":;"` as the third argument and colon (`:`) or semicolon (`;`) will delimit tokens. mix and match, she doesn't mind ๐
also, important, `<cyan>token</cyan>` will **never** produce empty tokens, even if two or more separators follow each other in a row. if that behaviour isn't your thing, go check out the closely related `split`-function instead. lowkey they're two different girls: the `token`-function is focused on the **tokens**, not the separators โ whereas the `split`-function is out here focused on the **separators**. different eras, same party ๐
the second argument is a reference to a string-array, and that's where the tokens get stored; this array will be expanded (or shrunk) as necessary so there's room for all of them. the first argument is finally the text that will be split into tokens. and `token()` returns the number of tokens that have been found. periodt. โจ
please peek the examples below for some hints on exactly how `token()` behaves and how it differs from `split()`:
## ๐ธ Example
print "This program will help you to understand, how the" print "token()-function exactly works and how it behaves" print "in certain special cases." print print "Please enter a line containing tokens separated" print "by either '=' or '-'" dim t$(10) do print input "Please enter a line: " l$ num=token(l$,t$(),"=-") print num," Tokens: "; for a=1 to num if (t$(a)="") then print "(EMPTY)"; else print t$(a); endif if (a<num) print ","; next a print loop
This program prints the following output:
Please enter a line: a 1 Tokens: a
Please enter a line: 0 Tokens:
Please enter a line: ab 1 Tokens: ab
Please enter a line: a=b 2 Tokens: a,b
Please enter a line: a- 1 Tokens: a
Please enter a line: a-= 1 Tokens: a
Please enter a line: =a- 1 Tokens: a
Please enter a line: a=-b 2 Tokens: a,b
Please enter a line: a--b- 2 Tokens: a,b
Please enter a line: -a==b-c== 3 Tokens: a,b,c
## ๐ See also
- `split`
---
# ๐ Name
`triangle` ? draw a triangle
## ๐ Synopsis
open window 100,100 triangle 100,100,50,50,100,50 fill triangle 50,100,100,50,200,200 clear fill triangle 20,20,10,10,200,200
## ๐ฌ Description
the `triangle`-command draws a triangle, bestie, and she needs **6 parameters**: the *x*- and *y*-coordinates of the three points that make up the triangle. that's it, that's the shape. ๐บ
with the optional keywords `clear` and `fill` (which can both show up, and in any order you want) the triangle can be cleared and filled respectively. slay.
## ๐ธ Example
open window 200,200 do phi=phi+0.2 i=i+2 color mod(i,255),mod(85+2*i,255),mod(170+3*i,255) dx=100*sin(phi):dy=20*cos(phi) 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) sleep 0.1 loop
This example draws a colored triangles until you get exhausted. ๐ญ๐
## ๐ See also
- `open window`, `open printer`, `line`, `circle`, `rectangle`
---
# ๐ Name
`trim$()` ? remove leading and trailing spaces from its argument
## ๐ Synopsis
a$=trim$(b$)
## ๐ฌ Description
the `trim$`-function removes **all** whitespace from the left end and from the right end of a string and returns the result. calling `trim$` is equivalent to calling `rtrim$(ltrim$())`. no cap, that's literally the same thing. โจ
## ๐ธ Example
do input "Continue ? Please answer yes or no: " a$ a$=lower$(trim$(a$)) if (len(a$)>0 and a$=left$("no",len(a$)) exit loop
This example asks for an answer (yes or no) and removes spaces with `trim$` to make the comparison with the string `"no"` more bulletproof. ๐
## ๐ See also
- `ltrim$`, `rtrim$`
---
# ๐ Name
`true` ? a constant with the value of 1
## ๐ Synopsis
okay=true
## ๐ฌ Description
the constant `true` can be assigned to variables which will later appear in conditions (e.g. an `if`-statement.
`true` may also be written as `TRUE` or even `TrUe`. she does not care about your capitalization era, bestie. ๐
## ๐ธ Example
input "Please enter a string of all upper letters: " a$ if (is_upper(a$)) print "Okay"
sub is_upper(a$) if (a$=upper$(a$)) return true return false end sub
## ๐ See also
- `false`
---
# ๐ U
- `until` ? end a repeat-loop
- `upper$()` ? convert a string to upper case
- `using` ? Specify the format for printing a number
---
# ๐ Name
`until` ? end a repeat-loop
## ๐ Synopsis
repeat ? until (?)
## ๐ฌ Description
the `until`-keyword ends a loop, which has been introduced by the `repeat`-keyword. `until` requires a condition in braces (or an expression, see here for details) as an argument; the loop will continue **until** this condition evaluates to true. that's the whole vibe check. ๐
## ๐ธ Example
c=1 s=1 repeat l=c s=-(s+sig(s)) c=c+1/s print c until(abs(l-c)<0.000001)
This program calculates the sequence `1/1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+ ?` ; please let me know, if you know against which value this converges. ๐ญ
## ๐ See also
- `repeat`
---
# ๐ Name
`upper$()` ? convert a string to upper case
## ๐ Synopsis
u$=upper$(a$)
## ๐ฌ Description
the `upper$`-function accepts a single string argument and converts it to all upper case. simple. iconic. LOUD. ๐ฃ
## ๐ธ Example
line input "Please enter a sentence without the letter 'e': " l$ p=instr(upper$(l$),"E") if (p) then l$=lower$(l$) mid$(l$,p,1)="E" print "Hey, you are wrong, see here!" print l$ else print "Thanks." endif
This program asks for a sentence and marks the first (if any) occurrence of the letter `'e'` by converting it to upper case (in contrast to the rest of the sentence, which is converted to lower case). ๐ฆ
## ๐ See also
- `lower$`
---
# ๐ Name
`using` ? Specify the format for printing a number
## ๐ Synopsis
print a using "##.###" print a using("##.###",",.")
## ๐ฌ Description
the `using`-keyword may appear as part of the `print`-statement and specifies the format (e.g. the number of digits before and after the decimal dot), which should be used to print the number. ๐
the possible values for the format argument (`"##.###"` in the synopsis above) are described within the entry for the `str$`-function; especially the second line in the synopsis (`print a using("##.###",",.")`) will become clear after referring to `str$`. in fact the `using` clause is closely related to the `str$`-function; the former can always be rewritten using the latter; i.e. `print foo using bar$` is always equivalent to `print str$(foo,bar$)`. therefore you should check out `str$` to learn more. ๐ซถ
## ๐ธ Example
for a=1 to 10 print sqrt(ran(10000*a)) using "#########.#####" next a
This example prints a column of square roots of random number, nicely aligned at the decimal dot. โจ
## ๐ See also
- `print`, `str$`
---
# ๐ V
- `val()` ? converts a string to a number
---
# ๐ Name
`val()` ? converts a string to a number
## ๐ Synopsis
x=val(x$)
## ๐ฌ Description
okay bestie, the `val`-function does a little vibe check on the start of its string argument, and if that start forms a floating point number it just hands you back that number, no cap. so the string **has** to start with digits (only whitespace in front is allowed, that's the whole rule), otherwise the `val`-function returns zero. periodt. โจ
## โจ Example โจ
input "Please enter a length, either in inches (in) or centimeters (cm) " l$ if (right$(l$,2)="in") then l=val(l$)*2.51 else l=val(l$) print "You have entered ",l,"cm."
so this one asks you for a length and then checks whether you specified it in inches or centimeters ๐ the length gets converted to centimeters, and that's literally it.
## ๐ See also ๐
- `str$`
---
# ๐ W ๐
- **`wait`** โ pause, sleep, wait for the specified number of seconds
- **`wend`** โ end a while-loop
- **`while`** โ start a while-loop
- **`window origin`** โ move the origin of a window
## โจ Name โจ
`wait` โ pause, sleep, wait for the specified number of seconds
## ๐ Synopsis ๐
wait 4
## ๐ธ Description ๐ธ
the `wait`-command is giving "many names, one queen" energy ๐
you can write `pause`, `sleep` or `wait` interchangeably, and no matter which one you pick, yabasic does **exactly** the same thing, fr fr.
so like, go read the entry for the `pause`-function for the actual info, because that's where the tea is โ
---
## โจ Name โจ
`wend` โ end a while-loop
## ๐ Synopsis ๐
while(a<b) ? wend
## ๐ธ Description ๐ธ
the `wend`-keyword marks the end of a while-loop, bestie. it's the "and that's the end of that chapter" of the loop ๐ฆ head over to the `while`-keyword for the full story.
`wend` can also be written as `end while` or even `end-while`, iykyk.
## โจ Example โจ
line input "Please enter a sentence: " a$ p=instr(a$,"e") while(p) mid$(a$,p,1)="E" p=instr(a$,"e") wend print a$
this one reads a sentence and converts **every** occurrence of the letter `e` into uppercase (`E`). iconic behavior honestly ๐
## ๐ See also ๐
- `while` (which is just the following entry).
---
## โจ Name โจ
`while` โ start a while-loop
## ๐ Synopsis ๐
while(?) ? wend
## ๐ธ Description ๐ธ
the `while`-keyword starts a while-loop, which is just a loop that keeps running as long as the condition (the one you put in braces right after the keyword `while`) evaluates to true. main character energy ๐ฅ
and listen, important caveat: the body of such a while-loop **will not be executed at all** if the condition following the `while`-keyword isn't true to begin with. like, zero times. not even once. ๐
if you wanna dip out of the loop early, you can use the `break`-statement.
## โจ Example โจ
open #1,"foo" while(!eof(1)) line input #1 a$ print a$ wend
this program reads the file `foo` and prints it line by line, super clean ๐ธ
## ๐ See also ๐
- `until`, `break`, `wend`, `do`
---
## โจ Name โจ
`origin` โ move the origin of a window
## ๐ Synopsis ๐
open window 200,200 origin "cc"
## ๐ธ Description ๐ธ
the `origin`-command applies to graphic windows and moves the origin of the coordinate system to one of nine points within the window โจ normally the origin lives in the upper left corner of the window, but sometimes that's inconvenient, and moving the origin can save you from subtracting a constant offset from all of your coordinates. it's giving "work smarter not harder" ๐ซถ
but you can't just yeet the origin anywhere you want โ in horizontal position there are only three positions: left, center and right, which are decoded by the letters `l`, `c` and `r`. in vertical position the allowed positions are top, center and bottom, encoded by the letters `t`, `c` and `b`. put the letters together and you get a string, which might be passed as an argument to the command, e.g. `"cc"` or `"rt"`.
## โจ Example โจ
100,100
open window 200,200 window origin "cc" circle 0,0,60
this example draws a circle, centered at the center of the window ๐ฏ
## ๐ See also ๐
- `open window`
---
# โญ X โญ
- **`xor()`** โ compute the exclusive or
## โจ Name โจ
`xor()` โ compute the exclusive or
## ๐ Synopsis ๐
x=xor(a,b)
## ๐ธ Description ๐ธ
`xor` computes the bitwise exclusive or of its two numeric arguments ๐ง to understand the result, you should view both arguments as binary numbers (i.e. a series of `0` and `1`); a bit of the result will then be `1` if **exactly one** argument has a `1` and the other has a `0` at this position in their binary representation. it's the "one of you, not both, not neither" of bits ๐
> heads up bestie: both arguments are **silently converted to integer values**, and negative numbers have their own binary representation and may lead to unexpected results when passed to `and`. no cap, be careful ๐
## โจ Example โจ
print xor(7,4)
this will print `3`. this result is obvious if you note that the binary representation of `7` and `4` are `111` and `100` respectively; this will yield `011` in binary representation or `2` as decimal. ๐ญ
the `eor`-function is the same as the `xor` function; both are synonymous; however they each have their own description, so you may check out the entry of `eor` for a slightly different view. same vibe, different font โจ
## ๐ See also ๐
- `and`, `or`, `eor`, `not`
---
# ๐ฅ Special characters ๐ฅ
- **`#`** โ either a comment or a marker for a file-number
- **`//`** โ starts a comment
- **`@`** โ synonymous to `at`
- **`:`** โ separate commands from each other
- **`;`** โ suppress the implicit newline after a print-statement
- **`**` or `^`** โ raise its first argument to the power of its second
## โจ Name โจ
`#` โ either a comment or a marker for a file-number
## ๐ Synopsis ๐
This is a comment, but the line below not !
open #1,"foo"
## ๐ธ Description ๐ธ
the hash (`'#'`) has two totally unrelated uses, bestie โ it's living a double life ๐
- a hash might appear in commands related with file-io. yabasic uses simple numbers to refer to open files (within `input`, `print`, `peek` or `eof`). in those commands the hash may precede the number, which specifies the file. please see those commands for further information and examples; the rest of this entry is about the second use (as a comment).
- as the very first character within a line, a hash introduces comments (similar to `rem`).
`'#'` as a comment is common in most scripting languages and has a special use under Unix: if the very first line of any Unix-program begins with the character sequence `'#!'` ("she-bang", no spaces allowed), the rest of the line is taken as the program that should be used to execute the script. i.e. if your yabasic-program starts with `'#!/usr/local/bin/yabasic'`, the program `/usr/local/bin/yabasic` will be invoked to execute the rest of the program. and as a remark for windows-users: this mechanism ensures that yabasic will be invoked to execute your program; the ending of the file (e.g. `.yab`) will be ignored by Unix. ๐
## โจ Example โจ
This line is a valid comment
print "Hello " : # But this is a syntax error, because print "World!" : # the hash is not the first character !
> note that this example will produce a **syntax error** and is **not** a valid program! ๐ญ don't do this one at home.
## ๐ See also ๐
- `input`, `print`, `peek` or `eof`, `//`, `rem`
---
## โจ Name โจ
`//` โ starts a comment
## ๐ Synopsis ๐
// This is a comment !
## ๐ธ Description ๐ธ
the double-slash (`'//'`) is (besides `REM` and `'#'`) the third way to start a comment ๐ and honestly? `'//'` is the latest and greatest in the field of commenting, and it allows yabasic to catch up with such cool languages like C++ and Java. it ate, no crumbs. ๐
## โจ Example โจ
// Another comment. print "Hello world !" // Another comment
unlike the example given for `'#'`, this example is syntactically correct and will **not** produce an error. see? we're thriving ๐ฆ
## ๐ See also ๐
- `#`, `rem`
---
## โจ Name โจ
`@` โ synonymous to `at`
## ๐ Synopsis ๐
clear screen ? print @(a,b)
## ๐ธ Description ๐ธ
since `'@'` is simply a synonym for `at`, please see `at` for further information ๐
short and sweet, we love a minimal queen.
## ๐ See also ๐
- `at`
---
## โจ Name โจ
`:` โ separate commands from each other
## ๐ Synopsis ๐
print "Hello ":print "World"
## ๐ธ Description ๐ธ
the colon (`':'`) separates multiple commands on a single line โจ
the colon and the newline-character have mostly the same effect, only that the latter, well, starts a new line too ๐ the only other difference is their effect within the (so-called) short `if`, which is an if-statement **without** the keyword `then`. please see the entry for `if` for more details.
## โจ Example โจ
if (a<10) print "Hello ":print "World !"
this example demonstrates the difference between colon and newline as described above ๐ฏ
## ๐ See also ๐
- `if`
---
## โจ Name โจ
`;` โ suppress the implicit newline after a print-statement
## โจ Synopsis โจ
print "foo",bar;
## ๐
Description ๐
okay bestie so the semicolon (`;`) has ONE job and one job only: it can show up at the **last** position inside a `print`-statement. That's it. Nowhere else. And what does it do? It suppresses the implicit newline that yabasic normally tacks on after every single `print`-statement. ๐
Put another way: normally every `print`-statement's output gets its own little line, all by itself, main character energy. But if you want the output of a bunch of `print`-statements to all pile onto **one single line** together? End the `print`-statement with a semicolon. Periodt. โจ
## ๐ Example ๐
print "Hello ";:print "World !"
This example prints `Hello World !` in a single line. slay ๐
## ๐ See also ๐
- `print`
---
## โญ Name โญ
`**` or `^` ? raise its first argument to the power of its second ๐ฅ
## โจ Synopsis โจ
print 2**b print 3^4
## ๐
Description ๐
`**` (or `^`, which is literally an exact synonym, no cap) is the arithmetic operator of **exponentiation**. It needs one number to its left and a second one to its right, and then `**` raises the first argument to the power of the second and hands you back the result. ๐
But here's the tea ๐ซ: the result only gets computed if it yields a **real** number (as opposed to a complex number). Which means the power **cannot** be computed if the first argument is negative and the second one is fractional. On the other hand, the second argument totally can be fractional if the first one is positive โ which means `**` can be used to compute arbitrary roots, like, `x**0.5` computes the square root of `x`. iconic. ๐
## ๐ Example ๐
print 2**0.5
## ๐ See also ๐
- `sqrt`
---
## ๐ฎ Reserved Words ๐ฎ
Here's the full list of every reserved word in yabasic. Please please PLEASE make sure you don't try to use one of them as the name of a variable or subroutine, bestie. ๐ Or, the other way around: if you get some mysterious error from yabasic and you're just sitting there like ??? and can't figure out why โ you might be using one of the reserved words below without even knowing it. it's giving sneaky ๐
Anyway, here's the list:
ABS ACOS AND ARRAYDIM ARRAYDIMENSION ARRAYSIZE AS ASC ASIN AT ATAN BEEP BELL BIN$ BIND BITBLIT BITBLIT$ BITBLT BITBLT$ BOX BREAK CASE CHR$ CIRCLE CLEAR CLOSE COLOR COLOUR COMPILE CONTINUE COS CURVE DATA DATE$ DEC DEFAULT DIM DO DOT ELSE ELSEIF ELSIF END ENDIF EOF EOR ERROR EXECUTE EXECUTE$ EXIT EXP EXPORT FI FILL FILLED FOR FRAC GETBIT$ GETSCREEN$ GLOB GOSUB GOTO HEX$ IF INKEY$ INPUT INSTR INT INTERRUPT LABEL LEFT$ LEN LET LINE LOCAL LOG LOOP LOWER$ LTRIM$ MAX MID$ MIN MOD MOUSEB MOUSEBUTTON MOUSEMOD MOUSEMODIFIER MOUSEX MOUSEY NEW NEXT NOT NUMPARAM ON OPEN OR ORIGIN PAUSE PEEK PEEK$ POKE PRINT PRINTER PUTBIT PUTSCREEN RAN READ READING RECT RECTANGLE REDIM REPEAT RESTORE RETURN REVERSE RIGHT$ RINSTR RTRIM$ SCREEN SEEK SIG SIN SLEEP SPLIT SPLIT$ SQR SQRT STATIC STEP STR$ SUB SUBROUTINE SWITCH SYSTEM SYSTEM$ TAN TELL TEXT THEN TIME$ TO TOKEN TOKEN$ TRIANGLE TRIM$ UNTIL UPPER$ USING VAL WAIT WEND WHILE WINDOW WRITING XOR
Please see here for explanations on how to use these words in yabasic. ๐ซถ
---
# ๐ธ Chapter 8. Some general concepts and terms ๐ธ
- Logical shortcuts
- Conditions and expressions
- References on arrays
- Specifying Filenames under Windows
- Escape-sequences
- Creating a standalone program from your yabasic-program
This chapter presents some general concepts and terms which honestly deserve a description all on their own, but aren't really tied to a single command or function in yabasic. Most of these topics don't lend themselves to being read alone โ think of them more like background material you'd read (or skim, no judgement ๐
) when an entry from the alphabetical list of commands points you here.
## ๐ง Logical shortcuts ๐ง
Logical shortcuts are **not** some special language construct, and there's no keyword for them. They're just a way of evaluating logical expressions. Logical expressions (i.e. a series of conditions or comparisons joined by `and` or `or`) only get evaluated until the final result of the expression can be determined. Example time:
if (a<>0 and b/a>2) print "b is at least twice as big as a"
The logical expression `a<>0 and b/a>2` is made of two comparisons, and **both** of them have to be true if the `print` statement should actually run. Now, if the first comparison (`a<>0`) is false, the whole logical expression can never be true โ so the second comparison (`b/a>2`) doesn't need to be evaluated at all. ๐ฆ
This is exactly how yabasic behaves: the evaluation of a composed logical expression is terminated immediately, as soon as the final result can be deduced from the already-evaluated parts.
In practice, this has the following consequences:
- If two or more comparisons are joined with `and` and one comparison results in false, the logical expression is evaluated no further and the overall result is false.
- If two or more comparisons are joined with `or` and one comparison results in true, the logical expression is evaluated no further and the result is true.
"Nice, but what's this good for??" I hear you say. ๐ Well bestie, just have another look at the example, especially that second comparison (`b/a>2`) โ dividing `b` by `a` is potentially hazardous: if `a` equals zero, the expression will cause an error and your program will **terminate**. ๐ญ To avoid this, the first part of the comparison (`a<>0`) checks whether the second one can be evaluated without risk. This pre-checking is the most common usage and the primary motivation for logical shortcuts (and honestly the reason why most programming languages implement them). ๐
## ๐ Conditions and expressions ๐
Okay so bottom line: there is **no** difference or distinction between conditions and expressions, at least as far as yabasic is concerned. So you can assign the result of comparisons to variables, or use an arithmetic expression or a simple variable inside a condition (like, inside an `if`-statement). All the constructs in the example below are totally valid: โจ
input "Please enter a number between 1 and 10: " a
rem Assigning the result of a comparison to a variable okay=a>=1 and a<=10
rem Use a variable within an if-statement if (not okay) error "Wrong, wrong !"
So conditions and expressions are really the same thing (at least as long as yabasic is concerned). Therefore the terms **conditions** and **expression** can really be used interchangeably โ at least in theory. In reality, the term *condition* gets used in connection with `if` or `while`, whereas the term *expression* tends to show up more often in an arithmetic context. ๐
## ๐ซถ References on arrays ๐ซถ
References on arrays are the **only** way to refer to an array as a whole, and to pass it to subroutines or functions like `arraydim` or `arraysize`. Whereas (for example) `a(2)` designates the second element of the array `a`, `a()` (with empty braces) refers to the array `a` itself. `a()` is called an **array reference**. ๐
If you pass an array reference to one of your own subroutines, you need to be aware that the subroutine will be able to **modify** the array you passed in. So passing an array reference does **not** create a copy of the array โ and this has some interesting consequences:
- **Speed and space:** creating a copy of an array would be a time (and resource) consuming operation; passing just a reference is cheap and fast. โก
- **Returning many values:** a subroutine that wants to give back more than one value may require an array reference among its arguments and then store its many return values within this array. This is the only way to return more than one value from a subroutine. ๐
## ๐ช Specifying Filenames under Windows ๐ช
As you probably know, Windows uses the character `\` to separate the directories within a pathname; an example would be `C:\yabasic\yabasic.exe` (the usual location of the yabasic executable). However, that very same character `\` is used to construct escape sequences โ not only in yabasic, but in most other programming languages too. ๐ฌ
Therefore the string `"C:\t.dat"` does **not** specify the file `t.dat` within the directory `C:`; this is because the sequence `\t` is translated into the tab-character. To specify this filename, you need to use the string `"C:\\t.dat"` (note the double slash `\\`). ๐
## ๐ง Escape-sequences ๐ง
Escape-sequences are the preferred way of specifying 'special' characters. They're introduced by the `\`-character and followed by one of a few regular letters, e.g. `\n` or `\r` (see the table below).
<pink>okay bestie</pink>, so escape sequences. They can show up <hotpink>anywhere</hotpink> inside any string, at any position, and here's the tea: they get swapped out at **parsetime**, not runtime. Like, the *second* yabasic clocks the string, it already replaced the escape with the matching special character. Which is why `len("\a")` returns `1` โ because yabasic already turned `"\a"` into the one special character it stands for <purple>before</purple> your program even starts running. ๐ซถ
### ๐ Table 8.1. Escape sequences ๐
- **`\n`** โ newline
- **`\t`** โ tabulator
- **`\v`** โ vertical tabulator
- **`\b`** โ backspace
- **`\r`** โ carriage return
- **`\f`** โ formfeed
- **`\a`** โ alert (i.e. a beeping sound)
- **`\\`** โ backslash
- **`\'`** โ single quote
- **`\"`** โ double quote
- **`\xHEX`** โ `chr$(HEX)` (see below)
<cyan>ngl</cyan>, the `\xHEX` form is lowkey iconic: it lets you encode <rainbow>arbitrary characters</rainbow> as long as you know where they sit (as a hex-number) in the ascii-charset. Example: `\x012` gets transformed into the character `chr$(18)` (or `chr$(dec("12",16))`). Heads up though โ `\x` wants a **hexa-decimal** number, and the hexa-decimal string `"12"` corresponds to the decimal number `18`. ๐
---
# ๐ Creating a standalone program from your yabasic-program ๐
- Creating a standalone-program from the command line
- Creating a standalone-program from within your program
- Downsides of creating a standalone program
- See also
## ๐ธ Note ๐ธ
The bind-feature, which is described below, is at an <peach>experimental</peach> stage right now. It works (at least for me !) under Windows and Linux, but I cannot even promise it for other variants of Unix. However, if it does not work for your Unix, I will at least try to make it work, if you give me sufficient information of your system. <lavender>(so like, be a good bestie and send the deets ๐)</lavender>
Sometimes you may want to give one of your yabasic-programs to other people. However, what if those other people do not have yabasic installed ? In that case you may create a standalone-program from your yabasic-program, i.e. an executable, that may be executed on its own, standalone, even (and especially !) on computers, that do not have yabasic installed. Having created a standalone program, you may pass it around like any other program (e.g. one written in C) and you can be sure that your program will execute right away. <mint>fr fr, it just runs.</mint> โจ
Such a standalone-program is simply created by copying the full yabasic-interpreter and your yabasic-program (plus all the libraries it does import) together into a single, new program, whose name might be chosen at will (under windows of course it should have the ending `.exe`). If you decide to create a standalone-program, there are three bits in yabasic, that you may use:
- The `bind`-command, which does the actual job of creating the standalone program from the yabasic-interpreter and your program.
- The command-line Option `--bind` (see options), which does the same from the command-line.
- The special `peek("isbound")`, which may be used to check, if the yabasic-program containing this peek is bound to the interpreter as part of a standalone program.
With these bits you know enough to create a standalone-program. Actually there are two ways to do this: on the command line and from within your program. ๐
## ๐ Creating a standalone-program from the command line ๐
Let's say you have the following very simple program within the file `foo.yab`:
print "Hello World !"
Normally you would start this yabasic-program by typing `yabasic foo.yab` and as a result the string `Hello World !` would appear on your screen. However, to create a standalone-program from `foo.yab` you would type:
yabasic -bind foo.exe foo.yab
This command does <hotpink>not</hotpink> execute your program `foo.yab` but rather create a standalone-program `foo.exe`. Note: under Unix you would probably name the standalone program `foo` or such, omitting the windows-specific ending `.exe`.
Yabasic will confirm by printing something like: `---Info: Successfully bound 'yabasic' and 'foo.yab' into 'foo.exe'.`
After that you will find a program `foo.exe` (which must be made executable with the `chmod`-command under Unix first). Now, executing this program `foo.exe` (or `foo` under Unix) will produce the output `Hello World !`. ๐
This newly created program `foo.exe` might be passed around to anyone, even if he does not have yabasic installed. <green>slay, portable.</green>
## ๐ฆ Creating a standalone-program from within your program ๐ฆ
It is possible to write a yabasic-program, that binds itself to the yabasic-interpreter. Here is an example:
if (!peek("isbound")) then bind "foo" print "Successfully created the standalone executable 'foo' !" exit endif
print "Hello World !"
If you run this program (which may be saved in the file `foo.yab`) via `yabasic foo.yab`, the `peek("isbound")` in the first line will check, if the program is already part of a standalone-program. If not (i.e. if the yabasic-interpreter and the yabasic-program are separate files) the `bind`-command will create a standalone program `foo` containing both. As a result you would see the output `Successfully created the standalone executable 'foo' !`. Note: Under Windows you would probably choose the filename `foo.exe`.
Now, if you run this standalone executable `foo` (or `foo.exe`), the very same yabasic-program that is shown above will be executed again. However, this time the `peek("isbound")` will return `TRUE` and therefore the condition of the `if`-statement is false and the three lines after `then` are not executed. Rather the last `print`-statement will run, and you will see the output `Hello World !`. <purple>the way that program justโฆ re-parents itself?? iconic.</purple> ๐ญ
That way a yabasic-program may turn itself into a standalone-program.
## ๐ Downsides of creating a standalone program ๐
Now, before you go out and turn all your yabasic-programs into standalone programs, please take a second to consider the downsides of doing so:
- The new standalone program will be at least as big as the interpreter itself, so you need to pass a few hundred kilobytes around, just to save people from having to install yabasic themselves.
- There is no easy way to extract your yabasic-program from within the standalone program: If you ever want to change it, you need to have it around separately.
- If a new version of yabasic becomes available, again you need to recreate all of your standalone programs to take advantage of bugfixes and improvements.
So, being able to create a standalone program is certainly a good thing, but certainly not a silver bullet. <yellow>vibe check: passed, but with caveats.</yellow>
## ๐ See also ๐
The `bind`-command, the `peek`-function and the command line options.
---
# โญ Chapter 9. A few example programs โญ
- A very simple program
- The demo of yabasic
## ๐ง A very simple program ๐ง
The program below is a very simple program:
repeat input "Please enter the first number, to add " a input "Please enter the second number, to add " b print a+b until(a=0 and b=0)
This program requests two numbers, which it than adds. The process is repeated until you enter zero (or nothing) twice. <mint>a lil calculator bestie, obsessed.</mint> ๐
## ๐ The demo of yabasic ๐
The listing below is the demo of yabasic. Note, that parts of this demo have been written before some of the more advanced features (e.g subroutines) of yabasic have been implemented. So please do not take this as a particular good example of yabasic-code. <lavender>(author said it, not me ๐)</lavender>
// // This program demos yabasic //
// Check, if screen is large enough clear screen sw=peek("screenwidth"):sh=peek("screenheight") if (sw<78 or sh<24) then print print " Sorry, but your screen is to small to run this demo !" print end endif sw=78:sh=24
// Initialize everything restore mmdata read mmnum:dim mmtext$(mmnum) for a=1 to mmnum:read mmtext$(a):next a
\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.
---
<pink>and THAT, bestie, is the whole demo listing, all the way down to the `mmdata` block and the copyright chapter โ every `label`, every `gosub`, every `data` line, kept exactly as it is, no notes skipped. ๐</pink>
# ๐ AUTHOR ๐
<purple>Marc Ihm</purple>, with the input and suggestions from many others. ๐ซถ <lavender>(a whole crowd of besties helped, fr fr)</lavender>
# ๐ฆ SEE ALSO ๐ฆ
- <cyan>`yabasic.htm`</cyan> โ for the hyperlinked version of the text that is presented above. โจ
- <cyan>`www.yabasic.de`</cyan> โ for further information on yabasic. ๐
# ๐ BUGS ๐
<pink>Still some.</pink> ๐ญ <lavender>(iconic honestly โ no cap, she's keeping it real)</lavender>
---
<purple>and that's a wrap on the whole page, girlies โ the little footer stamp at the very bottom of this manual page reads <cyan>`yabasic(1)`</cyan>, so that's your source and version tag right there, slay. ๐ธ๐</purple>
๐ฆ where this page comes from
- alpine 3.24: yabasic-doc 2.91.4-r1 ยท MIT
- debian bookworm: yabasic 1:2.90.3-1 ยท MIT
- debian trixie: yabasic 1:2.91.1-1 ยท MIT
- nixos 26.05: yabasic 2.91.4
- nixpkgs unstable: yabasic 2.92.1
- ubuntu jammy: yabasic 1:2.90.2-1 ยท MIT
- ubuntu noble: yabasic 1:2.90.3-1 ยท MIT
- ubuntu questing: yabasic 1:2.91.4-1
- ubuntu resolute: yabasic 1:2.91.4-1build1 ยท MIT
- ubuntu stonking: yabasic 1:2.91.4-1build1 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms