Re: How to get last input line in MathLink mode?
- To: mathgroup at smc.vnet.net
- Subject: [mg116575] Re: How to get last input line in MathLink mode?
- From: Alexey <lehin.p at gmail.com>
- Date: Sun, 20 Feb 2011 05:26:33 -0500 (EST)
- References: <ijitrt$2r4$1@smc.vnet.net>
Here is the function I have developed for this: In[1]:= getLastInput := Module[{num, f}, f = Function[{u, v}, {u /. {In -> num, HoldPattern -> First}, HoldComplete[v]}, HoldAllComplete]; First@Cases[ Block[{RuleDelayed = f}, DownValues[In]], {$Line - 1, x_} -> x, {1}, 1]] In[2]:= Evaluate[1 + 1] Out[2]= 2 In[3]:= getLastInput Out[3]= HoldComplete[Evaluate[1 + 1]] The problem was that RuleDelayed partially evaluates its r.h.s. in contradiction with the Documentation: In[9]:= a:>Unevaluated[b] // FullForm Out[9]//FullForm= RuleDelayed[a,b] And I have got the answer to the question on InString in MathLink mode from Todd Gayley (Wolfram Research): > InString is only assigned when using EnterTextPacket, not > EnterExpressionPacket. There is no string form of the input when > sending EnterExpressionPacket (whose content is, by definition, > already an expression).