3
$\begingroup$

Suppose that an expression like

f[something, 12]

was sent to a MathLink link, and we need to read off only the second part of f, which has a known type (e.g. integer). How can the first part, something, be discarded? something could be an atomic or compound expression of any kind. I need to do this in C.

Example:

int argc = 2;
if (! MLTestHeadWithArgCount(link, "f", &argc)) {
   // fail
}

// how do I discard the complete next expression here, whether it's atomic or compound?

int i;
MLGetInteger32(link, &i); // get the integer
$\endgroup$
2
  • $\begingroup$ Should I transfer it to a loopback link, then get rid of the loopback link? $\endgroup$
    – Szabolcs
    Oct 18, 2015 at 18:49
  • $\begingroup$ Hmm, I've completely forgotten about this. I think the right way might be MLTransferExpression(NULL, link), but haven't tried yet. $\endgroup$
    – Szabolcs
    Oct 18, 2015 at 20:08

1 Answer 1

3
$\begingroup$

Based on Todd Gayley's response here and trying it out, it can be done using

MLTransferExpression(NULL, link)

This will remove one complete (sub)expression form the link.

The code for the example from the question would be

int argc = 2;
if (! MLTestHeadWithArgCount(link, "f", &argc)) {
   // fail
}

MLTransferExpression(NULL, link);

int i;
MLGetInteger32(link, &i); // get the integer
$\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.