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
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.calcfor nested packages) on the session path and loads the function on demand.