[Coco] Back to DEF FN

William Astle lost at l-w.ca
Tue Jan 28 13:01:59 EST 2014


Having spent some time grokking the variable lookup code some time back, 
I think I can give an answer here.

"Array search disable" prevents the variable name parser from even 
considering subscripts. It should yield a syntax error if an array 
subscript is specified.

Note that color basic has a separate name space for arrays and scalars 
so an array B and a regular numeric B are different variables, 
regardless whether the array disable flag is set or not. That is, you 
can have a variable B and also an array B at the same time.

On 14-01-28 10:49 AM, Arthur Flexser wrote:
> Aaron, what does that "array search disable" do?   I'm guessing that if you
> define FN(B)=B+3, that the array search disable means it makes no
> difference if the dummy variable B happens to be the name of a declared
> array or not.  Is that correct?
>
> Art
>
>
> On Tue, Jan 28, 2014 at 12:29 PM, Aaron Wolfe <aawolfe at gmail.com> wrote:
>
>> Extended Basic Unravelled contains a detailed disassembly of the DEF
>> code.  Here is the relevant bit:
>>
>>
>> 1015 8880 BD B2 6A // JSR LB26A
>>      SYNTAX CHECK FOR '('
>>
>> 1016 8883 C6 80 // LDB #$80
>>     GET THE FLAG TO INDICATE ARRAY VARIABLE SEARCH DISABLE
>>
>> 1017 8885 D7 08  // STB ARYDIS
>>     AND SAVE IT IN THE ARRAY DISABLE FLAG
>>
>> 1018 8887 BD B3 57 // JSR LB357
>>     GET VARIABLE DESCRIPTOR
>>
>> 1019 888A 8D 25 // BSR L88B1
>>     'TM' ERROR IF STRING
>>
>> 1020 888C BD B2 67 // JSR LB267
>>     SYNTAX CHECK FOR ')'
>>
>> As you can see, there is no loop or any other mechanism that might
>> allow more than a single variable to be parsed.
>> The docs might be inconsistent or confusing, but the code is clear.
>>
>> -Aaron
>>
>>
>> On Mon, Jan 27, 2014 at 7:37 PM, Rogelio Perea <os9dude at gmail.com> 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
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> http://five.pairlist.net/mailman/listinfo/coco
>>
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
>




More information about the Coco mailing list