Category:FOCAL: Difference between revisions

From Rosetta Code
Content added Content deleted
(link to PDF)
No edit summary
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{stub}}{{language|FOCAL}}
{{language}}
FOCAL (which either stands for '''Fo'''rmula '''Cal'''culator or '''F'''ormulating '''O'''n-line '''C'''alculations in '''A'''lgebraic '''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. It could also be used satisfactorily on quite small computers: the FOCAL interpreter would run on a PDP-8 with only 4k words (6k bytes) of storage and still leave some space for user programs.
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==
==Running FOCAL in a PDP emulator==


There is a 256-line PDP-8 emulator in C which can run the included FOCAL binary tape image. Note that programs will run much faster than on a real PDP-8.
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 punched paper tape image. Note that programs will run much faster on this emulator than on a real PDP-8.


Exit the emulator by pressing Ctrl-Backslash. The emulator will quit and dump the zero page of memory in octal.
To exit the emulator, use Ctrl-Backslash. The emulator will quit and dump the RAM zero page in octal.


Compiling and running the emulator on Linux (should also work on macOS):
Compiling and running the emulator on Linux (should also work on macOS):
<pre>
<pre>
$ git clone https://git.jeelabs.org/jcw/embello
$ git clone https://github.com/JohnOH/embello/
$ cd embello/explore/1638-pdp8
$ cd embello/explore/1638-pdp8
$ make
$ make
Line 29: Line 75:
*W
*W
C-FOCAL,1969
C-FOCAL,1969
*T "HELLO WORLD FROM FOCAL"!
*
HELLO WORLD FROM FOCAL
QUIT PC 2627
0000: 2667 5403 5403 2603 0004 0013 0100 6400
0010: 3140 3207 1006 3220 0046 2032 0000 3216
0020: 0000 7715 2407 3206 0000 3206 0000 3140
0030: 3770 3217 7776 0000 0000 5377 0000 0000
0040: 2030 0000 0000 0000 0000 0000 0000 0000
0050: 0000 6603 2004 6724 7735 0000 0000 0000
0060: 3217 1500 0000 2676 2666 0001 0215 0000
0070: 0005 0273 0214 0207 0203 0337 0212 0215
0100: 0001 7700 0256 7701 7600 7760 0177 0017
0110: 0277 7776 7477 0260 7540 7522 7563 7775
0120: 7773 7767 0077 0200 4000 2030 2155 5715
0130: 6000 6200 3140 3206 3140 3217 2017 2407
0140: 0521 1565 0477 0534 0554 2274 2502 1314
0150: 0721 2465 2155 2425 0302 2242 2360 0413
0160: 1517 1533 2035 0744 0700 2062 2726 0000
0170: 0000 0000 0000 0000 0000 0000 2741 7610
</pre>
</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==
==External links==
*[http://bitsavers.informatik.uni-stuttgart.de/pdf/dec/pdp8/focal/DEC-08-AJAB-D_FOCAL_Programming_Manual_Jan70.pdf FOCAL-8 Programming manual] (PDF) from Bitsavers
*[http://bitsavers.informatik.uni-stuttgart.de/pdf/dec/pdp8/focal/DEC-08-AJAB-D_FOCAL_Programming_Manual_Jan70.pdf FOCAL-8 Programming manual] (PDF) from Bitsavers
*[https://en.wikipedia.org/wiki/FOCAL_(programming_language) FOCAL] article in Wikipedia

Latest revision as of 09:31, 25 April 2022

Language
FOCAL
This programming language may be used to instruct a computer to perform a task.
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using FOCAL.

FOCAL (which either stands for Formula Calculator or 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.

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 PDP-8 emulator in C which also includes a binary dump of the FOCAL-69 punched 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.

Compiling and running the emulator on Linux (should also work on macOS):

$ git clone https://github.com/JohnOH/embello/
$ cd embello/explore/1638-pdp8
$ make
$ ./p8 focal.bin 
LOAD 0000-7577 CHECK 1153

CONGRATULATIONS!!
YOU HAVE SUCCESSFULLY LOADED 'FOCAL,1969' ON A PDP-8 COMPUTER.


SHALL I RETAIN LOG, EXP, ATN ?:NO

SHALL I RETAIN SINE, COSINE ?:NO

PROCEED.

*W
C-FOCAL,1969
*T "HELLO WORLD FROM FOCAL"!
HELLO WORLD FROM FOCAL

Vector graphics support

FOCAL-11 on a DEC GT 40 graphics terminal can render vector graphics using a display list. A GT40 emulator including FOCAL-11 is available in the PiDP-11 Google Group.

External links

Pages in category "FOCAL"

The following 63 pages are in this category, out of 63 total.