Type: Package
Title: Run 'FOCAL' Language Source Code
Version: 1.0
Date: 2025-05-04
Description: Execute 'FOCAL' (https://en.wikipedia.org/wiki/FOCAL_(programming_language)) source code directly in 'R'. This is achieved by translating 'FOCAL' code into equivalent 'R' commands and controlling the sequence of execution.
License: LGPL-3
Imports: utils, methods
NeedsCompilation: no
Packaged: 2025-05-23 20:45:57 UTC; cgw
Author: Carl Witthoft [aut, cre]
Maintainer: Carl Witthoft <cellocgw@gmail.com>
Repository: CRAN
Date/Publication: 2025-05-27 09:00:02 UTC

Run 'FOCAL' Language Source Code

Description

Execute 'FOCAL' (<https://en.wikipedia.org/wiki/FOCAL_(programming_language)>) source code directly in 'R'. This is achieved by translating 'FOCAL' code into equivalent 'R' commands and controlling the sequence of execution.

The ‘DESCRIPTION’ File

Package: rFocal
Type: Package
Title: Run 'FOCAL' Language Source Code
Version: 1.0
Date: 2025-05-04
Authors@R: c(person(given = "Carl", family = "Witthoft", role = c("aut","cre"), email= "cellocgw@gmail.com"))
Description: Execute 'FOCAL' (<https://en.wikipedia.org/wiki/FOCAL_(programming_language)>) source code directly in 'R'. This is achieved by translating 'FOCAL' code into equivalent 'R' commands and controlling the sequence of execution.
License: LGPL-3
Imports: utils, methods
Author: Carl Witthoft [aut, cre]
Maintainer: Carl Witthoft <cellocgw@gmail.com>

Author(s)

Carl Witthoft [aut, cre] Maintainer: Carl Witthoft <cellocgw@gmail.com>


Run FOCAL Code in R

Description

rFocal is an interpreter function. It takes as input FOCAL commands and macros and executes the intended operations in R.

Usage

rFocal(focFile, rFile, runit=TRUE, saveit = FALSE)

Arguments

focFile

Any of the following: – a text file containing valid FOCAL commands, including the line numbers. – a character string or vector of character strings containing valid FOCAL commands, including the line numbers. – an R object of class "focfile" , generated in a previous call to rFocal.

rFile

A character string providing the name of a file to be created which will contain the interpreted code and associated tables. If left empty, this name is generated from the input focFile.

runit

If TRUE, the R code generated is executed.

saveit

If TRUE, two files are generated. One file, "runseq.txt" , is written to the current working directory. It contains the index numbers of the R code strings executed in sequence order. The other is a file named focFile, written to the current working directory or, if focFile is a path/filename string, to that directory.

Details

The FOCAL language was created in the prehistoric times before lower-case letters were available on computers. rFocal is case-insensitive with respect to the input code, should anyone wish to write new source FOCAL code. The original FOCAL character set included an up-arrow to indicate exponentiation. Given the number of different UTF-8 up-arrows available, rFocal does not support this item. The user must replace it with "^" in any source code. Some FOCAL commmands are unsupported because they have no functionality in the R environment. These commands, including ERASE, MODIFY, GO, if found in the input, are captured as "comment" lines. The FOCAL floating-point formatting syntax is ignored at this time. Future revisions may incorporate this feature.

Value

A list object of class focfile, containing the following.

code

A vector containing the R code equivalent to each FOCAL command.

retidx

An array of index values used to control the sequence of R commans executed

strnum

An array of the FOCAL line numbers

newvar

A collection of variable names created by the interpreter. This is used to re-create environment variables if the output is invoked in a future rFocal command. Note: these data are written to rFile when saveit is TRUE.

Author(s)

Carl Witthoft, carl@witthoft.com

References

See <https://en.wikipedia.org/wiki/FOCAL_(programming_language)> for a brief overview. The original 1968 manual can be found at <http://www.bitsavers.org/www.computer.museum.uq.edu.au/pdf/DEC-08-AJAB-D

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or standard data sets, see data().
focloop <- '1.1 FOR KK = 0,5 ; TYPE "KK SQUARED IS " , KK*KK, !'
rFocal(focloop)
focvals <- c('1.1 SET X = 3','1.2 SET Y = 5','1.3 TYPE "X AND Y",!','1.4 TYPE X, Y')
rFocal(focvals)