1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::{Environment, Expression, Symbol};
use std::cmp::Ordering;

use crate::Locker;

#[derive(Debug, Clone)]
pub struct Function {
    pub params: Vec<Symbol>,
    pub expressions: Vec<Expression>,
    pub collapse_input: bool,
    pub lexical_scope: Locker<Environment>,
}

impl PartialEq for Function {
    fn eq(&self, other: &Self) -> bool {
        self.params == other.params
            && self.expressions == other.expressions
            && self.collapse_input == other.collapse_input
    }
}

impl PartialOrd for Function {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        if self == other {
            Some(Ordering::Equal)
        } else {
            None
        }
    }
}

impl Function {
    pub fn new(
        params: Vec<Symbol>,
        expressions: Vec<Expression>,
        collapse_input: bool,
        lexical_scope: Locker<Environment>,
    ) -> Self {
        Self {
            params,
            expressions,
            collapse_input,
            lexical_scope,
        }
    }
}