Rank: Advanced Member Groups: Registered
Joined: 15/04/2012(UTC) Posts: 1,986 Was thanked: 1124 time(s) in 721 post(s)
|
I implemented a new MaximaTakeover() function, which adds definitions to the context or removes them according to the given arguments. First tests seem very promising, such that the full functionality of the Maxima plugin can be re-established soon. It turned out that something like Code:
int index;
if (context.Contains(lhs, out index) context.RemoveAt(index);
didn't do the job of deleting the definitions from the global context. The deletion actually worked (as per inspection in the debugger) but that was of only local scope. I had to resort to Clear(). Code:
public static bool MaximaTakeoverF1(Term[][] args, ref Store context, ref Term[] result)
{
// List of available definitions
String[] Functions = new String[]
{
"Diff(f__)",
"Diff(f__,x__)",
"Diff(f__,x__,n__)",
"Int(f__,x__)",
"Int(f__,x__,a__,b__)",
"Lim(f__,x__,x0__)",
"Sum(f__,var__,a__,b__)",
"Det(m__)"
};
// Try to ensure maxima is running
ControlObjects.CommunicationInterface.GetMaxima();
// Check if Maxima is running and complain otherwise
if (ControlObjects.CommunicationInterface.GetMaxima().GetState() != ControlObjects.CommunicationInterface.GetMaxima().GetMaximaStateRunning())
{
result = TermsConverter.ToTerms(ControlObjects.CommunicationInterface.GetMaxima().GetState());
return true;
}
// normalize the arguments list to the first three characters of the string representation
// i.e. int, dif, lim,...
List<string> NormArgs = new List<string>() { };
foreach (Term[] arg in args)
{
string Arg = TermsConverter.ToString(arg);
if (Arg.Length > 3) NormArgs.Add(Arg.Substring(1,3));
}
// Loop over the available functions
string message = "";
foreach (String Function in Functions)
{
string LhsString = Function.ToLower();
Entry lhs = Entry.Create(TermsConverter.ToTerms(LhsString));
if (NormArgs.Contains(LhsString.Substring(0, 3)) || NormArgs.Contains("all"))
{
// add definition
Entry rhs = Entry.Create(TermsConverter.ToTerms(Function)); ;
Entry def = context.AddDefinition(lhs, rhs);
// augment message
string MsgPart = LhsString.Split('(')[0] + "(), ";
if (!message.Contains(MsgPart)) message += MsgPart;
}
else
{
// remove definition
context.Clear(lhs);
}
}
// Make result string
result = TermsConverter.ToTerms(Symbols.StringChar + message + Symbols.StringChar);
return true;
}
|
|