Chain of packets in MathLink: are the packets always strictly ordered?
The Documentation does not state clear the order of packets returned
by slave kernel via MathLink
. It is natural to suppose that (when
sending an input expression with head EnterExpressionPacket
and working in standard mode):
1) the last packet before the next InputNamePacket
is always
ReturnExpressionPacket
2) there may be always only one ReturnExpressionPacket
and one
OutputNamePacket
for one EnterExpressionPacket
3) ReturnExpressionPacket
is always the next after OutputNamePacket
4) after MessagePacket
the next packet开发者_运维技巧 is always TextPacket
with
all contents of that message
5) there are only 7 types of returned packets in the standard mode: InputNamePacket
, OutputNamePacket
, ReturnExpressionPacket
, DisplayPacket
, DisplayEndPacket
,
MessagePacket
, TextPacket
.
Which of these statements are true?
- 1 is probably not guaranteed.
- 2 is definitely not true (evaluate: "2+2\n2+3").
- 3 is probably true but probably not guaranteed.
- I believe 4 is true.
- 5 is not guaranteed.
In general you should write your code to not rely on the order of packets coming from the kernel. The evaluation should be considered "active" until you receive a new InputNamePacket. OutputNamePacket should update some variable. ReturnExpressionPacket should use the current output name from that variable. If you receive an unknown packet simply ignore it and move on to the next packet.
精彩评论