Skip to content

Commit

Permalink
overwrite function patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
danilopedraza committed Sep 24, 2024
1 parent a051070 commit e5e5304
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ impl Callable for Function {
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum FunctionPatternKind {
Memoized,
NotMemoized,
Expand All @@ -1099,6 +1099,13 @@ pub struct PatternFunction {

impl PatternFunction {
pub fn add_pattern(&mut self, args: &[ASTNode], value: &ASTNode, kind: FunctionPatternKind) {
for i in 0..self.patterns.len() {
let (_, other_args, _) = &self.patterns[i];
if args == other_args {
self.patterns[i] = (kind, args.to_owned(), value.to_owned());
}
}

if self.patterns.is_empty() {
self.params = args.len();
} else {
Expand Down

0 comments on commit e5e5304

Please sign in to comment.