Skip to content

Commit

Permalink
fix behavior of functions in list intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
Vandesm14 committed Jun 13, 2024
1 parent e99751b commit 48e7784
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions stack-core/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,14 @@ impl Intrinsic {
}
}
}
(ExprKind::Function { body: mut x, .. }, ExprKind::Integer(i))
(ExprKind::Function { scope, body: mut x }, ExprKind::Integer(i))
if i >= 0 =>
{
if (i as usize) < x.len() {
let rest = x.split_off(i as usize);

context.stack_push(ExprKind::List(x).into())?;
context
.stack_push(ExprKind::Function { scope, body: x }.into())?;

context.stack_push(ExprKind::List(rest).into())?;
} else {
Expand Down Expand Up @@ -502,6 +503,7 @@ impl Intrinsic {
lhs.push_str(&rhs);
ExprKind::String(lhs)
}

(
ExprKind::Function {
scope,
Expand All @@ -512,6 +514,21 @@ impl Intrinsic {
lhs.extend(rhs);
ExprKind::Function { scope, body: lhs }
}

(
ExprKind::Function {
scope,
body: mut lhs,
},
ExprKind::List(rhs),
) => {
lhs.extend(rhs);
ExprKind::Function { scope, body: lhs }
}
(ExprKind::List(mut lhs), ExprKind::Function { body: rhs, .. }) => {
lhs.extend(rhs);
ExprKind::List(lhs)
}
_ => ExprKind::Nil,
};

Expand Down

0 comments on commit 48e7784

Please sign in to comment.