[SerializableAttribute]
public sealed class Expr : IDisposable, ISerializable
<SerializableAttribute>
Public NotInheritable Class Expr
Implements IDisposable, ISerializable
[SerializableAttribute]
public ref class Expr sealed : IDisposable,
ISerializable
[<SealedAttribute>]
[<SerializableAttribute>]
type Expr =
class
interface IDisposable
interface ISerializable
end
Like Wolfram Language expressions, Exprs are immutable, meaning they can never be changed once they are created. Operations that might appear to modify an Expr (like Delete(Int32)) return new modified Exprs without changing the original. Because Exprs are immutable, they are also thread-safe, meaning that any number of threads can access a given Expr at the same time.
Exprs are stored initially in a very efficient way, and they can be created and written to links very quickly. When you call operations that inspect their structure or that extract component parts, however, it is likely that they must be unpacked into a more .NET-native form that requires more memory.In its present state, Expr has four main uses:
(1) Storing expressions read from a link so that they can be later written to another link. This use replaces functionality that C-language programmers would use a loopback link for. (.NET/Link has an ILoopbackLink interface as well, but Expr affords an even easier method.)Expr e = ml.GetExpr();
// ... Later, write it to a different MathLink:
otherML.Put(e);
e.Dispose();
(2) Many of the IKernelLink methods take either a string or an Expr. If it is not convenient to build a string of Wolfram Language input, you can use an Expr. There are two ways to build an Expr: you can use a constructor, or you can create a loopback link as a scratchpad, build the expression on this link with a series of Put calls, then read the expression off the loopback link using GetExpr. Here is an example that creates an Expr that represents 2+2 and computes it in a Wolfram System session using these two techniques:
// First method: Build it using Expr constructors:
Expr symbolPlus = new Expr(ExpressionType.Symbol, "Plus");
Expr e1 = new Expr(symbolPlus, 2, 2);
// ml is a KernelLink
string result = ml.EvaluateToOutputForm(e1, 0);
// Second method: Build it on an ILoopbackLink with MathLink calls:
ILoopbackLink loop = MathLinkFactory.CreateLoopbackLink();
loop.PutFunction("Plus", 2);
loop.Put(2);
loop.Put(2);
Expr e2 = loop.GetExpr();
loop.Close();
result = ml.EvaluateToOutputForm(e2, 0);
e2.Dispose();
// This code will print out the next expression waiting on the link without
// consuming it, so that the state of the link is unchanged:
Console.WriteLine("Next expression is: " + ml.PeekExpr());
Expr(Object) | Creates an Expr whose value is given by the supplied object. |
Expr(ExpressionType, String) | Creates an Expr representing a Wolfram Language Integer, Real, String, or Symbol whose value is given by the supplied string (for example "2", "3.14", "Plus", or "True"). |
Expr(Object, Object) | Creates an Expr with the given head and arguments. |
Args | Gets an array of Exprs representing the arguments of this Expr. |
Dimensions | Gets an array of integers representing the dimensions of this Expr. Works like the Wolfram Language function Dimensions. |
Head | Gets the Expr representing the head of this Expr. Works like the Wolfram Language function Head. |
Item | Gets a part based on its position index. This is the indexer for the class. |
Length | Gets the length of this Expr. Works like the Wolfram Language Length function. |
AsArray | Converts the Expr to an array of the requested type and depth. |
AsDouble | Gives the double value for Exprs that can be represented as doubles. |
AsInt64 | Gives the Int64 value for Exprs that can be represented as integers. |
AtomQ | Tells whether the Expr represents a Wolfram Language atom. Works like the Wolfram Language function AtomQ. |
ComplexQ | Tells whether the Expr represents a Wolfram Language Complex number. |
CreateFromLink | Creates an Expr by reading it off a link. |
Delete | Returns a new Expr that has the same head but the nth element deleted (counted from the end if n is negative). Works like the Wolfram Language function Delete. |
Dispose | Frees resources that the Expr uses internally. |
Equals |
Implements a value-based equality comparison that is similar to the Wolfram Language SameQ function.
(Overrides ObjectEquals(Object)) |
Finalize |
The finalizer frees resources that the Expr uses internally.
(Overrides ObjectFinalize) |
GetHashCode | (Overrides ObjectGetHashCode) |
GetObjectData | Populates the SerializationInfo object with the Expr's internal state information. |
GetType | Gets the Type of the current instance. (Inherited from Object) |
Insert | Returns a new Expr that has the same head but with e inserted into position n (counted from the end if n is negative). Works like the Wolfram Language function Insert. |
IntegerQ | Tells whether the Expr represents a Wolfram Language integer. Works like the Wolfram Language function IntegerQ. |
ListQ | Tells whether the Expr represents a Wolfram Language list (that is, it has head List). Works like the Wolfram Language function ListQ. |
MatrixQ | The elements can be of any type (except lists). |
MatrixQ(ExpressionType) | Requires that every element be of the specified type. |
NumberQ | Tells whether the Expr represents a Wolfram Language number (real, integer, rational, or complex). Works like the Wolfram Language function NumberQ. |
Part(Int32) | Gives the Expr representing the specified part of this Expr. |
Part(Int32) | Extracts a part more than one level deep. |
Put | Not intended for general use. |
RationalQ | Tells whether the Expr represents a Wolfram Language Rational number. |
RealQ | Tells whether the Expr represents a Wolfram Language Real number. |
StringQ | Tells whether the Expr represents a Wolfram Language string. Works like the Wolfram Language function StringQ. |
SymbolQ | Tells whether the Expr represents a Wolfram Language symbol. |
Take | Returns a new Expr that has the same head but only the first n elements of this Expr (or last n elements if n is negative). Works like the Wolfram Language function Take. |
ToString |
Returns a representation of the Expr as a Wolfram Language InputForm string.
(Overrides ObjectToString) |
TrueQ | Tells whether the Expr represents the Wolfram Language symbol True. Works like the Wolfram Language function TrueQ. |
VectorQ | The elements can be of any type (except lists). |
VectorQ(ExpressionType) | Requires that every element be of the specified type. |
Equality(Expr, Expr) | Implements a value-based equality comparison that is similar to the Wolfram Language SameQ function. |
(Expr to Double) | Converts the Expr to a double value. This is the same operation as calling the AsDouble method. |
(Expr to Int64) | Converts the Expr to a long integer value. This is the same operation as calling the AsInt64 method. |
(Expr to String) | Converts the Expr to a string representation. This is the same operation as calling the ToString method. |
Inequality(Expr, Expr) | Implements a value-based inequality comparison. |
INT_MINUSONE | |
INT_ONE | |
INT_ZERO | |
SYM_FALSE | |
SYM_INTEGER | |
SYM_LIST | |
SYM_REAL | |
SYM_STRING | |
SYM_SYMBOL | |
SYM_TRUE |