ljedrz / lambda_calculus

A simple, zero-dependency implementation of the untyped lambda calculus in Safe Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make PRETTY_LAMBDA changeable outside the crate

Michael-F-Bryan opened this issue · comments

As it is, lambda_calculus::term::PRETTY_LAMBDA is a constant and you can only update it if you manually change the crate's source code. This means anyone wanting to use your crate can't actually choose whether to use the unicode λ or a \.

You may want to either make it a mutable static or provide some getters and setters so anyone using your crate can change it in their code without needing to make their own fork.

Just a little nitpicking because I saw you were wanting to do a 1.0 release on reddit. Other than that this looks like a really cool experiment!

Thanks for your feedback! This is a good point; I looked into my options and found the following:

  1. changing it to a static mut, but it requires unsafe blocks whenever it is used
  2. using lazy_static, but I would prefer to avoid any dependencies
  3. conditional compilation with e.g. #[cfg(feature="backslash_lambda")]

I don't have much experience in terms of crate integration, but option 3 looks most promising to me. I doubt anyone will want to use both variants at once, so a one-time decision makes sense. Do you think it would be a good idea?

Option 3 sounds like it'll probably be the best one. It's not really something you'd want to change often anyway, and a feature will probably be the best option.

You could probably do something like this:

#[cfg(feature = "backslash_lambda")]
const LAMBDA: char = '\\';
#[cfg(not(feature = "backslash_lambda"))]
const LAMBDA: char = 'λ';

Then whenever you need a lambda character just refer to that. From what I can see the only file affected would be src/term.rs.

Done. Thanks again!