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
sourceimpl 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 try_normal(&self) -> Option<&Normal>
pub fn try_normal(&self) -> Option<&Normal>
If this is a Normal
expression, return that. Otherwise return None.
sourcepub fn try_symbol(&self) -> Option<&Symbol>
pub fn try_symbol(&self) -> Option<&Symbol>
If this is a Symbol
expression, return that. Otherwise return None.
sourcepub fn try_number(&self) -> Option<Number>
pub fn try_number(&self) -> Option<Number>
If this is a Number
expression, return that. Otherwise return None.
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
.
Trait Implementations
sourceimpl Display for Expr
impl Display for Expr
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.
impl Eq for Expr
impl StructuralEq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more