Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
FOCAL (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Comparison with BASIC== Comparisons between FOCAL and BASIC were inevitable since both languages were common on [[minicomputer]]s of the same era, and the two languages have much in common in syntax and structure. In most cases, there is a direct conversion of FOCAL code to and from BASIC. For example, to ask a user to input a value, in FOCAL one would: ASK "What is your age?",AGE while in BASIC the equivalent is: {{sxhl| INPUT "What is your age?",AGE |basic}} With the exception of a few features that were missing from one or the other, and some relatively minor differences in syntax, the two languages are very similar. One notable exception is the {{code|IF}} in BASIC, which allowed any statement to be placed after the {{code|THEN}}, making it more similar with JOSS' control structures. BASIC reversed the ordering of the code compared to JOSS, placing the conditional expression at the start of the line rather than the end; in BASIC one uses {{code|IF this THEN that}} whereas JOSS used {{code|that IF this}}. FOCAL's {{code|IF}} was more like BASIC's [[computed goto]], {{code|ON X GOTO 10,20,30|basic}}, but the {{code|ON...GOTO}} allowed any number of lines as targets, as opposed to only three for negative, zero and positive as in FOCAL. Another major difference between the two is that FOCAL lacked inherent support for [[String (computer science)|strings]] as data elements that could be assigned to variables. As was the case in early BASICs or FORTRAN versions before the addition of strings (in F77), this limitation was generally avoided through the use of literal strings in input and output commands. It was only when manipulating individual strings, or characters in them, that this became a significant problem. As string variables were not supported, inputting a string used a [[kludge]] that converted any characters typed in by a user to their numeric character value. For example, if one typed {{kbd|HELLO}} at an input statement, FOCAL would convert the H to "8", the numeric value of "H" in the PDP-8's [[six-bit character code]]s ("H" is the eighth letter). It would then interpret the "E" as starting an exponent, then it would try to compute "8" to the "LLO" power, which would take several seconds of CPU time and result in a value of 0.76593020E+103, not a helpful response. Nevertheless, by asking questions that would be responded to using single-letter responses, like "<samp>Do you need instructions, Y or N</samp>", programmers could test the result against known character values to produce what looked like character input. Prepending a zero to a string would coerce it to numeric, so programs could test for specific multicharacter strings using IF statements such as {{code| I (A-0BROWN) 1.00,2.00,1.00}} which will branch to 2.00 if A = "BROWN" or 1.00 otherwise. However the program would throw an overflow error if the user entered text with unfortunately-placed 'E' characters. For instance, one could test for "BROWN" or "RED" but not "GREEN" or "YELLOW". FOCAL's PDP-8 implementation used a [[Floating-point arithmetic|floating point]] representation that represented numbers as four 12-bit words, forty-eight bits in total, with thirty-six bits of mantissa and twelve bits of exponent. This allowed for both significantly higher precision and a significantly wider range of values than most contemporary interpreters, making FOCAL a reasonable choice for serious numerical work. This high precision, and good choices for default decimal output formatting, meant that difficulties with binary-to-decimal rounding were not evident to beginning users. For comparison, [[Microsoft BASIC]] initially used a [[Microsoft Binary Format|32-bit format]], while later versions expanded this to 40-bits. Most BASICs had problems with rounding that led to simple equations resulting in tiny non-zero remainders. It is generally agreed that FOCAL was more efficient in its use of resources than comparable BASIC systems. On a typical machine of the day, often with 6 to 24 kilobytes of [[magnetic-core memory]], FOCAL could handle larger and more complex programming tasks than BASIC.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)