Skip to content

Commit

Permalink
Only take the body if the function is not of variable arity (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas authored May 9, 2024
1 parent d7ae4a8 commit abe9fcc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cogs/r5rs.scm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
(check-equal? "Parsing octal" #o0777 511)
(check-equal? "Parsing binary" #b0110 6)

(check-equal? "Empty anonymous function with variable arity" ((lambda x x)) '())

(check-equal? "filter treats lists as true" (filter (lambda (n) (list 1 2)) (list 1 2)) '(1 2))

(check-equal?
Expand Down
16 changes: 9 additions & 7 deletions crates/steel-core/src/steel_vm/const_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,16 @@ impl<'a> ConsumingVisitor for ConstantEvaluator<'a> {
return self.eval_kernel_function(ident.clone(), func, Vec::new(), &[]);
} else {
if let ExprKind::LambdaFunction(f) = &func {
if !f.args.is_empty() {
stop!(ArityMismatch => format!("function expected {} arguments, found 0", f.args.len()))
}
if !f.rest {
if !f.args.is_empty() {
stop!(ArityMismatch => format!("function expected {} arguments, found 0", f.args.len()))
}

// If the body is constant we can safely remove the application
// Otherwise we can't eliminate the additional scope depth
if self.to_constant(&f.body).is_some() {
return Ok(f.body.clone());
// If the body is constant we can safely remove the application
// Otherwise we can't eliminate the additional scope depth
if self.to_constant(&f.body).is_some() {
return Ok(f.body.clone());
}
}
}

Expand Down

0 comments on commit abe9fcc

Please sign in to comment.