READ/DATA & DEF FN for the 1000

See all articles from CATS v2 n12
Author(s): Mark Fisher
Publication: CATS Newsletter
Pub Details: CATS v2 n12 (Volume 2, Issue 12)
Date: March 1985
Pages: 14-15

Advanced BASIC for the T/S 1000

Reading Ward’s article reminded me that we had put out info on READ/DATA a while back. The following is an abstract of the August ’83 article.

Yes: you can use READ/DATA and DEF FN on the T/S 1000. These two commands are useful additions to the 1000 programmer’s bag of tricks.

READ/DATA

These statements can be simulated by a short subroutine, using string slicing. Practical applications of this technique have been publishedin this newsletter in IRS1040, IRS2, and BOGGLER. Here’s the listing:

  10 GOTO 90
20 REM **** READ SUB ****
30 FOR N=1 TO LEN D$
40 IF D$(N)="," THEN GOTO 60
50 NEXT N
60 LET T$=D$( TO N-1)
70 LET D$=D$(N+1 TO )
80 RETURN
90 REM MAIN PROGRAM
100 GOSUB 900
110 GOSUB 20
120 IF T$="END" THEN STOP
130 PRINT T$
140 GOTO 110
900 REM DATA SECTION
910 LET D$="FIRST,SECOND,THIRD,END"
920 RETURN

D$ is the Data string, set up as in line 900. T$ is the transfer string, that carries the individual values back to the program. N is a counter; it can be used in other parts of the program. If you need more data elements, use LET D$=D$+”whatever,” to extend it.

DEF FN

DEF FN can be a useful statement, allowing you to simplify listings when a complex formula is used several times. It essentially acts as a small subroutine, returning a value whenever invoked. On the T/S 1000, the VAL function can be used instead, as here:

  10 LET X=40
20 LET Y=5
30 LET F$="X+Y"
40 PRINT VAL F$

Try changing line 30 to 30 INPUT F$, and entering various formulas in X and Y. A practical example of this technique also appeared in IRS1040 & IRS2.

Mark Fisher

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.