问题
I am currently writing C++ programs for APL. Up to now, what I've been doing is creating a function in APL, which runs the command prompt and calls the executable, with input and output files it creates as parameters and in turn, the C++ executable is programmed to open the input file, read the input and store the output in the output file, which is fetched by the APL function and stored in one or more variables. The problem with this method is that, when I use simpler functions which will be called a lot or sometimes recursively, opening and closing files all the time for a simple computation take up a lot of the processing time. What I am trying to find out is a way to call a function that is written in C++, either from a solution or a library, and use it directly in my APL workspace.
For example I have a function in C++ written in this form:
Xadd(int x, int y);
and want to write it in APL like this Xadd (x) (y)
and be able to later open it through APL using ∇Xadd
. Thanks.
回答1:
I didn't quite get if you're call CPP functions from APL or vice versa. And you didn't specify which flavour APL you're coding, but you might want to check out these concepts:
- Shared Variable: ⎕SVO
- Auxillary Processor
- Calling compiled programs: ⎕NA
- Check out chapter 28 in the System Services Reference: LINK for IBM APL2/370.
回答2:
I would first compile the Xadd function in a DLL with a single entry point, then experiment with []NA. A helpful stepping stone might be to first get the DLL call working with VBA in Excel (or Word or any other MS Office application which uses VBA), then move on to APL.
来源:https://stackoverflow.com/questions/24812963/cross-platforming-c-functions-to-apl