[Coco] Back to DEF FN
William Astle
lost at l-w.ca
Mon Jan 27 21:24:23 EST 2014
Actually, it's not working. Try using something other than N1 and N2 in
your input and print statements. Say use X and Y.
What is happening is that because you've used the same variable name as
both parameters in the DEFFN statement and as your variables in the
call, it only looks like it's working. Instead, it's actually referring
to the global N2 variable.
What's actually happening is that "N1 N2" is being parsed as a single
variable "N1N2" which just happens to be recognized as N1 which is why
you don't get a syntax error. (You can see the same effect in numbers,
as well. Write "1 2" and it will be parsed as 12.)
There is absolutely no code in the ROM for handling multiple parameter
variables so there is no possible way for it to work. It's not that it's
impossible to add such code, but there isn't ROM space for it.
On 14-01-27 05:37 PM, Rogelio Perea wrote:
> 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
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>
More information about the Coco
mailing list