2
$\begingroup$

I noticed that many examples of C code for communicating via MathLink with the Mathematica kernel first pass an EvaluatePacket call to Mathematica, like this:

WSPutFunction(lp, "EvaluatePacket", 1);
WSPutFunction(lp, "Plus", 2);
WSPutInteger(lp, 8);
WSPutInteger(lp, 3);
WSEndPacket(lp);

while (WSNextPacket(lp) != RETURNPKT)
    WSNewPacket(lp);

int result;
WSGetInteger(lp, &result);

Thus far I have not been able to find out the purpose of the call to EvaluatePacket. Leaving out the statement WSPutFunction(lp, "EvaluatePacket", 1L); seems to work fine. Can somebody tell me a bit more about the use of EvaluatePacket?

$\endgroup$

1 Answer 1

2
$\begingroup$

I do not know why it works if no packet is explicitly given, but section 2.3.1 of the old MathLink tutorial is a useful read.

It says,

Everything that you send to the kernel should be wrapped in a packet head.

Then it details the effect of various packet types. For example, both EvaluatePacket and EnterExpressionPacket should contain an expression, but the former will not run the main loop, while the latter will.

Thus, I would not omit the packet name even if it does appear to work without it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.