Skip to content

Commit 7ea2a52

Browse files
let + var expr docs (#3486)
Signed-off-by: Joe Isaacs <[email protected]>
1 parent d75003a commit 7ea2a52

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

vortex-expr/src/let_.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::{AnalysisExpr, ExprRef, Identifier, Scope, ScopeDType, VortexExpr};
1010

1111
#[allow(clippy::derived_hash_with_manual_eq)]
1212
#[derive(Debug, Eq, Hash)]
13-
/// Let expressions are of the form `let var = bind in expr`
13+
/// Let expressions are of the form `let var = bind in expr`,
14+
/// see `Scope`.
1415
pub struct Let {
1516
var: Identifier,
1617
bind: ExprRef,

vortex-expr/src/scope.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ impl std::fmt::Display for Identifier {
4242
}
4343
}
4444

45-
/// The evaluation scope for an expression, all variables are evaluated relatively to the data it contains.
46-
/// It allows for expressions to access fields and previously defined data by [`Identifier`].
45+
/// Scope define the evaluation context/scope that an expression uses when being evaluated.
46+
/// There is a special `Identifier` (`Identity`) which is used to bind the initial array being evaluated
47+
///
48+
/// Other identifier can be bound with variables either before execution or while executing (see `Let`).
49+
/// Values can be extracted from the scope using the `Var` expression.
50+
///
51+
/// ```code
52+
/// <let x = lit(1) in var(Identifier::Identity) + var(x), { Identity -> Primitive[1,2,3]> ->
53+
/// <var(Identifier::Identity) + var(x), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
54+
/// <Primitive[1,2,3] + var(x), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
55+
/// <Primitive[1,2,3] + ConstantArray(1), { Identity -> Primitive[1,2,3], x -> ConstantArray(1)> ->
56+
/// <Primitive[2,3,4], { Identity -> Primitive[1,2,3], x -> ConstantArray(1)>
57+
/// ```
58+
///
59+
/// Other values can be bound before execution e.g.
60+
/// `<var("x") + var("y") + var("z"), x -> ..., y -> ..., z -> ...>`
4761
#[derive(Clone, Default)]
4862
pub struct Scope {
4963
array_len: usize,

vortex-expr/src/var.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct Var {
1616
var: Identifier,
1717
}
1818

19+
/// Used to extract values (Arrays from the Scope).
20+
/// see `Scope`.
1921
impl Var {
2022
pub fn new_expr(var: Identifier) -> ExprRef {
2123
Arc::new(Self { var })

0 commit comments

Comments
 (0)