[comp.sys.apple] I don't think I made myself clear...

pete@pro-europa.cts.com (Peter Creath) (08/10/89)

Okay, here's the problem:  I'm using AppleSoft & I need it to solve
non-constant equations.

for instance:     10 input a$
                  20 print a$" = " [answer]

                  RUN

                  ?3*4-2
                  3*4-2 = 10

In this case, the equation could be ANYTHING.  How would I get AppleSoft to
solve it?  (Short of writing massive code)

  ...thanx...    \\ Peter \\

_____________________________________________________________________________
Peter Creath                       | UUCP: crash!pro-europa!pete
13319 Conifer                      | ARPA: crash!pro-europa!pete@nosc.mil
Houston, Tx 77079                  | INET: pete@pro-europa.cts.com

jamesh@pro-colony.cts.com (James Howell) (08/11/89)

Network Comment: to #8800 by pete@pro-europa.cts.com

> ?3*4-2
> 3*4-2 = 10


        Hey, applesoft (or most languages for that matter) are not going to
let you stick any expression under the sun into a variable and have it
evaluated.  The best way would be to parse the string and recursively (yes it
can be done in basic) evaluate the expression.  Another way would be to use a
stack to convert to post fix and evaluate straight thru.

        If you know the apple well, there is an easier alternative.  Put a REM
statement in your code where you want the expression evaluated.  Make it long
enough that the longest expression you want to evaluate would fit.  Then input
your expression, poke in the "RESULT = ", then poke in the expression from
your variable, then poke in ": REM".  Then when the line that used to contain
the REM is executed, your expression gets evaluated.  You will probably want
to parse the expression for syntax errors though, and that would mean you
might as well write the code to evaluate the expression (parsed).

        If you want el cheapo syntax checking, use ON ERR GOTO, and check to
see if the error code is a syntax error on that line, if so take appropriate
action (ie. a message).
                                - Jim