2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Diagnostics;
7 using System.Threading.Tasks;
19 private readonly IKernelLink _kernel;
33 get {
return _kernel; }
106 private readonly
string _command;
107 private readonly IKernelLink _kernel;
117 get {
return _command; }
122 get {
return _kernel; }
129 throw new ArgumentException(
"Never feed a KernelOperation into another KernelOperation. You probably forgot an Eval somewhere.");
135 CheckArgs(args.AsEnumerable());
141 CheckArgs(args.AsEnumerable());
142 return Bracket(args.AsEnumerable());
147 args = args.ToArray();
150 String.Format(
"{0}[{1}]",_command, String.Join(
",", args))
157 Kernel.Evaluate(_command);
158 Kernel.WaitForAnswer();
159 var e = Kernel.GetExpr();
162 Kernel.WaitForAnswer();
163 return Kernel.GetObject();
172 Kernel.Evaluate(_command);
173 Kernel.WaitForAnswer();
174 Expr e = Kernel.GetExpr();
183 return delegate(Expr expr)
185 k.Evaluate(String.Format(
"{0}[{1}]", s, expr));
197 private static int x = 0;
199 private void MaybePrint()
203 Console.WriteLine(
"Computation number: {0}", x);
KernelOperation Format(params object[] args)
Formats the KernelOperation using String.Format(string, args)
KernelOperation Bracket(params object[] args)
Treats the command like the head of a Mathematica function and sets args to be its arguments...
KernelOperation Bracket< T >(IEnumerable< T > args)
Treats the command like the head of a Mathematica function and sets args to be its arguments...
Interface for the KernelDispatch class
Func< Expr, Expr > EvalFunc()
Converts this Command to a re-usable function which takes in and gives out Mathematica Expressions...
KernelOperation FullSimplify()
Performs a FullSimplify[] Mathematica operation upon the Command.
Expr Eval()
Evaluates the Command to a Mathematica expression.
object EvalObject()
Evaluates the Command to a .NET object, which can be cast as a double, int, boolean, etc.
Object allowing for a more clear and intuitive interface to the Mathematica kernel. Still a WIP.
Func< Expr, Expr > EvalFunc()
Converts this Command to a re-usable function which takes in and gives out Mathematica Expressions...
object EvalObject()
Evaluates the Command to a .NET object, which can be cast as a double, int, boolean, etc.
IKernelLink Kernel
Link to the Mathematica Kernel
KernelOperation(IKernelLink kernel, string command)
KernelOperation FullSimplify()
Performs a FullSimplify[] Mathematica operation upon the Command.
void CheckArgs< T >(IEnumerable< T > args)
string Command
The code to be executed when this KernelOperation is evaluated.
Expr Eval()
Evaluates the Command to a Mathematica expression.
KernelOperation Bracket(params object[] args)
Treats the command like the head of a Mathematica function and sets args to be its arguments...
IKernelLink Kernel
The IKernelLink used by this KernelDispatch.
KernelOperation Bracket< T >(IEnumerable< T > args)
Treats the command like the head of a Mathematica function and sets args to be its arguments...
static IKernelLink Kernel
The Mathematica kernel link
KernelOperation Format(params object[] args)
Formats the KernelOperation using String.Format(string, args)