35

I know the LET statement was available in AppleSoft and other Microsoft 8-bit BASICs back in the day, but I can't think of a time where I actually used it. Frankly, I get the impression that it was supported to conform to the Dartmouth standard but the interpreter was smart enough to not require it.

Was the LET statement actually required anywhere? Were there revisions of Microsoft BASIC that actually used it? Further, if the statement was used, did the interpreter spend any time pondering it or did it skip right past it?

3
  • 1
    Great answers below, but tl;dr: no. In Microsoft BASIC, the LET was already completely optional. They (Bill Gates) just put it in for backward compatibility with older, non-Microsoft, standards.
    – Mr Lister
    Commented May 28, 2016 at 13:35
  • It's pretty obvious that Kemeny and Kurtz were mathematicians...
    – RonJohn
    Commented Feb 25, 2022 at 23:46
  • Let as a statement was to make it easier for the lexical interpreter to disambiguate between a variable name at the start of a line vs. a statement. You cannot use reserved words as variable names, and Let was one of words. So when the interpreter read Let at the start of the line, it knew the next item was a variable. If Let wasn't there, it would have to pattern match against reserved words first and in early interpreters, that was a performance hit. Commented Nov 10, 2022 at 16:29

6 Answers 6

48

Except for the very earliest versions of basic, LET was rarely used, but the LET keyword was not always optional. Early BASIC interpreters required it; however, for most versions that came out for the PC (including Microsoft BASIC), the use of LET was optional.

Later standards in BASIC often required that the keyword be supported, but since there was no syntactical ambiguity in leaving it out, it was included simply to ensure compatibility with previous versions of BASIC that require it.

From MSDN » Visual BASIC:

Let Statement

Assigns the value of an expression to a variable or property.

Syntax

[Let] varname = expression

The Let statement syntax has these parts:

Let Optional. Explicit use of the Let keyword is a matter of style, but it is usually omitted.

I've read and written quite a few BASIC interpreters way back, and the lexer definition of an assignment statement usually looked something like this:

line-number [LET] variable = expression

(line numbers were later omitted)

That means the appearance of LET is optional. The only time the interpreter spent in pondering the LET statement was in tokenizing the sequence of characters. But once it was parsed, the token was simply discarded. The use of LET didn't actually add anything in the parsing or execution of code.

1
  • 6
    Congratulations on your first answer. This is of very high quality, and answers the question well. I would welcome you to the site, but you've been around longer than I have. - From review
    – wizzwizz4
    Commented May 28, 2016 at 6:40
22

I can only answer to the first question: the LET statement was actually used in 48K Sinclair BASIC, in which due to the way commands are entered, a keyword is needed before an identifier can be typed, so LET was needed in order to write a variable assignment (although there were unofficial patches to the ROM that eliminated that requirement).

In fact, and while this is not a recommended practice, the use of the LET keyword allowed you to type things like this in Sinclair BASIC:

LET let=0
LET if i were you=2
LET i wouldnt treat me the way you do=3

These examples, BTW, won't work in some MS BASIC interpreters. I have try them with MSX-1.

1
  • 3
    I also remember that GFA BASIC on the Atari ST and Amiga required LET
    – scruss
    Commented May 28, 2016 at 0:58
2

To answer the question

Was the LET statement actually required anywhere?

it was required in ANSI standard BASIC. On page 46 of ANSI standard X3.113-1987 "Full BASIC", the LET keyword is defined, and nowhere in the standard is it defined as optional. Indeed, in one of the few standard test suites for BASIC (NBS minimal BASIC test programs), test program 185 explicitly checks for LET being present, and allows its omission only if suitably documented to the reviewer's satisfaction.

The program, reproduced from ECMA-55 Minimal BASIC compiler / MB_git / [479f4b] /NBS, goes as follows:

10 PRINT "PROGRAM FILE 185: ERROR - MISSING KEYWORD LET."
20 PRINT "    ANSI STANDARD 9.2, 9.4"
30 PRINT
40 PRINT "SECTION 185.1: ERROR - MISSING KEYWORD LET."
50 PRINT
60 PRINT "THIS IS A TEST FOR A NON-STANDARD FEATURE OF MINIMAL BASIC."
70 PRINT "TO PASS THIS TEST, THE PROCESSOR MUST EITHER:"
80 PRINT
90 PRINT "   1) ACCEPT THE PROGRAM AND BE ACCOMPANIED BY DOCUMENTATION"
100 PRINT "      ACCURATELY DESCRIBING THE FEATURE'S INTERPRETATION"
110 PRINT "      BY THE PROCESSOR, OR"
120 PRINT
130 PRINT "   2) REJECT THE PROGRAM WITH AN APPROPRIATE ERROR MESSAGE"
140 PRINT
150 PRINT "SEE THE NBS MINIMAL BASIC TEST PROGRAMS USER'S MANUAL"
160 PRINT "FOR DETAILED CRITERIA."
170 PRINT
180 PRINT "                      BEGIN TEST."
190 PRINT
200 PRINT "ABOUT TO EXECUTE 'LET X1 = 11' AND THEN 'X1 = 12'"
230 LET X1=11
240 X1=12
280 PRINT "VALUE OF X1 = ";X1
290 PRINT
300 PRINT "                        END TEST."
310 PRINT
320 PRINT "END PROGRAM 185"
330 END

The BASIC-80 (MBASIC) Reference Manual mentions that it is compliant, even though LET is optional for it.

0

On the Sharp PC-1211 pocket computer (also rebranded as TRS-80 PC1 and as variants PC-1210/PC-1212) you could omit the LET keyword for simple assignments but you were required to use it in an IF statement as there was no THEN keyword (and no ELSE obviously) which would require a keyword to mark the end of boolean expression.

10: A=1
20: IF B=10LET A=2:GOTO 40
30: PRINT "A*B=";AB: REM * as multiplication was also optional
40: END

Later models based on the SC61860 ESR-H cpu (PC-12??, PC-13?0, PC-14??, etc.) added the THEN keyword but still required the LET after the THEN but only there.

EDIT: UncleBod comment added to answer

here is an interesting reason that LET still was mandatory after THEN. If there is no keyword after THEN the following part is calculated as a line number. A=2 would result in GOTO 1 (if it was a true comparison) or GOTO 0 otherwise. Line number 1 might exist, but never line number 0. (Just tested on a PC-1262) – UncleBod

2
  • 1
    There is an interesting reason that LET still was mandatory after THEN. If there is no keyword after THEN the following part is calculated as a line number. A=2 would result in GOTO 1 (if it was a true comparison) or GOTO 0 otherwise. Line number 1 might exist, but never line number 0. (Just tested on a PC-1262)
    – UncleBod
    Commented Nov 10, 2022 at 8:44
  • Thank you. I had forgotten about that which is a shame as I had a PC-1350 and a PC-1262 for years that I still used a lot. Commented Nov 10, 2022 at 10:49
-1

When I started programming, there was only BASIC and GW BASIC followed. In those days you had to plan and reserve your memory, because there wasn't not much. LET and DIM did that trick. LET assigned memory to a variable and with DIM you had the option to define how much memory.

4
  • 1
    According to the GW-BASIC 3.2 manual, at least that version entirely ignored "LET". I can't find any copies of the manual for older versions, but my understanding is that no version of GW-BASIC required the use of "LET". I'm also not sure what you mean by "there was only BASIC and GW BASIC", as there were lots of different versions of BASIC around long before GW-BASIC was released in 1983.
    – Jules
    Commented Jun 2, 2016 at 20:45
  • GW BASIC was very different from the BASIC version I knew. I couldn't program in GW BASIC, because I found it a little difficult and I didn't have the special editor. I started by hacking a menu written in BASIC with the use of Ctrl-Break and LIST. And I had MS DOS, PC DOS just came on the market. I was 8 or 9 years old in that time, do I don't recall it that precisely. I live in The Netherlands and I don't know if they released many DOS versions in Europe. Commented Jun 2, 2016 at 20:56
  • 1
    Welcome to Retrocomputing Stack Exchange. This is a good answer, however some of the content is disputed. If you can find any, could you cite your sources please?
    – wizzwizz4
    Commented Jun 2, 2016 at 21:06
  • Wow, to find my source, I have to dig deep in my DOS/BASIC archive and maybe in an old DOS manual Commented Jun 2, 2016 at 21:18
-1

I had an old TI Basic computer (Texas Instruments) and remember always using the LET statement. I recall that I was mostly copying BASIC programs from a textbook and since the textbook used the LET statement I did too for consistency sake.

5
  • 1
    Was TI BASIC also one (like the Sinclair one mentioned above) where you had to use LET in order to enter a variable name on the keyboard? I know it had a mapping of single keyboard key to BASIC keyword, for many keys anyway. Commented Jun 9, 2016 at 3:45
  • No, you could enter anything you wanted as a variable name on the keyboard but all the examples of TI Basic code I saw written used LET statements. Commented Jun 9, 2016 at 15:43
  • This doesn't actually answer the question, "Was the LET statement actually required anywhere?"
    – cjs
    Commented Jul 26, 2019 at 3:16
  • "you could enter anything you wanted as a variable name" This is incorrect. Page 18 of the TI-99/4A BASIC Reference Manual (Howard W. Sams & Co., 1984) states that variable names have a character length limit and characters that are considered illegal.
    – JRN
    Commented Nov 10, 2022 at 5:08
  • Page 157 of the TI-99/4A BASIC Reference Manual (Howard W. Sams & Co., 1984) states that "You can omit the keyword LET." The book also includes program code with assignment statements that do not use the LET keyword.
    – JRN
    Commented Nov 10, 2022 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .