Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 19 variants Number(f64), Var(String), UnaryMinus(Box<Expr>), UnaryNot(Box<Expr>), BinOp(Box<Expr>, Op, Box<Expr>), Call(String, Vec<Expr>), Matrix(Vec<Vec<Expr>>), Transpose(Box<Expr>), Range(Box<Expr>, Option<Box<Expr>>, Box<Expr>), Colon, StrLiteral(String), StringObjLiteral(String), Lambda { params: Vec<String>, body: Box<Expr>, source: String, }, PlainTranspose(Box<Expr>), CellLiteral(Vec<Expr>), CellIndex(Box<Expr>, Box<Expr>), FuncHandle(String), FieldGet(Box<Expr>, String), DotCall(Vec<String>, Vec<Expr>),
}
Expand description

An expression node in the AST.

Produced by the parser and consumed by eval / eval_with_io.

Variants§

§

Number(f64)

A numeric literal (e.g. 3, 2.5, 1e-3).

§

Var(String)

A variable or constant reference (e.g. x, pi, ans).

§

UnaryMinus(Box<Expr>)

Arithmetic negation: -expr.

§

UnaryNot(Box<Expr>)

Logical NOT: ~expr. Result is 1.0 if expr == 0.0, else 0.0.

§

BinOp(Box<Expr>, Op, Box<Expr>)

Binary operation: lhs op rhs.

§

Call(String, Vec<Expr>)

Function call or variable indexing: name(arg1, arg2, ...).

Disambiguation happens at eval time: if name exists in the environment it is treated as indexing, otherwise as a built-in or user function call.

§

Matrix(Vec<Vec<Expr>>)

Matrix literal: [row1; row2; ...] where each row is a list of expressions.

§

Transpose(Box<Expr>)

Conjugate transpose: A'. For complex scalars, returns the conjugate.

§

Range(Box<Expr>, Option<Box<Expr>>, Box<Expr>)

Range expression: start:stop or start:step:stop. Evaluates to a 1×N row vector.

§

Colon

Bare : used as an all-elements index in A(:,j) or A(i,:). Only valid as an argument inside an indexing expression.

§

StrLiteral(String)

Single-quoted char array literal.

§

StringObjLiteral(String)

Double-quoted string object literal.

§

Lambda

Anonymous function: @(params) body_expr.

At evaluation time this is converted to Value::Lambda, capturing the current environment as a lexical closure.

Fields

§params: Vec<String>

Parameter names in declaration order (e.g. ["x", "n"]).

§body: Box<Expr>

Body expression evaluated when the lambda is called.

§source: String

Source text for display (e.g. @(x) x.^2 + 1), stored at parse time.

§

PlainTranspose(Box<Expr>)

Non-conjugate (plain) transpose: A.'.

Transposes without complex conjugation. For real matrices, identical to A'. For complex: z.' returns z unchanged (no sign flip on imaginary part).

§

CellLiteral(Vec<Expr>)

Cell array literal: {e1, e2, e3}.

Evaluates each element and produces Value::Cell.

§

CellIndex(Box<Expr>, Box<Expr>)

Cell array brace-indexing: c{i}.

The first expression must evaluate to Value::Cell; the second is the 1-based integer index.

§

FuncHandle(String)

Function handle: @funcname.

Produces a Value::Lambda that forwards its arguments to the named built-in or user function.

§

FieldGet(Box<Expr>, String)

Struct field read: s.field or chained s.a.b (parsed as FieldGet(FieldGet(s,"a"),"b")).

At eval time the base expression must evaluate to Value::Struct.

§

DotCall(Vec<String>, Vec<Expr>)

Package-qualified function call: pkg.func(args) or pkg.sub.func(args).

segments holds the dot-separated name components, e.g. ["utils", "my_function"]. At eval time:

  • If segments[0] is in the environment (a struct or callable), the chain is followed as field accesses and the final value is called with the given arguments.
  • Otherwise, the segments are treated as a package call: the autoload hook searches for +utils/my_function.calc (or +utils/+sub/func.calc for nested packages) on the session path and loads the function on demand.

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V