tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
408 stars 28 forks source link

Draft: Add variable definitions via let #110

Open leftshift opened 2 years ago

leftshift commented 2 years ago

As came up in #104, i took a look at adding variable definitions via let x = expr.

Still some things to figure out: Right now, it's possible to set variables to names which then are inaccessible because they are masked by a unit with the same name. I'd like to probably change lookup slightly so it also returns the type of the lookup result, so before setting a variable, we can check whether there already is something other than a variable with this name and refuse. I think silently redefining variables with another let is fine, though.

Again, any thoughts or ideas are appreciated :)

leftshift commented 2 years ago

Oops, broke the tests /o\

I actually took a quick look at the tests when working on #104 and wanted to add a test for accessing the previous result, but couldn't figure out how to make the thread local context also mutable... It might also make sense to refactor these tests to use lib::eval()?