We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technology expertise.
:Pattern: addto[$CurrentLink, n_Integer]
:Arguments: {n}This zeros the global variable counter every time the program is started.
:ArgumentTypes: {Integer}
:ReturnType: Integer
:End:
int addto(int n) {This installs one instance of the external program containing addto: This installs another instance: This adds 10 to the counter in the first instance of the external program: This adds 15 to the counter in the second instance of the external program: This operates on the first instance of the program again: If an external program maintains information about its state then you can use different instances of the program to represent different states. $CurrentLink then provides a way to refer to each instance of the program. The value of $CurrentLink is temporarily set every time a particular instance of the program is called, as well as when each instance of the program is first installed. WSEvaluateString(stdlink,"string") send input to the Wolfram System but return no results Sending a string for evaluation by the Wolfram System. The two‐way nature of WSTP connections allows you not only to have the Wolfram System call an external program, but also to have that external program call back to the Wolfram System. In the simplest case, you can use the WSTP function WSEvaluateString() to send a string to the Wolfram System. The Wolfram System will evaluate this string, producing whatever effects the string specifies, but it will not return any results from the evaluation back to the external program. To get results back you need explicitly to send an EvaluatePacket to the Wolfram System, and then read the contents of the ReturnPacket that comes back.
counter += n;
return counter;
}
WSPutFunction(stdlink, "EvaluatePacket", 1);This constructs the expression Factorial[7] or 7!.
WSPutFunction(stdlink, "Factorial", 1);This specifies that the packet you are constructing is finished.
WSPutInteger32(stdlink, 7);
WSCheckFunction(stdlink, "ReturnPacket", &n);This extracts the integer result for 7! from the packet.
WSGetInteger32(stdlink, &ans);WSEndPacket(stdlink) specify that a packet is finished and ready to be sent to the Wolfram System Sending a packet to the Wolfram System. When you can send the Wolfram System an EvaluatePacket[input], it may in general produce many packets in response, but the final packet should be ReturnPacket[output]. "Manipulating Expressions in External Programs" discusses how to handle sequences of packets and expressions whose structure you do not know in advance.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4