[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Applesoft limitation
mojoehand <jgray@zianet.com> wrote:
> I haven't done anything with Applesoft in many years. I was just
> trying to do something simple and re-learned that Applesoft doesn't
> have things that I am used to having in other BASICs. In particular, I
> needed the INSTR() function, but it's not there. Short of using
> another BASIC or even another language, is there some "enhancement"
> software to add INSTR() and such to Applesoft? Or, is there any way to
> fake this function in standard Applesoft?
Applesoft has a user-defined "&" statement (ampersand) to extend the
language, which can implement anything you want to do (in assembly
language). It operates by calling an entry point (3F5 comes to mind).
Assembly language code can then call Applesoft support routines to parse
further bits of the statement to implement multiple commands, fetch
arguments, etc.
There is probably already an existing INSTR implementation as an &
command, but I haven't used Applesoft for anything serious in about the
last 25 years so I can't point you to anything specific.
It can't be used in an expression context, so wouldn't be as natural as
an INSTR() function in another BASIC. You would have to do something
like this:
10000 &INSTR S1,S2,P%: IF P% > 0 THEN ...
Without resorting to assembly language, you could write a subroutine in
Applesoft to implement an INSTR mechanism, but it would be pretty slow.
It would have to pick apart the strings one character at a time, and you
would want a very efficient string search algorithm to limit the
overhead. Brute force search would be horrible.
--
David Empson
dempson@actrix.gen.nz