Struct wolfram_expr::Expr

source ·
pub struct Expr { /* private fields */ }
Expand description

Wolfram Language expression.

Example

Construct the expression {1, 2, 3}:

use wolfram_expr::{Expr, Symbol};

let expr = Expr::normal(Symbol::new("System`List"), vec![
    Expr::from(1),
    Expr::from(2),
    Expr::from(3)
]);

Reference counting

Internally, Expr is an atomically reference-counted ExprKind. This makes cloning an expression computationally inexpensive.

Implementations§

If this is a Normal expression, return that. Otherwise return None.

If this is a True or False symbol, return that. Otherwise return None.

If this is a ExprKind::String expression, return that. Otherwise return None.

If this is a Symbol expression, return that. Otherwise return None.

If this is a Number expression, return that. Otherwise return None.

👎Deprecated: Use Expr::try_as_normal() instead
👎Deprecated: Use Expr::try_as_symbol() instead
👎Deprecated: Use Expr::try_as_number() instead

Construct a new expression from an ExprKind.

Consume self and return an owned ExprKind.

If the reference count of self is equal to 1 this function will not perform a clone of the stored ExprKind, making this operation very cheap in that case.

Get the ExprKind representing this expression.

Get mutable access to the ExprKind that represents this expression.

If the reference count of the underlying shared pointer is not equal to 1, this will clone the ExprKind to make it unique.

Retrieve the reference count of this expression.

Construct a new normal expression from the head and elements.

Construct a new expression from a Symbol.

Construct a new expression from a Number.

Construct a new expression from a String.

Construct an expression from a floating-point number.

let expr = Expr::real(3.14159);
Panics

This function will panic if real is NaN.

Returns the outer-most symbol “tag” used in this expression.

To illustrate:

ExpressionTag
5None
"hello"None
foofoo
f[1, 2, 3]f
g[x][y]g

If this represents a Normal expression, return its head. Otherwise, return None.

Attempt to get the element at index of a Normal expression.

Return None if this is not a Normal expression, or the given index is out of bounds.

index is 0-based. The 0th index is the first element, not the head.

This function does not panic.

Returns true if self is a Normal expr with the head sym.

Null WL.

Construct a new Rule[_, _] expression from the left-hand side and right-hand side.

Example

Construct the expression FontSize -> 16:

use wolfram_expr::{Expr, Symbol};

let option = Expr::rule(Symbol::new("System`FontSize"), Expr::from(16));

Construct a new RuleDelayed[_, _] expression from the left-hand side and right-hand side.

Example

Construct the expression x :> RandomReal[]:

use wolfram_expr::{Expr, Symbol};

let delayed = Expr::rule_delayed(
    Symbol::new("Global`x"),
    Expr::normal(Symbol::new("System`RandomReal"), vec![])
);

Construct a new List[...]({...}) expression from it’s elements.

Example

Construct the expression {1, 2, 3}:

use wolfram_expr::Expr;

let list = Expr::list(vec![Expr::from(1), Expr::from(2), Expr::from(3)]);

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

By default, this should generate a string which can be unambiguously parsed to reconstruct the Expr being displayed. This means symbols will always include their contexts, special characters in String’s will always be properly escaped, and numeric literals needing precision and accuracy marks will have them.

Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.