[Coco] DEFFN in Extended BASIC

Arthur Flexser flexser at fiu.edu
Sun Jan 4 02:40:41 EST 2015


You could save still more bytes by making it a single-argument function,
since all the second argument is doing is making the first argument a
longer-named unused dummy variable, XY.  Incidentally, I think defining a
function argument variable may cause an additional entry in the program's
variable table, so there's 7 bytes gone on account of that (2 for the
variable name, 5 for its value).

Seems like a GOSUB might often be better used for what you're talking
about, in the absence of true multiple-variable functions being implemented
in CoCo Basic.

Art

On Sun, Jan 4, 2015 at 2:23 AM, Allen Huffman <alsplace at pobox.com> wrote:

> > On Jan 4, 2015, at 1:14 AM, Arthur Flexser <flexser at fiu.edu> wrote:
> >
> > 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.
>
> Agreed. YMMV :) It would not makes sense for that. But for the program I
> was toying with:
>
> DEFFNP(X Y)=1024+Y*32+X
>
> "1024+Y*32+X" is 11 bytes
>
> A line number and P=1024*Y*32+X takes 30 bytes.
>
> A line number and P=FNP(X Y) is 26 bytes, so I can save 4 (at the loss of
> CPU time) every time I use it. (I just have to use it more times than the
> overhead for the DEFFNP line before it's break-even.)
>
> Pity it's not available in Color BASIC, else it could be yet another trick
> to squeeze a tiny bit more memory out of those 4K programs.
>
>                 -- Allen
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>


More information about the Coco mailing list