[Coco] DEFFN in Extended BASIC

Arthur Flexser flexser at fiu.edu
Sun Jan 4 02:14:04 EST 2015


What that last program is doing is defining a function of the dummy
variable AB as being equal to the sum of A and B.  So, regardless of what
value of AB is used as an argument of the function, it returns A+B.  You
could have made it DEFFNC(Q R)=A+B with the same result.

The program could be shortened to
10 A=10:B=1:PRINT A+B

In any case PRINTFNA(0) tokenizes to 6 bytes, PRINTA+B to 4 bytes, so
there's no space saving.

Art

On Sun, Jan 4, 2015 at 1:15 AM, Allen Huffman <alsplace at pobox.com> 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
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list