问题
Is it possible to execute a program within another program that requires parameters? (without inlining it)
E.g.
________________
- PROGRAM:ADD
- :Prompt A,B
- :A+B>C
________________
- PROGRAM:TEST
- :For(I,0,20)
- :Disp (prgmADD (I,I+1))
- :End_________
Obviously this doesn't work the way it currently is, but I hope I made it clear what I'm getting at.
回答1:
I don't think there is a way to do that - you're basically asking to fake user input, which isn't supported.
The way I have gotten around it is preloading the variables by setting A and B to I, I+1. Then have another variable that you never touch in any program that is a flag letting the subprogram know it can skip input.
When the subprogram runs, it uses an if statment to check the flag variable. If it is set to a specific value you've chosen, it knows that it means it doesn't have to run the Prompt command because A and B are already set. After checking the value, it should reset the flag so that when you run it manually later it doesn't skip the prompt.
The specific convention I used was to have the last list in the system reserved for use by my programs. Each program knew to look at the list for parameters. That made it so I didn't have to worry about getting variable letters matched up between programs. So in this case the first element of the list could be 1 to signal that there are parameters to read. If it is 0, it uses prompt. Otherwise it looks at the second and third elements for the values of A and B. It clears the list when it is done with it, so the leftover data doesn't interfere with later runs.
回答2:
The conventional way to pass arguments is in a list through Ans
like so:
________________
- PROGRAM:ADD
- :Ans(1)+Ans(2
________________
- PROGRAM:TEST
- :For(I,0,20
- :{I,I+1
- :prgmADD
- :Disp Ans
- :End
________________
回答3:
As Katie stated, there is no built in method for passing parameters between TI-Basic Programs. There is, however, a primitive method through which a single parameter can passed to a function.
An unevaluated expression can be held in one of the Y-VARS
variables. Using this variable in your program will cause the expression contained within to be evaluated and the result to be returned. The interesting part of this is that Y-VARS
variables can be passed a parameter which will be substituted for a single variable in the body of the expression. The variable that it is substituted for depends on the Y-VARS
variable you used. Function
variables use X
, Parametric
use T
and, Polar
use θ
.
This Sample program demonstrates what I have described.
:"XLog(X→Y1
:Disp Y1(10
:Disp Y1(5
When Y1
is passed 10
as a parameter, all instance of X
in Y1
are replace with 10
. Y1
is now equivalent to 10log(10
, or simply 10. The same affect is seen when passing 5
to Y1
.
The obvious drawback of this workaround is that only one parameter can be passed. Other drawbacks include that you can only put standard calculator functions into one of the Y-VARS
and that accessing Y-VARS
comes with a significant overhead.
来源:https://stackoverflow.com/questions/28369217/ti-84-programming-parameter