[Coco] Back to DEF FN

Rogelio Perea os9dude at gmail.com
Mon Jan 27 19:37:40 EST 2014


Just got delivered a library copy of Peter Vernon's "Making The Mos of Your
TRS-80 Color Computer", it was the bargain bin on Amazon (Prentice-Hall
Australia 1983 ISBN 0 7248 0752 7).

Leafing through the pages I came to the section where each ECB command is
listed, an odd wording of the old DEF FN caught my eye:

10 DEF FN( A B C)=(A+B+C)/3
20 INPUT"ENTER THREE NUMBERS";A,B,C
30 D=FNA(A B C)
40 PRINT"THE AVERAGE IS";D
50 PRINT
60 GOTO 20

I was perplexed for a bit. Could it be that the proper syntax on the CoCo's
DEF FN requires the variables to be separated by a space instead of a
comma? could it be *that* simple?

I retyped the MOD routine into the CoCo as:

10 DEF FNRE=(N1 N2)=N1-INT(N1/N2)*N2
20 CLS
30 INPUT"NUMBER 1";N1
40 INPUT"NUMBER 2";N2
50 PRINT
60 PRINT N1;"MOD";N2;"IS";FNRE(N1 N2)
70 PRINT
80 GOTO 30

And it worked. This routine above is based on one shown by Lewis
Rosenfelder in "Basic Faster And Better & Other Mysteries" book. I was on a
roll and ported another one from Rosenfelder's (date day # finder):

10 CLS
20 DEF FNJD(Y M
D)=(M-1)*28+VAL(MID$("000303060811131619212426",(M-1)*2+1,2))-((M>2) AND
((Y AND NOT -4)=0))+D
30 INPUT"YEAR (1901-2099)";Y
40 INPUT"MONTH (1-12)";M
50 INPUT"DAY (1-31)";D
60 PRINT
70 PRINT"THAT IS THE";FNJD(Y M D);"DAY OF THE YEAR"
80 PRINT
90 END

Still smiling as I type this. The CoCo ECB book sins in being sparse at
best on covering one of the most underrated functions in the BASIC
repertoire, one that can come useful if applied properly. It had been years
(decades actually) since the first time I fiddled with DEF FN and it was
disappointing back then that I could not get it to work with 2 or more
arguments... I was using the syntax I knew from the TRS-80 Model I and III
BASIC separating the arguments by commas.

With all this, the CoCo's DEF FN is still limited to numeric functions as
far as I know; ran a routine trying to define a string variable function
(simple concatenation) and the CoCo returned a type mismatch error. Oh
well, having this found to work with multiple variable arguments is in my
eye *the* discovery of the 21st century. Old ECB CoCo style :-)


-- RP



More information about the Coco mailing list