DEV Community

Discussion on: Rust Your Own Lisp

Collapse
yorodm profile image
Yoandy Rodriguez Martinez

Great stuff Ben!!!. A question from a fellow Rustling, why does Fun(LvalFun) works without deriving PartialEq?

Collapse
deciduously profile image
Ben Lovy Author • Edited on

Good eye :) It definitely doesn't, I fudged it:

impl PartialEq for LvalFun {
    fn eq(&self, other: &LvalFun) -> bool {
        match self {
            LvalFun::Builtin(name, _) => match other {
                LvalFun::Builtin(other_name, _) => name == other_name,
                _ => false,
            },
            LvalFun::Lambda(env, formals, body) => match other {
                LvalFun::Lambda(other_env, other_f, other_b) => {
                    formals == other_f && body == other_b && env == other_env
                }
                _ => false,
            },
        }
    }
}

Builtin functions are considered "equal" if they share a name, and because there are no name collisions in the environment I deemed it "good enough".

Can you think of reasons why this wouldn't be sufficient? It's on my "revisit later" list and for now seems to be working fine.

Collapse
yorodm profile image
Yoandy Rodriguez Martinez

Oooh, I missed the part where you implemented that, nice workaround :D

Thread Thread
deciduously profile image
Ben Lovy Author

workaround, cheat, who knows :)