[Coco] DEFFN in Extended BASIC

William Astle lost at l-w.ca
Sun Jan 4 00:55:18 EST 2015


This one is working because you're using X and Y as your counters so Y 
is getting set independently of the FN call. Try using, say, G and Q in 
the DEFFN statement and see what happens. You'll see that if your loop 
counters are not the same as your parameter variable names, you'll get a 
single + in the top left on the second loop.

For added fun related to your other queries:

Try this:

A=1 2 3
PRINT A

That will print out 123. That means there is no possible way to pass 
multiple numeric constants using a space as the separator. Spaces are 
permitted inside numbers.

Try this too:

X = 5
Y = 10
X Y = 42
PRINT X Y

Any guesses what is happening there? In actual fact, what happens is the 
"X Y = 42" line assigns 42 to a variable called "XY". This happens 
because the parser uses the same space-skipping next character routine 
when parsing variable names as it does when parsing numbers and most 
other things.

So, when you do the following:

DEF FNX(A B) = A + B

You are actually defining a function with a parameter called AB which is 
not referenced anywhere. Instead, the external variables A and B are 
referenced.

In other words, it wasn't doing anything like what you thought it was doing.

On 15-01-03 10:26 PM, Allen Huffman wrote:
>> On Jan 3, 2015, at 8:43 PM, Arthur Flexser <flexser at fiu.edu> wrote:
>>
>> DEF FN can take only a single argument, contrary to what it says in some
>> Tandy documentation.
>
> Test program - does the same thing with and without DEFFN, and shows the time of each:
>
> 10 T1=TIMER
> 20 FOR X=0 TO 31:FOR Y=0 TO 15
> 30 P=1024+Y*32+X:POKE P,42
> 40 NEXT:NEXT
> 50 T1=TIMER-T1
>
> 60 DEF FNP(X Y)=1024+Y*32+X
> 70 T2=TIMER
> 80 FOR X=0 TO 31:FOR Y=0 TO 15
> 90 P=FNP(X Y):POKE P,43
> 100 NEXT:NEXT
> 110 T2=TIMER-T2
>
> 120 PRINT T1,T2
>
> The 32 column screen will be covered with inverted asterisks, then inverted plus signs.
>
> 		— Allen
>
>



More information about the Coco mailing list