Category:FOCAL: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(11 intermediate revisions by 3 users not shown)
Line 1:
{{stub}}{{language|FOCAL}}
FOCAL, (which iseither allegedly shortstands for "Formulating'''Fo'''rmula '''Cal'''culator or '''F'''ormulating On'''O'''n-line Calculations'''C'''alculations in Algebraic'''A'''lgebraic Language"'''L'''anguage), is an imperative, interpreted programming language similar to JOSS. It was first introduced in 1968, and FOCAL-69 was widely used on the PDP-8 minicomputer from Digital Equipment Corporation.
 
FOCAL, which is allegedly short for "Formulating On-line Calculations in Algebraic Language", is an imperative, interpreted programming language similar to JOSS. It was first introduced in 1968, and FOCAL-69 was widely used on the PDP-8 minicomputer from Digital Equipment Corporation.
 
Like JOSS and BASIC, FOCAL was not intended to be used for developing large applications; the manual said it was "designed to help scientists, engineers, and students solve numerical problems." The design goals thus emphasize simplicity and accessibility.
 
FOCAL could also be used satisfactorily on quite small computers: its interpreter runs on a PDP-8 with only 4k words (6k bytes) of storage and still leaves some space for user programs. During startup, the FOCAL interpreter asks if the built-in sine, cosine, log, exp, and arctangent functions should be kept in memory. If the user answers NO to one (or both) of these questions, memory occupied by these functions is freed and can be used for FOCAL programs instead.
 
==FOCAL commands==
 
To conserve memory, FOCAL commands are often abbreviated by using their first character only, e.g. "T" for TYPE or "I" for IF.
 
The first two letters of variable names must be unique. E.g. variables named TEST1 and TEST2 would both refer to the same variable "TE" as far as FOCAL is concerned.
 
Function names start with the letter F, e.g. FSIN() and FCOS(). Appendix D of the FOCAL manual shows how to compute trigonometric functions that are not directly available.
 
FOCAL always computes a maximum of six significant digits, although more digits can be displayed depending on the output format: "%x.y", x=total digits, y=digits after decimal point.
 
A program is started with the go (or simply "g") command.
 
{| class="wikitable"
! Command !! Abbreviation !! Function
|-
| ASK || A || Input one or more variables
|-
| COMMENT || C || Start a comment line
|-
| DO || D || Jump to a single line or code block, then return
|-
| ERASE || E || Erase program or variables
|-
| FOR || F || Run the following command in a loop
|-
| GO/GOTO || G || Start a program, optionally at a certain line
|-
| IF || I || IF statement, go to the 1st/2nd/3rd line given, depending on whether the value is <0, ==0, or >0
|-
| LOCATIONS || L || Show FOCAL memory usage
|-
| QUIT || Q || Stop a running program
|-
| RETURN || R || Return from a DO subroutine call
|-
| SET || S || Set a variable, e.g. "SET A=1"
|-
| TYPE || T || Print a variable/expression/string. A "!" character prints a line feed and a "%" sets the number output format. "T $" prints a list of all variables and their values.
|-
| WRITE || W || List the whole or parts of a program. The whole program listing always starts with the (commented out) FOCAL version number, e.g. "FOCAL,1969".
|-
|}
 
==Running FOCAL in a PDP emulator==
 
There is a tiny [https://jeelabs.org/2016/09/tfoc---pdp-8-in-256-lines-of-c/ PDP-8 emulator in C] which also includes a binary dump of the FOCAL-69 binarypunched paper tape image. Note that programs will run much faster on this emulator than on a real PDP-8.
 
To exit the emulator, use Ctrl-Backslash. The emulator will quit and dump the RAM zero page in octal.
Line 15 ⟶ 57:
Compiling and running the emulator on Linux (should also work on macOS):
<pre>
$ git clone https://gitgithub.jeelabs.orgcom/jcwJohnOH/embello/
$ cd embello/explore/1638-pdp8
$ make
Line 36 ⟶ 78:
HELLO WORLD FROM FOCAL
</pre>
 
==Vector graphics support==
 
FOCAL-11 on a [https://en.wikipedia.org/wiki/DEC_GT40 DEC GT 40 graphics terminal] can render vector graphics using a display list. A GT40 emulator including FOCAL-11 is available in the [https://groups.google.com/g/pidp-11/c/vw020UvT5tE PiDP-11 Google Group].
 
==External links==
Anonymous user