Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support assertions #229

Open
twolodzko opened this issue Sep 12, 2023 · 1 comment
Open

Support assertions #229

twolodzko opened this issue Sep 12, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@twolodzko
Copy link
Contributor

It would be great to have assertions, so it would be possible to do

2 + 2 == 4  # returns TRUE
2 + 2 == 5  # returns FALSE
2 + 2 != 5   # returns TRUE

This could be helpful for verifying calculations, e.g. expression == my_answer to validate manual calculations.

A more controversial syntax (but arguably, closer to actual math syntax) might overload the = operator, so

x = 4        # x was not used before, so it is an assignment
x = 2 + 2  # assertion is true, nothing happens
x = 2 + 3  # Error: x is not equal to 5
y = 8 / 2   # y was not used before, assign
x = y        # get x and y and assert to compare for equality

So the above would work in a similar way on how = operator works in Erlang or Elixir, see https://learnyousomeerlang.com/starting-out-for-real#invariable-variables

Having the above would also help to get rid of accidental overwrites like

pi = 42

If forced assignment would be needed, there's the := symbol commonly used in math for it.

@printfn
Copy link
Owner

printfn commented Sep 12, 2023

Thanks for the suggestion! Assertions (and comparison operators in general) are definitely on my radar to add at some point.

@printfn printfn added the enhancement New feature or request label Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants