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§
Source§impl Expr
impl Expr
Sourcepub fn try_as_normal(&self) -> Option<&Normal>
👎Deprecated: match on Expr::kind() instead
pub fn try_as_normal(&self) -> Option<&Normal>
match on Expr::kind() instead
If this is a Normal expression, return that. Otherwise return None.
Sourcepub fn try_as_bool(&self) -> Option<bool>
👎Deprecated: match on Expr::kind() instead
pub fn try_as_bool(&self) -> Option<bool>
match on Expr::kind() instead
If this is the True or False symbol, return that. Otherwise None.
Sourcepub fn try_as_str(&self) -> Option<&str>
👎Deprecated: match on Expr::kind() instead
pub fn try_as_str(&self) -> Option<&str>
match on Expr::kind() instead
If this is an ExprKind::String expression, return that. Otherwise return None.
Sourcepub fn try_as_symbol(&self) -> Option<&Symbol>
👎Deprecated: match on Expr::kind() instead
pub fn try_as_symbol(&self) -> Option<&Symbol>
match on Expr::kind() instead
If this is a Symbol expression, return that. Otherwise return None.
Sourcepub fn try_as_number(&self) -> Option<Number>
👎Deprecated: match on Expr::kind() instead
pub fn try_as_number(&self) -> Option<Number>
match on Expr::kind() instead
If this is a Number expression, return that. Otherwise return None.
pub fn try_normal(&self) -> Option<&Normal>
match on Expr::kind() instead
pub fn try_symbol(&self) -> Option<&Symbol>
match on Expr::kind() instead
pub fn try_number(&self) -> Option<Number>
match on Expr::kind() instead
Source§impl Expr
impl Expr
Sourcepub fn to_kind(self) -> ExprKind
pub fn to_kind(self) -> 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.
Sourcepub fn normal<H: Into<Expr>>(head: H, contents: Vec<Expr>) -> Expr
pub fn normal<H: Into<Expr>>(head: H, contents: Vec<Expr>) -> Expr
Construct a new normal expression from the head and elements.
Sourcepub fn real(real: f64) -> Expr
pub fn real(real: f64) -> Expr
Construct an expression from a floating-point number.
let expr = Expr::real(3.14159);§Panics
This function will panic if real is NaN.
Sourcepub fn tag(&self) -> Option<Symbol>
pub fn tag(&self) -> Option<Symbol>
Returns the outer-most symbol “tag” used in this expression.
To illustrate:
| Expression | Tag |
|---|---|
5 | None |
"hello" | None |
foo | foo |
f[1, 2, 3] | f |
g[x][y] | g |
Sourcepub fn normal_head(&self) -> Option<Expr>
pub fn normal_head(&self) -> Option<Expr>
If this represents a Normal expression, return its head. Otherwise, return
None.
Sourcepub fn normal_part(&self, index_0: usize) -> Option<&Expr>
pub fn normal_part(&self, index_0: usize) -> Option<&Expr>
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.
Sourcepub fn has_normal_head(&self, sym: &Symbol) -> bool
pub fn has_normal_head(&self, sym: &Symbol) -> bool
Returns true if self is a Normal expr with the head sym.
Sourcepub fn rule<LHS: Into<Expr>>(lhs: LHS, rhs: Expr) -> Expr
pub fn rule<LHS: Into<Expr>>(lhs: LHS, rhs: Expr) -> Expr
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));Sourcepub fn rule_delayed<LHS: Into<Expr>>(lhs: LHS, rhs: Expr) -> Expr
pub fn rule_delayed<LHS: Into<Expr>>(lhs: LHS, rhs: Expr) -> Expr
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![])
);