[Coco] DEFFN in Extended BASIC

Richard Goedeken Richard at fascinationsoftware.com
Sun Jan 4 01:30:48 EST 2015


William's point is that this DEFFN mechanism is supposed to work like a Lambda
function for BASIC, but you are misusing it.

If it worked properly as a Lambda function, then this syntax would function
correctly:

10 DEFFNA(I J)=I+J
20 PRINTFNA(1 10)

But that doesn't work.  The reasons why it doesn't work are explained in his
earlier email.  Your example works because you are taking advantage of the
fact that you have defined A and B as 'global' variables.  This does work (as
a non-nested, anonymous function -- basically a regular subroutine), but it is
less useful than a proper lambda function.

You're not 'passing in' multiple variables; you're just using variables that
were already in the global namespace.  You could do the same thing like this:

10 DEFFNA(X)=A+B+C+D
20 A=1:B=10:C=100:C=1000
30 PRINT FNA(9999)

The input variable is irrelevant because you're not using it.

Richard


On 01/03/2015 10:15 PM, Allen Huffman wrote:
>> On Jan 3, 2015, at 11:33 PM, Allen Huffman <alsplace at pobox.com> wrote:
>> 
>> 10 DEFFNA(A B C D)=A+B+C+D 20 A=1:B=10:C=100:C=1000 30 PRINT FNA(1 10 100
>> 1000)
>> 
>> …prints 1111.
>> 
>> Tests show it does not work with direct numbers like FNA(1 2 3 4) but
>> works with variables.
> 
> And, I might add, it has to be the variables you used in DEFN() for it to
> work. It must just simply be making a note of where that formula is, and
> when it sees FNx( it jumps there?
> 
> I notice it produces the expected result even if you call it as FNA(0). It
> just uses the A and B you defined earlier, and jumps to whatever code. It's
> a function GOSUB. Cool.
> 
> I guess it's time to look at Unravelled and see how it's doing this since
> there is an understanding that it doesn't work when clearly it does.
> 
> 10 DEFFNA(A B)=A+B 
> 20 A=10:B=1:PRINTFNA(0)
> RUN
> 11
> 
> Slower, but could save memory.
> 
> -- Allen
> 


More information about the Coco mailing list